5 #include <boost/lexical_cast.hpp>
6 #include <boost/algorithm/string.hpp>
30 ss << std::fixed << value;
38 return boost::lexical_cast<int64_t>(i.c_str());
40 catch(
const boost::bad_lexical_cast& e )
51 return boost::lexical_cast<uint64_t>(i.c_str());
53 catch(
const boost::bad_lexical_cast& e )
64 return boost::lexical_cast<double>(i.c_str());
66 catch(
const boost::bad_lexical_cast& e )
77 ss << std::setprecision(std::numeric_limits<double>::digits10 + 2) << std::fixed << d;
83 return boost::lexical_cast<std::string>(d);
88 return boost::lexical_cast<std::string>(d);
92 return boost::lexical_cast<std::string>(d);
94 std::string
trim(
const std::string& s )
96 return boost::algorithm::trim_copy(s);
106 string result = boost::algorithm::trim_copy( s );
107 while( result.find(
" " ) != result.npos )
108 boost::algorithm::replace_all( result,
" ",
" " );
125 size_t i = 0, n = s.size(), suffix_start = n;
128 if( !((s[i] >=
'0') && (s[i] <=
'9')) )
134 uint64_t u =
to_uint64( s.substr( 0, suffix_start ) );
139 uint64_t thousand = 1024;
141 if( suffix_start == n )
145 else if( suffix_start == n-1 )
148 else if( suffix_start == n-2 )
150 FC_ASSERT( (s[suffix_start+1] ==
'b') || (s[suffix_start+1] ==
'B') );
153 else if( suffix_start == n-3 )
155 FC_ASSERT( (s[suffix_start+1] ==
'i') || (s[suffix_start+1] ==
'I') );
156 FC_ASSERT( (s[suffix_start+2] ==
'b') || (s[suffix_start+2] ==
'B') );
158 switch( s[suffix_start] )
200 auto next = format.find(
'$' );
201 while( prev < format.size() )
203 ss << format.substr( prev, next == string::npos ? string::npos : next - prev );
206 if( next ==
size_t(string::npos) || next == format.size() )
212 if( format[prev] ==
'{' )
215 next = format.find(
'}', prev );
217 if( next != string::npos )
220 string key = format.substr( prev+1, (next-prev-1) );
222 auto val = args.
find( key );
223 if( val != args.
end() )
225 if( val->value().is_object() || val->value().is_array() )
231 catch(
const fc::assert_exception& e )
233 ss <<
"[\"ERROR_WHILE_CONVERTING_VALUE_TO_STRING\"]";
237 ss << val->value().as_string();
240 ss <<
"${"<<key<<
"}";
246 next = format.find(
'$', prev );