diff --git a/Makefile b/Makefile index dc90eab..53a7403 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -CFLAGS=-Wall -std=c89 -g +CFLAGS=-Wall -std=c89 -g -O2 OBJS=jsmn.o demo.o diff --git a/demo.c b/demo.c index 0c2d18b..1d32944 100644 --- a/demo.c +++ b/demo.c @@ -19,18 +19,15 @@ static void jsmn_dump_obj(jsontok_t *obj, const char *js) { len = obj->end - obj->start; - printf("[%d,%d]\t", obj->start, obj->end); + printf("[%3d,%3d]\t", obj->start, obj->end); char *type; switch (obj->type) { - case JSON_OTHER: - type = "(?)"; - break; - case JSON_NUMBER: - type = "(N)"; + case JSON_PRIMITIVE: + type = "(.)"; break; case JSON_STRING: - type = "(S)"; + type = "(s)"; break; case JSON_ARRAY: type = "(A)"; @@ -91,7 +88,6 @@ int main(int argc, char *argv[]) { r = jsmn_parse(&parser); if (r < 0) { printf("error %d at pos %d: %s\n", r, parser.pos, &js[parser.pos]); - exit(EXIT_FAILURE); } for (i = 0; inum_tokens; i++) { parser->tokens[i].start = -1; parser->tokens[i].end = -1; - parser->tokens[i].type = JSON_OTHER; + parser->tokens[i].type = JSON_PRIMITIVE; } } @@ -49,7 +49,7 @@ static int jsmn_parse_primitive(jsmn_parser *parser) { js = parser->js; - token = jsmn_start_token(parser, JSON_NUMBER); + token = jsmn_start_token(parser, JSON_PRIMITIVE); for (; js[parser->pos] != '\0'; parser->pos++) { switch (js[parser->pos]) { @@ -66,7 +66,6 @@ static int jsmn_parse_primitive(jsmn_parser *parser) { return JSMN_ERROR_PART; } - static int jsmn_parse_string(jsmn_parser *parser) { const char *js; jsontok_t *token; @@ -112,7 +111,6 @@ static int jsmn_parse_string(jsmn_parser *parser) { return JSMN_ERROR_PART; } - jsmnerr_t jsmn_parse(jsmn_parser *parser) { const char *js; jsontype_t type; @@ -131,6 +129,7 @@ jsmnerr_t jsmn_parse(jsmn_parser *parser) { case '}': case ']': type = (c == '}' ? JSON_OBJECT : JSON_ARRAY); token = jsmn_end_token(parser, type); + token->end++; break; case '-': case '0': case '1' : case '2': case '3' : case '4': case '5': case '6': case '7' : case '8': case '9': diff --git a/jsmn.h b/jsmn.h index f045a08..959e942 100644 --- a/jsmn.h +++ b/jsmn.h @@ -10,11 +10,10 @@ * o Other primitive: boolean (true/false) or null */ typedef enum { - JSON_OTHER = 0, + JSON_PRIMITIVE = 0, JSON_OBJECT = 1, JSON_ARRAY = 2, - JSON_STRING = 3, - JSON_NUMBER = 4 + JSON_STRING = 3 } jsontype_t; typedef enum {