aboutsummaryrefslogtreecommitdiff
path: root/libbutl/char-scanner.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2017-05-24 13:26:13 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2017-05-24 13:28:51 +0200
commitb6e02f4224975a6425f62095bc35478e8866db77 (patch)
tree51627eef813ebb670efca83aed7dd284cb738806 /libbutl/char-scanner.cxx
parenteb3c27b8f47c793244436cd082512bb8235bea89 (diff)
Various improvements to char_scanner
Diffstat (limited to 'libbutl/char-scanner.cxx')
-rw-r--r--libbutl/char-scanner.cxx68
1 files changed, 27 insertions, 41 deletions
diff --git a/libbutl/char-scanner.cxx b/libbutl/char-scanner.cxx
index cbc2503..42a72cc 100644
--- a/libbutl/char-scanner.cxx
+++ b/libbutl/char-scanner.cxx
@@ -14,44 +14,44 @@ namespace butl
peek () -> xchar
{
if (unget_)
- return buf_;
- else
- {
- if (eos_)
- return xchar (xchar::traits_type::eof (), line, column);
- else
- {
- xchar::int_type v (is_.peek ());
+ return ungetc_;
- if (v == xchar::traits_type::eof ())
- eos_ = true;
- else if (crlf_ && v == 0x0D)
- {
- is_.get ();
- xchar::int_type v1 (is_.peek ());
+ if (unpeek_)
+ return unpeekc_;
- if (v1 != '\n')
- {
- unget_ = true;
- buf_ = '\n';
- }
+ if (eos_)
+ return xchar (xchar::traits_type::eof (), line, column);
- v = '\n';
- }
+ xchar::int_type v (is_.peek ());
- return xchar (v, line, column);
+ if (v == xchar::traits_type::eof ())
+ eos_ = true;
+ else if (crlf_ && v == 0x0D)
+ {
+ is_.get ();
+ xchar::int_type v1 (is_.peek ());
+
+ if (v1 != '\n')
+ {
+ // We need to make sure subsequent calls to peek() return newline.
+ //
+ unpeek_ = true;
+ unpeekc_ = xchar ('\n', line, column);
}
+
+ v = '\n';
}
+
+ return xchar (v, line, column);
}
- auto char_scanner::
- get () -> xchar
+ void char_scanner::
+ get (const xchar& c)
{
if (unget_)
- {
unget_ = false;
- return buf_;
- }
+ else if (unpeek_)
+ unpeek_ = false;
else
{
// When is_.get () returns eof, the failbit is also set (stupid,
@@ -60,8 +60,6 @@ namespace butl
// eof. But we can only call peek() on eof once; any subsequent
// calls will spoil the failbit (even more stupid).
//
- xchar c (peek ());
-
if (!eos (c))
{
is_.get ();
@@ -74,18 +72,6 @@ namespace butl
else
column++;
}
-
- return c;
}
}
-
- void char_scanner::
- unget (const xchar& c)
- {
- // Because iostream::unget cannot work once eos is reached,
- // we have to provide our own implementation.
- //
- buf_ = c;
- unget_ = true;
- }
}