fix build, added is_array and is_object to value

This commit is contained in:
Daniel Larimer 2013-01-15 13:08:00 -05:00
parent 2476ae450d
commit 21ef2d11e9
3 changed files with 18 additions and 10 deletions

View file

@ -139,6 +139,8 @@ namespace fc {
const char* type()const; const char* type()const;
bool is_null()const; bool is_null()const;
bool is_string()const; bool is_string()const;
bool is_object()const;
bool is_array()const;
void visit( const_visitor&& v )const; void visit( const_visitor&& v )const;

View file

@ -82,7 +82,7 @@ fc::string error_frame::to_detail_string()const {
return ss.str(); return ss.str();
} }
fc::string error_frame::to_string()const { fc::string error_frame::to_string()const {
return substitute( desc, meta ); return substitute( desc, meta ? *meta : fc::value() );
} }
#if 0 #if 0
fc::stringstream ss; fc::stringstream ss;
@ -158,18 +158,18 @@ fc::string substitute( const fc::string& format, const fc::value& keys ) {
// the key is between prev and next // the key is between prev and next
fc::string key = format.substr( prev+1, (next-prev-1) ); fc::string key = format.substr( prev+1, (next-prev-1) );
//slog( "key '%s'", key.c_str() ); //slog( "key '%s'", key.c_str() );
if( keys ) { // if( keys ) {
auto itr = keys->find( key.c_str() ); auto itr = keys.find( key.c_str() );
if( itr != keys->end() ) { if( itr != keys.end() ) {
if( itr->val.is_string() ) { if( itr->val.is_string() ) {
ss<<itr->val.cast<fc::string>(); ss<<itr->val.cast<fc::string>();
} else { } else {
ss << fc::json::to_string( itr->val ); ss << fc::json::to_string( itr->val );
} }
} else { } else {
ss << "???"; ss << "???";
} }
} // }
prev = next + 1; prev = next + 1;
// find the next $ // find the next $
next = format.find( '$', prev ); next = format.find( '$', prev );

View file

@ -291,6 +291,12 @@ value& value::operator=( const value& v ){
bool value::is_null()const { bool value::is_null()const {
return strcmp(gh(holder)->type(), "void") == 0; return strcmp(gh(holder)->type(), "void") == 0;
} }
bool value::is_object()const {
return strcmp(gh(holder)->type(), "object") == 0;
}
bool value::is_array()const {
return strcmp(gh(holder)->type(), "array") == 0;
}
bool value::is_string()const { bool value::is_string()const {
return strcmp(gh(holder)->type(), "string") == 0; return strcmp(gh(holder)->type(), "string") == 0;
} }