|
|
@ -100,6 +100,12 @@ static jsontok_t *jsmn_token_end(struct jsmn_params *params, jsontype_t type, in
|
|
|
|
|
|
|
|
|
|
|
|
int jsmn_parse(const unsigned char *js, jsontok_t *tokens, size_t num_tokens, int *errpos) {
|
|
|
|
int jsmn_parse(const unsigned char *js, jsontok_t *tokens, size_t num_tokens, int *errpos) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define jsmn_assert(cond, pos, err) \
|
|
|
|
|
|
|
|
if (!(cond)) { \
|
|
|
|
|
|
|
|
jsmn_error(¶ms, pos); \
|
|
|
|
|
|
|
|
return (err); \
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct jsmn_params params;
|
|
|
|
struct jsmn_params params;
|
|
|
|
|
|
|
|
|
|
|
|
int r;
|
|
|
|
int r;
|
|
|
@ -122,11 +128,13 @@ int jsmn_parse(const unsigned char *js, jsontok_t *tokens, size_t num_tokens, in
|
|
|
|
case '{': case '[':
|
|
|
|
case '{': case '[':
|
|
|
|
type = (*p == '{' ? JSON_OBJECT : JSON_ARRAY);
|
|
|
|
type = (*p == '{' ? JSON_OBJECT : JSON_ARRAY);
|
|
|
|
cur_token = jsmn_token_start(¶ms, type, p - js);
|
|
|
|
cur_token = jsmn_token_start(¶ms, type, p - js);
|
|
|
|
|
|
|
|
jsmn_assert(cur_token != NULL, p - js, -1);
|
|
|
|
cur_token->start = p - js;
|
|
|
|
cur_token->start = p - js;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case '}' : case ']':
|
|
|
|
case '}' : case ']':
|
|
|
|
type = (*p == '}' ? JSON_OBJECT : JSON_ARRAY);
|
|
|
|
type = (*p == '}' ? JSON_OBJECT : JSON_ARRAY);
|
|
|
|
cur_token = jsmn_token_end(¶ms, type, p - js + 1);
|
|
|
|
cur_token = jsmn_token_end(¶ms, type, p - js + 1);
|
|
|
|
|
|
|
|
jsmn_assert(cur_token != NULL, p - js, -1);
|
|
|
|
cur_token->end = p - js + 1;
|
|
|
|
cur_token->end = p - js + 1;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
@ -134,21 +142,17 @@ int jsmn_parse(const unsigned char *js, jsontok_t *tokens, size_t num_tokens, in
|
|
|
|
case '5': case '6': case '7' : case '8': case '9':
|
|
|
|
case '5': case '6': case '7' : case '8': case '9':
|
|
|
|
case 't': case 'f': case 'n' :
|
|
|
|
case 't': case 'f': case 'n' :
|
|
|
|
cur_token = jsmn_token_start(¶ms, JSON_OTHER, p - js);
|
|
|
|
cur_token = jsmn_token_start(¶ms, JSON_OTHER, p - js);
|
|
|
|
|
|
|
|
jsmn_assert(cur_token != NULL, p - js, -1);
|
|
|
|
r = jsmn_parse_primitive(js, cur_token);
|
|
|
|
r = jsmn_parse_primitive(js, cur_token);
|
|
|
|
if (r < 0) {
|
|
|
|
jsmn_assert(r == 0, p - js, -2);
|
|
|
|
jsmn_error(¶ms, p - js);
|
|
|
|
p = &js[cur_token->end] - 1;
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
p = &js[cur_token->end];
|
|
|
|
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case '\"':
|
|
|
|
case '\"':
|
|
|
|
cur_token = jsmn_token_start(¶ms, JSON_STRING, p - js);
|
|
|
|
cur_token = jsmn_token_start(¶ms, JSON_STRING, p - js);
|
|
|
|
|
|
|
|
jsmn_assert(cur_token != NULL, p - js, -1);
|
|
|
|
r = jsmn_parse_string(js, cur_token);
|
|
|
|
r = jsmn_parse_string(js, cur_token);
|
|
|
|
if (r < 0) {
|
|
|
|
jsmn_assert(r == 0, p - js, -2);
|
|
|
|
jsmn_error(¶ms, p - js);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
p = &js[cur_token->end];
|
|
|
|
p = &js[cur_token->end];
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|