25 return ((ch >=
'0') && (ch <=
'9'));
29static const char *
hatoui(
const char *first,
const char *last,
32 unsigned int result = 0;
33 for (; first != last; ++first)
39 else if (*first >=
'a' && *first <=
'f')
40 digit = *first -
'a' + 10;
42 else if (*first >=
'A' && *first <=
'F')
43 digit = *first -
'A' + 10;
48 result = 16 * result + digit;
56 const char *raw,
const char *end)
61 const char *rawStart = raw;
73 consumed = (raw - rawStart);
77 consumed = (raw - rawStart);
81 consumed = (raw - rawStart);
85 consumed = (raw - rawStart);
90 consumed = (raw - rawStart);
94 consumed = (raw - rawStart);
100 if (!strncmp(raw,
"null", 4)) {
102 consumed = (raw - rawStart);
104 }
else if (!strncmp(raw,
"true", 4)) {
106 consumed = (raw - rawStart);
108 }
else if (!strncmp(raw,
"false", 5)) {
110 consumed = (raw - rawStart);
129 const char *first = raw;
131 const char *firstDigit = first;
134 if ((*firstDigit ==
'0') &&
json_isdigit(firstDigit[1]))
140 if ((*first ==
'-') && (raw < end) && (!
json_isdigit(*raw)))
149 if (raw < end && *raw ==
'.') {
162 if (raw < end && (*raw ==
'e' || *raw ==
'E')) {
166 if (raw < end && (*raw ==
'-' || *raw ==
'+')) {
180 consumed = (raw - rawStart);
191 if (raw >= end || (
unsigned char)*raw < 0x20)
194 else if (*raw ==
'\\') {
202 case '\\': writer.
push_back(
'\\');
break;
211 unsigned int codepoint;
212 if (raw + 1 + 4 >= end ||
213 hatoui(raw + 1, raw + 1 + 4, codepoint) !=
228 else if (*raw ==
'"') {
234 writer.
push_back(
static_cast<unsigned char>(*raw));
242 consumed = (raw - rawStart);
259#define expect(bit) (expectMask & (EXP_##bit))
260#define setExpect(bit) (expectMask |= EXP_##bit)
261#define clearExpect(bit) (expectMask &= ~EXP_##bit)
267 uint32_t expectMask = 0;
268 std::vector<UniValue*> stack;
270 std::string tokenVal;
271 unsigned int consumed;
274 const char* raw{str_in.data()};
275 const char* end{raw + str_in.size()};
292 }
else if (
expect(ARR_VALUE)) {
299 }
else if (
expect(OBJ_NAME)) {
304 }
else if (
expect(COLON)) {
329 stack.push_back(
this);
333 top->
values.push_back(tmpVal);
351 if (!stack.size() || (last_tok ==
JTOK_COMMA))
413 top->
values.push_back(tmpVal);
427 top->
values.push_back(tmpVal);
436 top->
keys.push_back(tokenVal);
446 top->
values.push_back(tmpVal);
456 }
while (!stack.empty ());
Filter that generates and validates UTF-8, as well as collates UTF-16 surrogate pairs as specified in...
void push_back(unsigned char ch)
void push_back_u(unsigned int codepoint_)
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)