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 );
static string to_string(const variant &v, output_formatting format=stringify_large_ints_and_doubles, uint32_t max_depth=DEFAULT_MAX_RECURSION_DEPTH)
std::string format_string(const std::string &, const variant_object &, uint32_t max_object_depth=200)
virtual std::string do_grouping() const
std::string to_lower(const std::string &)
string trim_and_normalize_spaces(const string &s)
iterator find(const string &key) const
An order-perserving dictionary of variant's.
Used to generate a useful error report when an exception is thrown.At each level in the stack where t...
int64_t to_int64(const std::string &)
#define FC_RETHROW_EXCEPTIONS(LOG_LEVEL, FORMAT,...)
Catchs all exception's, std::exceptions, and ... and rethrows them after appending the provided log m...
std::string to_pretty_string(int64_t)
double to_double(const std::string &)
#define FC_CAPTURE_AND_RETHROW(...)
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
uint64_t parse_size(const string &s)
#define FC_THROW_EXCEPTION(EXCEPTION, FORMAT,...)
uint64_t to_uint64(const std::string &)
Defines exception's used by fc.
std::string to_string(double)
virtual char do_thousands_sep() const
std::string trim(const std::string &)