From 813c483a312e1b1b4fa5a02234009ec546a0cc8c Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Sat, 23 May 2020 23:33:57 +0300 Subject: Add putback depth char_scanner template parameter --- libbutl/char-scanner.ixx | 52 +++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 27 deletions(-) (limited to 'libbutl/char-scanner.ixx') diff --git a/libbutl/char-scanner.ixx b/libbutl/char-scanner.ixx index 7e9c4b0..57aefc2 100644 --- a/libbutl/char-scanner.ixx +++ b/libbutl/char-scanner.ixx @@ -3,36 +3,33 @@ namespace butl { - template - inline char_scanner:: + template + inline char_scanner:: char_scanner (std::istream& is, bool crlf, std::uint64_t l, std::uint64_t p) : char_scanner (is, validator_type (), crlf, l, p) { } - template - inline auto char_scanner:: + template + inline auto char_scanner:: peek (std::string& what) -> xchar { return peek (&what); } - template - inline auto char_scanner:: + template + inline auto char_scanner:: peek () -> xchar { return peek (nullptr /* what */); } - template - inline auto char_scanner:: + template + inline auto char_scanner:: get (std::string* what) -> xchar { - if (unget_) - { - unget_ = false; - return ungetc_; - } + if (ungetn_ != 0) + return ungetb_[--ungetn_]; else { xchar c (peek (what)); @@ -41,33 +38,34 @@ namespace butl } } - template - inline auto char_scanner:: + template + inline auto char_scanner:: get (std::string& what) -> xchar { return get (&what); } - template - inline auto char_scanner:: + template + inline auto char_scanner:: get () -> xchar { return get (nullptr /* what */); } - template - inline void char_scanner:: + template + 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; + assert (ungetn_ != N); // Make sure the buffer is not filled. + + ungetb_[ungetn_++] = c; } - template - inline auto char_scanner:: + template + inline auto char_scanner:: peek_ () -> int_type { if (gptr_ != egptr_) @@ -86,8 +84,8 @@ namespace butl return r; } - template - inline void char_scanner:: + template + inline void char_scanner:: get_ () { int_type c; @@ -106,8 +104,8 @@ namespace butl save_->push_back (static_cast (c)); } - template - inline std::uint64_t char_scanner:: + template + inline std::uint64_t char_scanner:: pos_ () const { return buf_ != nullptr ? buf_->tellg () : 0; -- cgit v1.1