24 return ((ch >=
'0') && (ch <=
'9'));
28static const char *
hatoui(
const char *first,
const char *last,
30 unsigned int result = 0;
31 for (; first != last; ++first) {
35 }
else if (*first >=
'a' && *first <=
'f') {
36 digit = *first -
'a' + 10;
37 }
else if (*first >=
'A' && *first <=
'F') {
38 digit = *first -
'A' + 10;
43 result = 16 * result + digit;
51 const char *raw,
const char *end) {
55 const char *rawStart = raw;
69 consumed = (raw - rawStart);
73 consumed = (raw - rawStart);
77 consumed = (raw - rawStart);
81 consumed = (raw - rawStart);
86 consumed = (raw - rawStart);
90 consumed = (raw - rawStart);
96 if (!strncmp(raw,
"null", 4)) {
98 consumed = (raw - rawStart);
100 }
else if (!strncmp(raw,
"true", 4)) {
102 consumed = (raw - rawStart);
104 }
else if (!strncmp(raw,
"false", 5)) {
106 consumed = (raw - rawStart);
126 const char *first = raw;
128 const char *firstDigit = first;
132 if ((*firstDigit ==
'0') &&
json_isdigit(firstDigit[1])) {
140 if ((*first ==
'-') && (raw < end) && (!
json_isdigit(*raw))) {
151 if (raw < end && *raw ==
'.') {
167 if (raw < end && (*raw ==
'e' || *raw ==
'E')) {
171 if (raw < end && (*raw ==
'-' || *raw ==
'+')) {
187 consumed = (raw - rawStart);
199 if (raw >= end || (uint8_t)*raw < 0x20) {
201 }
else if (*raw ==
'\\') {
235 unsigned int codepoint;
236 if (raw + 1 + 4 >= end ||
237 hatoui(raw + 1, raw + 1 + 4, codepoint) !=
251 }
else if (*raw ==
'"') {
257 writer.
push_back(
static_cast<uint8_t
>(*raw));
266 consumed = (raw - rawStart);
283#define expect(bit) (expectMask & (EXP_##bit))
284#define setExpect(bit) (expectMask |= EXP_##bit)
285#define clearExpect(bit) (expectMask &= ~EXP_##bit)
290 uint32_t expectMask = 0;
291 std::vector<UniValue *> stack;
293 std::string tokenVal;
294 unsigned int consumed;
297 const char *raw{str_in.data()};
298 const char *end{raw + str_in.size()};
316 }
else if (
expect(ARR_VALUE)) {
323 }
else if (
expect(OBJ_NAME)) {
328 }
else if (
expect(COLON)) {
354 stack.push_back(
this);
358 top->
values.push_back(tmpVal);
378 if (!stack.size() || (last_tok ==
JTOK_COMMA)) {
409 if (!stack.size() || (last_tok ==
JTOK_COMMA) ||
448 top->
values.push_back(tmpVal);
462 top->
values.push_back(tmpVal);
471 top->
keys.push_back(tokenVal);
481 top->
values.push_back(tmpVal);
491 }
while (!stack.empty());
Filter that generates and validates UTF-8, as well as collates UTF-16 surrogate pairs as specified in...
void push_back_u(unsigned int codepoint_)
void push_back(uint8_t ch)
void push_back(UniValue val)
enum VType getType() const
std::vector< UniValue > values
std::vector< std::string > keys
bool read(std::string_view raw)
static bool jsonTokenIsValue(enum jtokentype jtt)
static bool json_isspace(int ch)
static bool json_isdigit(int ch)
static constexpr size_t MAX_JSON_DEPTH
enum jtokentype getJsonToken(std::string &tokenVal, unsigned int &consumed, const char *raw, const char *end)
static const char * hatoui(const char *first, const char *last, unsigned int &out)