parse doubles as strings
This commit is contained in:
parent
043ead5579
commit
637f475e44
3 changed files with 21 additions and 8 deletions
|
|
@ -37,6 +37,7 @@ SET(BOOST_COMPONENTS)
|
|||
LIST(APPEND BOOST_COMPONENTS thread date_time system filesystem program_options signals serialization chrono unit_test_framework context locale iostreams)
|
||||
SET( Boost_USE_STATIC_LIBS ON CACHE STRING "ON or OFF" )
|
||||
|
||||
|
||||
IF( ECC_IMPL STREQUAL openssl )
|
||||
SET( ECC_REST src/crypto/elliptic_impl_pub.cpp )
|
||||
ELSE( ECC_IMPL STREQUAL openssl )
|
||||
|
|
@ -270,7 +271,7 @@ target_include_directories(fc
|
|||
)
|
||||
|
||||
#target_link_libraries( fc PUBLIC easylzma_static scrypt udt ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} ${ZLIB_LIBRARIES} ${PLATFORM_SPECIFIC_LIBS} ${RPCRT4} ${CMAKE_DL_LIBS} ${rt_library} ${ECC_LIB} )
|
||||
target_link_libraries( fc PUBLIC easylzma_static udt ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} ${ZLIB_LIBRARIES} ${PLATFORM_SPECIFIC_LIBS} ${RPCRT4} ${CMAKE_DL_LIBS} ${rt_library} ${readline_libraries} ${ECC_LIB} )
|
||||
target_link_libraries( fc PUBLIC -L/usr/local/lib easylzma_static udt ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} ${ZLIB_LIBRARIES} ${PLATFORM_SPECIFIC_LIBS} ${RPCRT4} ${CMAKE_DL_LIBS} ${rt_library} ${readline_libraries} ${ECC_LIB} )
|
||||
|
||||
if(MSVC)
|
||||
set_source_files_properties( src/network/http/websocket.cpp PROPERTIES COMPILE_FLAGS "/bigobj" )
|
||||
|
|
|
|||
|
|
@ -294,6 +294,14 @@ namespace fc
|
|||
|
||||
} // namespace fc
|
||||
|
||||
#if __APPLE__
|
||||
#define LIKELY(x) __builtin_expect((long)!!(x), 1L)
|
||||
#define UNLIKELY(x) __builtin_expect((long)!!(x), 0L)
|
||||
#else
|
||||
#define LIKELY(x) (x)
|
||||
#define UNLIKELY(x) (x)
|
||||
#endif
|
||||
|
||||
/**
|
||||
*@brief: Workaround for varying preprocessing behavior between MSVC and gcc
|
||||
*/
|
||||
|
|
@ -304,7 +312,7 @@ namespace fc
|
|||
#define FC_ASSERT( TEST, ... ) \
|
||||
FC_EXPAND_MACRO( \
|
||||
FC_MULTILINE_MACRO_BEGIN \
|
||||
if( !(TEST) ) \
|
||||
if( UNLIKELY(!(TEST)) ) \
|
||||
FC_THROW_EXCEPTION( fc::assert_exception, #TEST ": " __VA_ARGS__ ); \
|
||||
FC_MULTILINE_MACRO_END \
|
||||
)
|
||||
|
|
|
|||
|
|
@ -343,8 +343,8 @@ namespace fc { namespace json_relaxed
|
|||
|
||||
template<bool strict>
|
||||
fc::variant parseNumberOrStr( const fc::string& token )
|
||||
{
|
||||
|
||||
{ try {
|
||||
//ilog( (token) );
|
||||
size_t i = 0, n = token.length();
|
||||
if( n == 0 )
|
||||
FC_THROW_EXCEPTION( parse_error_exception, "expected: non-empty token, got: empty token" );
|
||||
|
|
@ -426,12 +426,14 @@ namespace fc { namespace json_relaxed
|
|||
if( i >= n )
|
||||
return parseInt<10>( token, start );
|
||||
char c = token[i++];
|
||||
//idump((c)(std::string()+c));
|
||||
switch( c )
|
||||
{
|
||||
case '0': case '1': case '2': case '3': case '4':
|
||||
case '5': case '6': case '7': case '8': case '9':
|
||||
break;
|
||||
case '.':
|
||||
return fc::variant(token);
|
||||
if( dot_ok )
|
||||
{
|
||||
dot_ok = false;
|
||||
|
|
@ -442,7 +444,9 @@ namespace fc { namespace json_relaxed
|
|||
return fc::variant( fc::to_double(token.c_str()) );
|
||||
}
|
||||
|
||||
//idump((i));
|
||||
c = token[i+1];
|
||||
//idump((c));
|
||||
switch( c )
|
||||
{
|
||||
case '0': case '1': case '2': case '3': case '4':
|
||||
|
|
@ -466,7 +470,7 @@ namespace fc { namespace json_relaxed
|
|||
FC_THROW_EXCEPTION( parse_error_exception, "expected digit after '.'" );
|
||||
return fc::variant( token );
|
||||
default:
|
||||
FC_THROW_EXCEPTION( parse_error_exception, "illegal character '{c}' in token", ( "c", c ) );
|
||||
FC_THROW_EXCEPTION( parse_error_exception, "illegal character '{c}' in token", ( "c", c )("i",int(c)) );
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
@ -554,7 +558,7 @@ namespace fc { namespace json_relaxed
|
|||
FC_THROW_EXCEPTION( parse_error_exception, "illegal character '{c}' in number", ( "c", c ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
} FC_CAPTURE_AND_RETHROW( (token) ) }
|
||||
|
||||
template<typename T, bool strict>
|
||||
variant_object objectFromStream( T& in )
|
||||
|
|
@ -641,13 +645,13 @@ namespace fc { namespace json_relaxed
|
|||
|
||||
template<typename T, bool strict>
|
||||
variant numberFromStream( T& in )
|
||||
{
|
||||
{ try {
|
||||
fc::string token = tokenFromStream(in);
|
||||
variant result = parseNumberOrStr<strict>( token );
|
||||
if( strict && !(result.is_int64() || result.is_uint64() || result.is_double()) )
|
||||
FC_THROW_EXCEPTION( parse_error_exception, "expected: number" );
|
||||
return result;
|
||||
}
|
||||
} FC_CAPTURE_AND_RETHROW() }
|
||||
|
||||
template<typename T, bool strict>
|
||||
variant wordFromStream( T& in )
|
||||
|
|
|
|||
Loading…
Reference in a new issue