34 #define JSMN_API static
36 #define JSMN_API extern
68 #ifdef JSMN_PARENT_LINKS
102 if (parser->
toknext >= num_tokens) {
105 tok = &tokens[parser->
toknext++];
108 #ifdef JSMN_PARENT_LINKS
117 static void jsmn_fill_token(
jsmntok_t* token,
const jsmntype_t type,
const int start,
const int end)
120 token->
start = start;
128 static int jsmn_parse_primitive(
jsmn_parser* parser,
const char* js,
const size_t len,
jsmntok_t* tokens,
const size_t num_tokens)
135 for (; parser->
pos < len && js[parser->
pos] !=
'\0'; parser->
pos++) {
136 switch (js[parser->
pos]) {
150 if (js[parser->
pos] < 32 || js[parser->
pos] >= 127) {
162 if (tokens == NULL) {
166 token = jsmn_alloc_token(parser, tokens, num_tokens);
172 #ifdef JSMN_PARENT_LINKS
182 static int jsmn_parse_string(
jsmn_parser* parser,
const char* js,
const size_t len,
jsmntok_t* tokens,
const size_t num_tokens)
186 int start = parser->
pos;
191 for (; parser->
pos < len && js[parser->
pos] !=
'\0'; parser->
pos++) {
192 char c = js[parser->
pos];
196 if (tokens == NULL) {
199 token = jsmn_alloc_token(parser, tokens, num_tokens);
205 #ifdef JSMN_PARENT_LINKS
212 if (c ==
'\\' && parser->
pos + 1 < len) {
215 switch (js[parser->
pos]) {
229 for (i = 0; i < 4 && parser->
pos < len && js[parser->
pos] !=
'\0'; i++) {
231 if (!((js[parser->
pos] >= 48 && js[parser->
pos] <= 57) ||
232 (js[parser->
pos] >= 65 && js[parser->
pos] <= 70) ||
233 (js[parser->
pos] >= 97 && js[parser->
pos] <= 102))) {
262 for (; parser->
pos < len && js[parser->
pos] !=
'\0'; parser->
pos++) {
271 if (tokens == NULL) {
274 token = jsmn_alloc_token(parser, tokens, num_tokens);
287 #ifdef JSMN_PARENT_LINKS
297 if (tokens == NULL) {
301 #ifdef JSMN_PARENT_LINKS
305 token = &tokens[parser->
toknext - 1];
307 if (token->
start != -1 && token->
end == -1) {
308 if (token->
type != type) {
311 token->
end = parser->
pos + 1;
315 if (token->parent == -1) {
321 token = &tokens[token->parent];
324 for (i = parser->
toknext - 1; i >= 0; i--) {
326 if (token->
start != -1 && token->
end == -1) {
327 if (token->
type != type) {
331 token->
end = parser->
pos + 1;
339 for (; i >= 0; i--) {
341 if (token->
start != -1 && token->
end == -1) {
349 r = jsmn_parse_string(parser, js, len, tokens, num_tokens);
354 if (parser->
toksuper != -1 && tokens != NULL) {
369 #ifdef JSMN_PARENT_LINKS
372 for (i = parser->
toknext - 1; i >= 0; i--) {
374 if (tokens[i].start != -1 && tokens[i].end == -1) {
400 if (tokens != NULL && parser->
toksuper != -1) {
410 r = jsmn_parse_primitive(parser, js, len, tokens, num_tokens);
415 if (parser->
toksuper != -1 && tokens != NULL) {
428 if (tokens != NULL) {
429 for (i = parser->
toknext - 1; i >= 0; i--) {
431 if (tokens[i].start != -1 && tokens[i].end == -1) {
jsmntype_t
Definition: jsmn.h:46
@ JSMN_PRIMITIVE
Definition: jsmn.h:46
@ JSMN_OBJECT
Definition: jsmn.h:46
@ JSMN_UNDEFINED
Definition: jsmn.h:46
@ JSMN_ARRAY
Definition: jsmn.h:46
@ JSMN_STRING
Definition: jsmn.h:46
void jsmn_init(jsmn_parser *parser)
Definition: jsmn.h:444
#define JSMN_API
Definition: jsmn.h:36
int jsmn_parse(jsmn_parser *parser, const char *js, const size_t len, jsmntok_t *tokens, const unsigned int num_tokens)
Definition: jsmn.h:255
jsmnerr
Definition: jsmn.h:48
@ JSMN_ERROR_INVAL
Definition: jsmn.h:52
@ JSMN_ERROR_PART
Definition: jsmn.h:54
@ JSMN_ERROR_NOMEM
Definition: jsmn.h:50
unsigned int pos
Definition: jsmn.h:78
int toksuper
Definition: jsmn.h:80
unsigned int toknext
Definition: jsmn.h:79
int start
Definition: jsmn.h:65
int size
Definition: jsmn.h:67
int end
Definition: jsmn.h:66
jsmntype_t type
Definition: jsmn.h:64