19 static bool ParsePrechecks(
const std::string& str)
23 if (str.size() >= 1 && (json_isspace(str[0]) || json_isspace(str[str.size()-1])))
25 if (str.size() != strlen(str.c_str()))
30 bool ParseInt32(
const std::string& str, int32_t *out)
32 if (!ParsePrechecks(str))
36 long int n = strtol(str.c_str(), &endp, 10);
37 if(out) *out = (int32_t)n;
41 return endp && *endp == 0 && !errno &&
46 bool ParseInt64(
const std::string& str, int64_t *out)
48 if (!ParsePrechecks(str))
52 long long int n = strtoll(str.c_str(), &endp, 10);
53 if(out) *out = (int64_t)n;
56 return endp && *endp == 0 && !errno &&
61 bool ParseDouble(
const std::string& str,
double *out)
63 if (!ParsePrechecks(str))
65 if (str.size() >= 2 && str[0] ==
'0' && str[1] ==
'x')
67 std::istringstream text(str);
68 text.imbue(std::locale::classic());
71 if(out) *out = result;
72 return text.eof() && !text.fail();
79 throw std::runtime_error(
"JSON value is not an object as expected");
86 throw std::runtime_error(
"JSON value is not an object or array as expected");
93 throw std::runtime_error(
"JSON value is not a boolean as expected");
100 throw std::runtime_error(
"JSON value is not a string as expected");
107 throw std::runtime_error(
"JSON value is not an integer as expected");
110 throw std::runtime_error(
"JSON integer out of range");
117 throw std::runtime_error(
"JSON value is not an integer as expected");
120 throw std::runtime_error(
"JSON integer out of range");
127 throw std::runtime_error(
"JSON value is not a number as expected");
130 throw std::runtime_error(
"JSON double out of range");
137 throw std::runtime_error(
"JSON value is not an object as expected");
144 throw std::runtime_error(
"JSON value is not an array as expected");
const std::string & get_str() const
const std::vector< UniValue > & getValues() const
std::vector< UniValue > values
bool ParseDouble(const std::string &str, double *out)
Convert string to double with strict parse error feedback.
bool ParseInt64(const std::string &str, int64_t *out)
Convert string to signed 64-bit integer with strict parse error feedback.
int64_t get_int64() const
bool ParseInt32(const std::string &str, int32_t *out)
Convert string to signed 32-bit integer with strict parse error feedback.
const std::string & getValStr() const
const UniValue & get_array() const
std::vector< std::string > keys
const std::vector< std::string > & getKeys() const
const UniValue & get_obj() const