aboutsummaryrefslogtreecommitdiff
path: root/libbutl/char-scanner.ixx
blob: 2d962073a49b4b76fd6a55b54796d042d8bfb1ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// file      : libbutl/char-scanner.ixx -*- C++ -*-
// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd
// license   : MIT; see accompanying LICENSE file

namespace butl
{
  inline auto char_scanner::
  get () -> xchar
  {
    if (unget_)
    {
      unget_ = false;
      return ungetc_;
    }
    else
    {
      xchar c (peek ());
      get (c);
      return c;
    }
  }

  inline void char_scanner::
  unget (const xchar& c)
  {
    // Because iostream::unget cannot work once eos is reached, we have to
    // provide our own implementation.
    //
    unget_ = true;
    ungetc_ = c;
  }
}