Deduplicate some code
This commit is contained in:
parent
52f6810735
commit
4d782e894f
1 changed files with 7 additions and 34 deletions
|
|
@ -461,21 +461,9 @@ namespace fc
|
||||||
{ try {
|
{ try {
|
||||||
check_string_depth( utf8_str );
|
check_string_depth( utf8_str );
|
||||||
|
|
||||||
fc::stringstream in( utf8_str );
|
fc::istream_ptr in( new fc::stringstream( utf8_str ) );
|
||||||
//in.exceptions( std::ifstream::eofbit );
|
fc::buffered_istream bin( in );
|
||||||
switch( ptype )
|
return from_stream( bin, ptype );
|
||||||
{
|
|
||||||
case legacy_parser:
|
|
||||||
return variant_from_stream<fc::stringstream, legacy_parser>( in );
|
|
||||||
case legacy_parser_with_string_doubles:
|
|
||||||
return variant_from_stream<fc::stringstream, legacy_parser_with_string_doubles>( in );
|
|
||||||
case strict_parser:
|
|
||||||
return json_relaxed::variant_from_stream<fc::stringstream, true>( in );
|
|
||||||
case relaxed_parser:
|
|
||||||
return json_relaxed::variant_from_stream<fc::stringstream, false>( in );
|
|
||||||
default:
|
|
||||||
FC_ASSERT( false, "Unknown JSON parser type {ptype}", ("ptype", ptype) );
|
|
||||||
}
|
|
||||||
} FC_RETHROW_EXCEPTIONS( warn, "", ("str",utf8_str) ) }
|
} FC_RETHROW_EXCEPTIONS( warn, "", ("str",utf8_str) ) }
|
||||||
|
|
||||||
variants json::variants_from_string( const std::string& utf8_str, parse_type ptype )
|
variants json::variants_from_string( const std::string& utf8_str, parse_type ptype )
|
||||||
|
|
@ -838,25 +826,10 @@ namespace fc
|
||||||
bool json::is_valid( const std::string& utf8_str, parse_type ptype )
|
bool json::is_valid( const std::string& utf8_str, parse_type ptype )
|
||||||
{
|
{
|
||||||
if( utf8_str.size() == 0 ) return false;
|
if( utf8_str.size() == 0 ) return false;
|
||||||
fc::stringstream in( utf8_str );
|
fc::istream_ptr in( new fc::stringstream( utf8_str ) );
|
||||||
switch( ptype )
|
fc::buffered_istream bin( in );
|
||||||
{
|
from_stream( bin, ptype );
|
||||||
case legacy_parser:
|
try { bin.peek(); } catch ( const eof_exception& e ) { return true; }
|
||||||
variant_from_stream<fc::stringstream, legacy_parser>( in );
|
|
||||||
break;
|
|
||||||
case legacy_parser_with_string_doubles:
|
|
||||||
variant_from_stream<fc::stringstream, legacy_parser_with_string_doubles>( in );
|
|
||||||
break;
|
|
||||||
case strict_parser:
|
|
||||||
json_relaxed::variant_from_stream<fc::stringstream, true>( in );
|
|
||||||
break;
|
|
||||||
case relaxed_parser:
|
|
||||||
json_relaxed::variant_from_stream<fc::stringstream, false>( in );
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
FC_ASSERT( false, "Unknown JSON parser type {ptype}", ("ptype", ptype) );
|
|
||||||
}
|
|
||||||
try { in.peek(); } catch ( const eof_exception& e ) { return true; }
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue