34#define JSMN_API static
36#define JSMN_API extern
74#ifdef JSMN_PARENT_LINKS
100 jsmntok_t *tokens,
const unsigned int num_tokens);
107 const size_t num_tokens) {
109 if (parser->
toknext >= num_tokens) {
112 tok = &tokens[parser->
toknext++];
115#ifdef JSMN_PARENT_LINKS
125 const int start,
const int end) {
127 token->
start = start;
135static int jsmn_parse_primitive(
jsmn_parser *parser,
const char *js,
137 const size_t num_tokens) {
143 for (; parser->
pos < len && js[parser->
pos] !=
'\0'; parser->
pos++) {
144 switch (js[parser->
pos]) {
161 if (js[parser->
pos] < 32 || js[parser->
pos] >= 127) {
173 if (tokens == NULL) {
177 token = jsmn_alloc_token(parser, tokens, num_tokens);
183#ifdef JSMN_PARENT_LINKS
193static int jsmn_parse_string(
jsmn_parser *parser,
const char *js,
195 const size_t num_tokens) {
198 int start = parser->
pos;
203 for (; parser->
pos < len && js[parser->
pos] !=
'\0'; parser->
pos++) {
204 char c = js[parser->
pos];
208 if (tokens == NULL) {
211 token = jsmn_alloc_token(parser, tokens, num_tokens);
217#ifdef JSMN_PARENT_LINKS
224 if (c ==
'\\' && parser->
pos + 1 < len) {
227 switch (js[parser->
pos]) {
241 for (i = 0; i < 4 && parser->
pos < len && js[parser->
pos] !=
'\0';
244 if (!((js[parser->
pos] >= 48 && js[parser->
pos] <= 57) ||
245 (js[parser->
pos] >= 65 && js[parser->
pos] <= 70) ||
246 (js[parser->
pos] >= 97 && js[parser->
pos] <= 102))) {
269 jsmntok_t *tokens,
const unsigned int num_tokens) {
275 for (; parser->
pos < len && js[parser->
pos] !=
'\0'; parser->
pos++) {
284 if (tokens == NULL) {
287 token = jsmn_alloc_token(parser, tokens, num_tokens);
300#ifdef JSMN_PARENT_LINKS
310 if (tokens == NULL) {
314#ifdef JSMN_PARENT_LINKS
318 token = &tokens[parser->
toknext - 1];
320 if (token->
start != -1 && token->
end == -1) {
321 if (token->
type != type) {
324 token->
end = parser->
pos + 1;
328 if (token->parent == -1) {
334 token = &tokens[token->parent];
337 for (i = parser->
toknext - 1; i >= 0; i--) {
339 if (token->
start != -1 && token->
end == -1) {
340 if (token->
type != type) {
344 token->
end = parser->
pos + 1;
352 for (; i >= 0; i--) {
354 if (token->
start != -1 && token->
end == -1) {
362 r = jsmn_parse_string(parser, js, len, tokens, num_tokens);
367 if (parser->
toksuper != -1 && tokens != NULL) {
380 if (tokens != NULL && parser->
toksuper != -1 &&
383#ifdef JSMN_PARENT_LINKS
386 for (i = parser->
toknext - 1; i >= 0; i--) {
388 if (tokens[i].start != -1 && tokens[i].end == -1) {
414 if (tokens != NULL && parser->
toksuper != -1) {
425 r = jsmn_parse_primitive(parser, js, len, tokens, num_tokens);
430 if (parser->
toksuper != -1 && tokens != NULL) {
443 if (tokens != NULL) {
444 for (i = parser->
toknext - 1; i >= 0; i--) {
446 if (tokens[i].start != -1 && tokens[i].end == -1) {
jsmntype_t
Definition: jsmn.h:46
@ JSMN_PRIMITIVE
Definition: jsmn.h:51
@ JSMN_OBJECT
Definition: jsmn.h:48
@ JSMN_UNDEFINED
Definition: jsmn.h:47
@ JSMN_ARRAY
Definition: jsmn.h:49
@ JSMN_STRING
Definition: jsmn.h:50
struct jsmn_parser jsmn_parser
void jsmn_init(jsmn_parser *parser)
Definition: jsmn.h:459
#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:268
jsmnerr
Definition: jsmn.h:54
@ JSMN_ERROR_INVAL
Definition: jsmn.h:58
@ JSMN_ERROR_PART
Definition: jsmn.h:60
@ JSMN_ERROR_NOMEM
Definition: jsmn.h:56
unsigned int pos
Definition: jsmn.h:84
int toksuper
Definition: jsmn.h:86
unsigned int toknext
Definition: jsmn.h:85
int end
Definition: jsmn.h:72
int size
Definition: jsmn.h:73
int start
Definition: jsmn.h:71
jsmntype_t type
Definition: jsmn.h:70