26 if (str.size() != strlen(str.c_str()))
31 bool ParseInt32(
const std::string& str, int32_t *out)
37 long int n = strtol(str.c_str(), &endp, 10);
38 if(out) *out = (int32_t)n;
42 return endp && *endp == 0 && !errno &&
43 n >= std::numeric_limits<int32_t>::min() &&
44 n <= std::numeric_limits<int32_t>::max();
47 bool ParseInt64(
const std::string& str, int64_t *out)
53 long long int n = strtoll(str.c_str(), &endp, 10);
54 if(out) *out = (int64_t)n;
57 return endp && *endp == 0 && !errno &&
58 n >= std::numeric_limits<int64_t>::min() &&
59 n <= std::numeric_limits<int64_t>::max();
62 bool ParseDouble(
const std::string& str,
double *out)
66 if (str.size() >= 2 && str[0] ==
'0' && str[1] ==
'x')
68 std::istringstream text(str);
69 text.imbue(std::locale::classic());
72 if(out) *out = result;
73 return text.eof() && !text.fail();
80 throw std::runtime_error(
"JSON value is not an object as expected");
87 throw std::runtime_error(
"JSON value is not an object or array as expected");
94 throw std::runtime_error(
"JSON value is not a boolean as expected");
101 throw std::runtime_error(
"JSON value is not a string as expected");
108 throw std::runtime_error(
"JSON value is not an integer as expected");
111 throw std::runtime_error(
"JSON integer out of range");
118 throw std::runtime_error(
"JSON value is not an integer as expected");
121 throw std::runtime_error(
"JSON integer out of range");
128 throw std::runtime_error(
"JSON value is not a number as expected");
131 throw std::runtime_error(
"JSON double out of range");
138 throw std::runtime_error(
"JSON value is not an object as expected");
145 throw std::runtime_error(
"JSON value is not an array as expected");
const std::string & get_str() const
int64_t get_int64() const
const UniValue & get_obj() const
const std::string & getValStr() const
const std::vector< UniValue > & getValues() const
const std::vector< std::string > & getKeys() const
std::vector< UniValue > values
std::vector< std::string > keys
const UniValue & get_array() const
static bool ParsePrechecks(const std::string &str)
bool ParseInt32(const std::string &str, int32_t *out)
Convert string to signed 32-bit integer 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.
bool ParseDouble(const std::string &str, double *out)
Convert string to double with strict parse error feedback.
static bool json_isspace(int ch)