aboutsummaryrefslogtreecommitdiff
path: root/libbutl/char-scanner.cxx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2018-12-15 17:23:37 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2018-12-15 17:27:56 +0300
commit3bf1846063ad30ecc0fc90d34490bf70776faef0 (patch)
tree8a2a248be187671f8d9fd75d3367bfb9de782e45 /libbutl/char-scanner.cxx
parent5bff24a8862f61e40f827591be5c81228efab4c6 (diff)
Add manifest_rewriter class
Diffstat (limited to 'libbutl/char-scanner.cxx')
-rw-r--r--libbutl/char-scanner.cxx25
1 files changed, 17 insertions, 8 deletions
diff --git a/libbutl/char-scanner.cxx b/libbutl/char-scanner.cxx
index aa9e1b7..763a3cb 100644
--- a/libbutl/char-scanner.cxx
+++ b/libbutl/char-scanner.cxx
@@ -35,9 +35,10 @@ using namespace std;
namespace butl
{
char_scanner::
- char_scanner (istream& is, bool crlf, uint64_t l)
+ char_scanner (istream& is, bool crlf, uint64_t l, uint64_t p)
: line (l),
column (1),
+ position (p),
is_ (is),
buf_ (dynamic_cast<fdbuf*> (is.rdbuf ())),
gptr_ (nullptr),
@@ -56,7 +57,7 @@ namespace butl
return unpeekc_;
if (eos_)
- return xchar (xchar::traits_type::eof (), line, column);
+ return xchar (xchar::traits_type::eof (), line, column, position);
int_type v (peek_ ());
@@ -77,13 +78,16 @@ namespace butl
// We need to make sure subsequent calls to peek() return newline.
//
unpeek_ = true;
- unpeekc_ = xchar ('\n', line, column);
+ unpeekc_ = xchar ('\n', line, column, position);
+
+ if (v1 == xchar::traits_type::eof ())
+ eos_ = true;
}
v = '\n';
}
- return xchar (v, line, column);
+ return xchar (v, line, column, position);
}
void char_scanner::
@@ -91,20 +95,23 @@ namespace butl
{
if (unget_)
unget_ = false;
- else if (unpeek_)
- unpeek_ = false;
else
{
+ if (unpeek_)
+ {
+ unpeek_ = false;
+ }
// When is_.get () returns eof, the failbit is also set (stupid,
// isn't?) which may trigger an exception. To work around this
// we will call peek() first and only call get() if it is not
// eof. But we can only call peek() on eof once; any subsequent
// calls will spoil the failbit (even more stupid).
//
- if (!eos (c))
- {
+ else if (!eos (c))
get_ ();
+ if (!eos (c))
+ {
if (c == '\n')
{
line++;
@@ -112,6 +119,8 @@ namespace butl
}
else
column++;
+
+ position = pos_ ();
}
}
}