Updates from BitShares FC #22

Closed
nathanielhourt wants to merge 693 commits from dapp-support into latest-fc
2 changed files with 23 additions and 5 deletions
Showing only changes of commit 66ed9fc3dc - Show all commits

View file

@ -32,6 +32,12 @@ namespace fc
fc::string pretty_print( const fc::string& v, uint8_t indent ); fc::string pretty_print( const fc::string& v, uint8_t indent );
} }
#if __cplusplus > 201402L
#define FALLTHROUGH [[fallthrough]];
#else
#define FALLTHROUGH
#endif
#define MAX_RECURSION_DEPTH 200 #define MAX_RECURSION_DEPTH 200
#include <fc/io/json_relaxed.hpp> #include <fc/io/json_relaxed.hpp>
@ -290,7 +296,7 @@ namespace fc
if (dot) if (dot)
FC_THROW_EXCEPTION(parse_error_exception, "Can't parse a number with two decimal places"); FC_THROW_EXCEPTION(parse_error_exception, "Can't parse a number with two decimal places");
dot = true; dot = true;
[[fallthrough]]; FALLTHROUGH
case '0': case '0':
case '1': case '1':
case '2': case '2':
@ -320,7 +326,7 @@ namespace fc
{ // read error ends the loop { // read error ends the loop
} }
fc::string str = ss.str(); fc::string str = ss.str();
if (str == "-." || str == ".") // check the obviously wrong things we could have encountered if (str == "-." || str == "." || str == "-") // check the obviously wrong things we could have encountered
FC_THROW_EXCEPTION(parse_error_exception, "Can't parse token \"${token}\" as a JSON numeric constant", ("token", str)); FC_THROW_EXCEPTION(parse_error_exception, "Can't parse token \"${token}\" as a JSON numeric constant", ("token", str));
if( dot ) if( dot )
return return
@ -443,7 +449,7 @@ namespace fc
case 0: case 0:
if( parser_type == fc::json::broken_nul_parser ) if( parser_type == fc::json::broken_nul_parser )
return variant(); return variant();
[[fallthrough]]; FALLTHROUGH
default: default:
FC_THROW_EXCEPTION( parse_error_exception, "Unexpected char '${c}' in \"${s}\"", FC_THROW_EXCEPTION( parse_error_exception, "Unexpected char '${c}' in \"${s}\"",
("c", c)("s", stringFromToken(in)) ); ("c", c)("s", stringFromToken(in)) );
@ -591,7 +597,7 @@ namespace fc
return; return;
case variant::int64_type: case variant::int64_type:
if( format == json::stringify_large_ints_and_doubles && if( format == json::stringify_large_ints_and_doubles &&
v.as_int64() > 0xffffffff ) ( v.as_int64() > 0xffffffff || v.as_int64() < -int64_t(0xffffffff) ) )
os << '"'<<v.as_string()<<'"'; os << '"'<<v.as_string()<<'"';
else else
os << v.as_int64(); os << v.as_int64();
@ -712,7 +718,7 @@ namespace fc
//If we're in quotes and see a \n, just print it literally but unset the escape flag. //If we're in quotes and see a \n, just print it literally but unset the escape flag.
if( quote && escape ) if( quote && escape )
escape = false; escape = false;
[[fallthrough]]; FALLTHROUGH
default: default:
if( first ) { if( first ) {
ss<<'\n'; ss<<'\n';

View file

@ -309,4 +309,16 @@ BOOST_AUTO_TEST_CASE(structured_test)
test_recursive( v_big_array ); test_recursive( v_big_array );
} }
BOOST_AUTO_TEST_CASE(precision_test)
{
BOOST_CHECK_EQUAL( "\"4294967296\"", fc::json::to_string( fc::variant( 0x100000000LL ) ) );
BOOST_CHECK_EQUAL( "\"-4294967296\"", fc::json::to_string( fc::variant( -0x100000000LL ) ) );
std::string half = fc::json::to_string( fc::variant( 0.5 ) );
BOOST_CHECK_EQUAL( '"', half.front() );
BOOST_CHECK_EQUAL( '"', half.back() );
half = half.substr( 1, half.length() - 2 );
while( '0' == half.back() ) half.erase( half.length() - 1, 1 );
BOOST_CHECK_EQUAL( "0.5", half );
}
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()