Merge branch 'phoenix' of https://github.com/InvictusInnovations/fc into phoenix

This commit is contained in:
Daniel Larimer 2014-04-25 15:17:10 -04:00
commit 07affde1f2
2 changed files with 54 additions and 38 deletions

View file

@ -264,12 +264,14 @@ namespace fc {
istream& operator>>( istream& o, std::string& v ) istream& operator>>( istream& o, std::string& v )
{ {
assert(false && "not implemented");
return o; return o;
} }
#ifdef USE_FC_STRING #ifdef USE_FC_STRING
istream& operator>>( istream& o, fc::string& v ) istream& operator>>( istream& o, fc::string& v )
{ {
assert(false && "not implemented");
return o; return o;
} }
#endif #endif
@ -282,51 +284,61 @@ namespace fc {
istream& operator>>( istream& o, double& v ) istream& operator>>( istream& o, double& v )
{ {
assert(false && "not implemented");
return o; return o;
} }
istream& operator>>( istream& o, float& v ) istream& operator>>( istream& o, float& v )
{ {
assert(false && "not implemented");
return o; return o;
} }
istream& operator>>( istream& o, int64_t& v ) istream& operator>>( istream& o, int64_t& v )
{ {
assert(false && "not implemented");
return o; return o;
} }
istream& operator>>( istream& o, uint64_t& v ) istream& operator>>( istream& o, uint64_t& v )
{ {
assert(false && "not implemented");
return o; return o;
} }
istream& operator>>( istream& o, int32_t& v ) istream& operator>>( istream& o, int32_t& v )
{ {
assert(false && "not implemented");
return o; return o;
} }
istream& operator>>( istream& o, uint32_t& v ) istream& operator>>( istream& o, uint32_t& v )
{ {
assert(false && "not implemented");
return o; return o;
} }
istream& operator>>( istream& o, int16_t& v ) istream& operator>>( istream& o, int16_t& v )
{ {
assert(false && "not implemented");
return o; return o;
} }
istream& operator>>( istream& o, uint16_t& v ) istream& operator>>( istream& o, uint16_t& v )
{ {
assert(false && "not implemented");
return o; return o;
} }
istream& operator>>( istream& o, int8_t& v ) istream& operator>>( istream& o, int8_t& v )
{ {
assert(false && "not implemented");
return o; return o;
} }
istream& operator>>( istream& o, uint8_t& v ) istream& operator>>( istream& o, uint8_t& v )
{ {
assert(false && "not implemented");
return o; return o;
} }

View file

@ -211,54 +211,58 @@ namespace fc
template<typename T> template<typename T>
variant number_from_stream( T& in ) variant number_from_stream( T& in )
{ {
char buf[30]; fc::stringstream ss;
memset( buf, 0, sizeof(buf) );
char* pos = buf;
bool dot = false; bool dot = false;
bool neg = false; bool neg = false;
if( in.peek() == '-') if( in.peek() == '-')
{ {
neg = true; neg = true;
*pos = in.get(); ss.put( in.get() );
++pos;
} }
bool done = false; bool done = false;
while( !done)
try
{ {
char c = in.peek(); char c;
switch( c ) while((c = in.peek()) && !done)
{ {
case '.':
{ switch( c )
if( dot ) {
{ case '.':
done = true; if (dot)
break; FC_THROW_EXCEPTION(parse_error_exception, "Can't parse a number with two decimal places");
} dot = true;
dot = true; case '0':
} case '1':
case '0': case '2':
case '1': case '3':
case '2': case '4':
case '3': case '5':
case '4': case '6':
case '5': case '7':
case '6': case '8':
case '7': case '9':
case '8': ss.put( in.get() );
case '9': break;
*pos = c; default:
++pos; done = true;
in.get(); break;
break; }
default:
done = true;
break;
} }
} }
if( dot ) return to_double(buf); catch (fc::eof_exception&)
if( neg ) return to_int64(buf); {
return to_uint64(buf); }
fc::string str = ss.str();
if (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));
if( dot )
return to_double(str);
if( neg )
return to_int64(str);
return to_uint64(str);
} }
template<typename T> template<typename T>
variant token_from_stream( T& in ) variant token_from_stream( T& in )
@ -269,7 +273,7 @@ namespace fc
try try
{ {
char c; char c;
while( (c = in.peek()) && !parsed_unexpected_character) while((c = in.peek()) && !parsed_unexpected_character)
{ {
switch( c ) switch( c )
{ {