This commit is contained in:
Daniel Larimer 2014-05-19 15:22:33 -04:00
commit ed508141a6

View file

@ -276,10 +276,12 @@ namespace fc
std::stringstream ss; std::stringstream ss;
ss.exceptions( std::ifstream::badbit ); ss.exceptions( std::ifstream::badbit );
bool received_eof = false; bool received_eof = false;
bool done = false;
try try
{ {
char c; char c;
while((c = in.peek()) ) while((c = in.peek()) && !done)
{ {
switch( c ) switch( c )
{ {
@ -295,7 +297,8 @@ namespace fc
ss.put( in.get() ); ss.put( in.get() );
break; break;
default: default:
return ss.str() + stringFromToken(in); done = true;
break;
} }
} }
} }
@ -307,22 +310,29 @@ namespace fc
// we can get here either by processing a delimiter as in "null," // we can get here either by processing a delimiter as in "null,"
// an EOF like "null<EOF>", or an invalid token like "nullZ" // an EOF like "null<EOF>", or an invalid token like "nullZ"
fc::string str = ss.str(); fc::string str = ss.str();
if( str == "null" ) return variant(); if( str == "null" )
if( str == "true" ) return true; return variant();
if( str == "false" ) return false; if( str == "true" )
return true;
if( str == "false" )
return false;
else else
{ {
if (received_eof) if (received_eof)
FC_THROW_EXCEPTION( parse_error_exception, "Unexpected EOF" ); {
if (str.empty())
FC_THROW_EXCEPTION( parse_error_exception, "Unexpected EOF" );
else
return str;
}
else else
{ {
// I'm not sure why we do this, a comment would be helpful.
// if we've reached this point, we've either seen a partial // if we've reached this point, we've either seen a partial
// token ("tru<EOF>") or something our simple parser couldn't // token ("tru<EOF>") or something our simple parser couldn't
// make out ("falfe") // make out ("falfe")
return str; // A strict JSON parser would signal this as an error, but we
// FC_THROW_EXCEPTION( parse_error_exception, "Invalid token '${token}'", // will just treat the malformed token as an un-quoted string.
// ("token",str) ); return str + stringFromToken(in);;
} }
} }
} }