Fixed reading of wrapped strings that contain multiple " within the string

This commit is contained in:
Robert Osfield 2010-06-09 13:54:08 +00:00
parent 4354c0180c
commit ae88d9467c

View File

@ -102,6 +102,8 @@ public:
virtual void writeWrappedString( const std::string& str )
{
OSG_NOTICE<<"writeWrappedString( "<<str<<" )"<<std::endl;
std::string wrappedStr;
unsigned int size = str.size();
for ( unsigned int i=0; i<size; ++i )
@ -114,6 +116,9 @@ public:
wrappedStr.insert( 0, 1, '\"' );
wrappedStr += '\"';
OSG_NOTICE<<" wrappedStr = "<<wrappedStr<<std::endl;
writeString( wrappedStr );
}
@ -231,37 +236,40 @@ public:
virtual void readCharArray( char* s, unsigned int size ) {}
virtual void readWrappedString( std::string& str )
{
readString( str );
if ( str[0]=='\"' )
{
if ( str.size()==1 || (*str.rbegin())!='\"' )
{
char ch;
do
_in->get( ch ); checkStream();
// skip white space
while ( ch==' ' )
{
_in->get( ch ); checkStream();
if ( ch=='\\' )
{
_in->get( ch ); checkStream();
if ( ch=='\"' )
{
str += ch; ch = 0;
}
else if ( ch=='\\' )
if (ch=='"')
{
// we have an "wrapped string"
_in->get( ch ); checkStream();
while ( ch!='"' )
{
if (ch=='\\')
{
_in->get( ch ); checkStream();
str += ch;
}
else str += ch;
_in->get( ch ); checkStream();
}
}
else
{
str += '\\'; str += ch;
}
}
else
// we have an unwrapped string, read to first space or end of line
while ( (ch!=' ') && (ch!=0) && (ch!='\n') )
{
str += ch;
} while ( ch!='\"' );
_in->get( ch ); checkStream();
}
str = str.substr(1, str.size()-2);
}
}