From b6e02f4224975a6425f62095bc35478e8866db77 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 24 May 2017 13:26:13 +0200 Subject: Various improvements to char_scanner --- libbutl/char-scanner.ixx | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 libbutl/char-scanner.ixx (limited to 'libbutl/char-scanner.ixx') diff --git a/libbutl/char-scanner.ixx b/libbutl/char-scanner.ixx new file mode 100644 index 0000000..2d96207 --- /dev/null +++ b/libbutl/char-scanner.ixx @@ -0,0 +1,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; + } +} -- cgit v1.1