From 9c876964a5c94aab63e32687621736c66de8e9a5 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sun, 17 Jul 2011 10:30:40 +0000 Subject: [PATCH] From Wang Rui, improved the handling of the _preReadString within the readWrappedString method by factoring the reading of the next character into a dedicated getCharacter(..) method. --- src/osgPlugins/osg/AsciiStreamOperator.h | 32 +++++++++++++++--------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/osgPlugins/osg/AsciiStreamOperator.h b/src/osgPlugins/osg/AsciiStreamOperator.h index 10b74a4ce..091d497ae 100644 --- a/src/osgPlugins/osg/AsciiStreamOperator.h +++ b/src/osgPlugins/osg/AsciiStreamOperator.h @@ -246,35 +246,29 @@ public: virtual void readWrappedString( std::string& str ) { - if ( !_preReadString.empty() ) - { - str = _preReadString; - return; - } - char ch; - _in->get( ch ); checkStream(); + getCharacter( ch ); // skip white space while ( ch==' ' || (ch=='\n') || (ch=='\r')) { - _in->get( ch ); checkStream(); + getCharacter( ch ); } if (ch=='"') { // we have an "wrapped string" - _in->get( ch ); checkStream(); + getCharacter( ch ); while ( ch!='"' ) { if (ch=='\\') { - _in->get( ch ); checkStream(); + getCharacter( ch ); str += ch; } else str += ch; - _in->get( ch ); checkStream(); + getCharacter( ch ); } } else @@ -283,7 +277,7 @@ public: while ( (ch!=' ') && (ch!=0) && (ch!='\n') ) { str += ch; - _in->get( ch ); checkStream(); + getCharacter( ch ); } } } @@ -321,6 +315,20 @@ public: } protected: + void getCharacter( char& ch ) + { + if ( !_preReadString.empty() ) + { + ch = _preReadString[0]; + _preReadString.erase( _preReadString.begin() ); + } + else + { + _in->get( ch ); + checkStream(); + } + } + std::string _preReadString; };