text
stringlengths 0
14.1k
|
---|
if (hasesc) { |
dst = process_escapes(ctx, start, strend, dst, dstend); |
if (!dst) |
return false; |
} else { |
dst = plain_copy(dst, start, strend); |
} |
*dst = '\0'; |
jv->u.v_size = dst - get_cstring(jv); |
ctx->linenr += lines; |
*src_p = strend + 1; |
return true; |
} |
/* |
* Helpers for relaxed parsing |
*/ |
static bool skip_comment(struct JsonContext *ctx, const char **src_p, const char *end) |
{ |
const char *s, *start; |
char c; |
size_t lnr; |
s = start = *src_p; |
if (s >= end) |
return false; |
c = *s++; |
if (c == '/') { |
s = memchr(s, '\n', end - s); |
if (s) { |
ctx->linenr++; |
*src_p = s + 1; |
} else { |
*src_p = end; |
} |
return true; |
} else if (c == '*') { |
for (lnr = 0; s + 2 <= end; s++) { |
if (s[0] == '*' && s[1] == '/') { |
ctx->linenr += lnr; |
*src_p = s + 2; |
return true; |
} else if (s[0] == '\n') { |
lnr++; |
} |
} |
} |
return false; |
} |
static bool skip_extra_comma(struct JsonContext *ctx, const char **src_p, const char *end, enum ParseState state) |
{ |
bool skip = false; |
const char *src = *src_p; |
while (src < end && isspace(*src)) { |
if (*src == '\n') |
ctx->linenr++; |
src++; |
} |
if (src < end) { |
if (*src == '}') { |
if (state == S_DICT_COMMA_OR_CLOSE || state == S_DICT_KEY_OR_CLOSE) |
skip = true; |
} else if (*src == ']') { |
if (state == S_LIST_COMMA_OR_CLOSE || state == S_LIST_VALUE_OR_CLOSE) |
skip = true; |
} |
} |
*src_p = src; |
return skip; |
} |
/* |
* Main parser |
*/ |
/* oldstate + token -> newstate */ |
static const unsigned char STATE_STEPS[MAX_STATES][MAX_TOKENS] = { |
[S_INITIAL_VALUE] = { |
[T_OPEN_LIST] = S_LIST_VALUE_OR_CLOSE, |
[T_OPEN_DICT] = S_DICT_KEY_OR_CLOSE, |
[T_STRING] = S_DONE, |
[T_OTHER] = S_DONE }, |
[S_LIST_VALUE] = { |
[T_OPEN_LIST] = S_LIST_VALUE_OR_CLOSE, |
[T_OPEN_DICT] = S_DICT_KEY_OR_CLOSE, |
[T_STRING] = S_LIST_COMMA_OR_CLOSE, |
[T_OTHER] = S_LIST_COMMA_OR_CLOSE }, |
[S_LIST_VALUE_OR_CLOSE] = { |
[T_OPEN_LIST] = S_LIST_VALUE_OR_CLOSE, |
[T_OPEN_DICT] = S_DICT_KEY_OR_CLOSE, |
[T_STRING] = S_LIST_COMMA_OR_CLOSE, |
[T_OTHER] = S_LIST_COMMA_OR_CLOSE, |
[T_CLOSE_LIST] = S_PARENT }, |
[S_LIST_COMMA_OR_CLOSE] = { |
[T_COMMA] = S_LIST_VALUE, |