blob: 0e00dfdb9d7c9a84454c010a6e048f06c86fc58d (
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
// 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;
}
inline auto char_scanner::
peek_ () -> int_type
{
if (gptr_ != egptr_)
return *gptr_;
int_type r (is_.peek ());
// Update buffer pointers for the next chunk.
//
if (buf_ != nullptr)
{
gptr_ = buf_->gptr ();
egptr_ = buf_->egptr ();
}
return r;
}
inline void char_scanner::
get_ ()
{
if (gptr_ != egptr_)
{
buf_->gbump (1);
++gptr_;
}
else
is_.get (); // About as fast as ignore() and way faster than tellg().
}
}
|