From 0568be6e0b1304226ddf8b17f3df4a5dfa2babdd Mon Sep 17 00:00:00 2001 From: "Serge A. Zaitsev" Date: Mon, 15 Nov 2010 15:00:42 +0200 Subject: Demo separated from the jsmn code. Makefile changed. Some comments added --- jsmn.c | 60 ++---------------------------------------------------------- 1 file changed, 2 insertions(+), 58 deletions(-) (limited to 'jsmn.c') diff --git a/jsmn.c b/jsmn.c index 334249476..50123373e 100644 --- a/jsmn.c +++ b/jsmn.c @@ -1,5 +1,4 @@ #include -#include #include "jsmn.h" @@ -53,7 +52,7 @@ int jsmn_parse(const unsigned char *js, jsontok_t *tokens, size_t num_tokens, in } int jsmn_token_end(jsontype_t type, int pos) { - unsigned int i; + int i; for (i = num_tokens - 1; i>= 0; i--) { if (tokens[i].type == type && tokens[i].start != -1 && tokens[i].end == -1) { tokens[i].end = pos; @@ -64,7 +63,6 @@ int jsmn_parse(const unsigned char *js, jsontok_t *tokens, size_t num_tokens, in } const unsigned char *p; - jsontok_t *cur_token; int obj_common[] = { JSON_SYM_ERROR(0 ... 255), @@ -96,9 +94,7 @@ int jsmn_parse(const unsigned char *js, jsontok_t *tokens, size_t num_tokens, in int *obj_state = obj_common; - cur_token = tokens; - - int i; + unsigned int i; for (i = 0; istart, obj->end); - len = obj->end - obj->start; - - char *type; - switch (obj->type) { - case JSON_OTHER: - type = "other"; - break; - case JSON_STRING: - type = "string"; - break; - case JSON_ARRAY: - type = "array"; - break; - case JSON_OBJECT: - type = "object"; - break; - } - - printf(" %s ", type); - - if (len > 0) { - char *s = strndup(&js[obj->start], len); - printf("%s", s); - free(s); - } - printf("\n"); -} - -int main(int argc, char *argv[]) { - int i; -#define NUM_TOKENS 20 - jsontok_t tokens[NUM_TOKENS]; - - const char *js = - "{" - "\"foo\": \"bar\"," - "\"bar\": [1,2, 3]," - "\"obj\": { \"true\": false}" - "}"; - - jsmn_parse(js, tokens, NUM_TOKENS, NULL); - - for (i = 0; i