Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r63098 - trunk/boost/spirit/home/support/iterators/detail
From: hartmut.kaiser_at_[hidden]
Date: 2010-06-19 08:54:05


Author: hkaiser
Date: 2010-06-19 08:54:04 EDT (Sat, 19 Jun 2010)
New Revision: 63098
URL: http://svn.boost.org/trac/boost/changeset/63098

Log:
Spirit: fixing problem in multi_pass
Text files modified:
   trunk/boost/spirit/home/support/iterators/detail/istream_policy.hpp | 24 ++++++++++++++++++++----
   1 files changed, 20 insertions(+), 4 deletions(-)

Modified: trunk/boost/spirit/home/support/iterators/detail/istream_policy.hpp
==============================================================================
--- trunk/boost/spirit/home/support/iterators/detail/istream_policy.hpp (original)
+++ trunk/boost/spirit/home/support/iterators/detail/istream_policy.hpp 2010-06-19 08:54:04 EDT (Sat, 19 Jun 2010)
@@ -48,14 +48,19 @@
             static typename MultiPass::reference get_input(MultiPass& mp)
             {
                 if (!mp.shared()->initialized_)
- advance_input(mp);
+ mp.shared()->read_one();
                 return mp.shared()->curtok_;
             }
 
             template <typename MultiPass>
             static void advance_input(MultiPass& mp)
             {
- mp.shared()->read_one();
+ // We invalidate the currently cached input character to avoid
+ // reading more input from the underlying iterator than
+ // required. Without this we would always read ahead one
+ // character, even if this character never gets consumed by the
+ // client.
+ mp.shared()->peek_one();
             }
 
             // test, whether we reached the end of the underlying stream
@@ -89,9 +94,20 @@
 
             void read_one()
             {
- if (!(input_ >> curtok_))
+ if (!(input_ >> curtok_)) {
+ initialized_ = false;
                     eof_reached_ = true;
- initialized_ = true;
+ }
+ else {
+ initialized_ = true;
+ }
+ }
+
+ void peek_one()
+ {
+ input_.peek(); // try for eof
+ initialized_ = false;
+ eof_reached_ = input_.eof();
             }
 
             T& input_;


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk