summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSerge A. Zaitsev <devnull@localhost>2010-11-16 13:50:13 +0200
committerSerge A. Zaitsev <devnull@localhost>2010-11-16 13:50:13 +0200
commita2755a75953e61fffb6210c16ddbaee1e4f6ff90 (patch)
tree693e11e2c85f3f2ce11e3ee57cd1ba476570490e
parentdaf93a0ebd10e3778ec77a62577543fb11884c83 (diff)
Design: some error codes added
-rw-r--r--jsmn.c18
-rw-r--r--jsmn.h7
2 files changed, 16 insertions, 9 deletions
diff --git a/jsmn.c b/jsmn.c
index 2ba4e536a..dbf5b2fba 100644
--- a/jsmn.c
+++ b/jsmn.c
@@ -129,35 +129,35 @@ int jsmn_parse(const unsigned char *js, jsontok_t *tokens, size_t num_tokens, in
case '{': case '[':
type = (*p == '{' ? JSON_OBJECT : JSON_ARRAY);
cur_token = jsmn_token_start(&params, type, p - js);
- jsmn_assert(cur_token != NULL, -1);
+ jsmn_assert(cur_token != NULL, JSMN_ERROR_NOMEM);
break;
case '}' : case ']':
type = (*p == '}' ? JSON_OBJECT : JSON_ARRAY);
cur_token = jsmn_token_end(&params, type, p - js + 1);
- jsmn_assert(cur_token != NULL, -1);
+ jsmn_assert(cur_token != NULL, JSMN_ERROR_PART);
break;
case '-': case '0': case '1' : case '2': case '3' : case '4':
case '5': case '6': case '7' : case '8': case '9':
cur_token = jsmn_token_start(&params, JSON_NUMBER, p - js);
- jsmn_assert(cur_token != NULL, -1);
+ jsmn_assert(cur_token != NULL, JSMN_ERROR_NOMEM);
r = jsmn_parse_primitive(js, cur_token);
- jsmn_assert(r == 0, -2);
+ jsmn_assert(r == 0, JSMN_ERROR_INVAL);
p = &js[cur_token->end] - 1;
break;
case 't': case 'f': case 'n' :
cur_token = jsmn_token_start(&params, JSON_OTHER, p - js);
- jsmn_assert(cur_token != NULL, -1);
+ jsmn_assert(cur_token != NULL, JSMN_ERROR_NOMEM);
r = jsmn_parse_primitive(js, cur_token);
- jsmn_assert(r == 0, -2);
+ jsmn_assert(r == 0, JSMN_ERROR_INVAL);
p = &js[cur_token->end] - 1;
break;
case '\"':
cur_token = jsmn_token_start(&params, JSON_STRING, p - js);
- jsmn_assert(cur_token != NULL, -1);
+ jsmn_assert(cur_token != NULL, JSMN_ERROR_NOMEM);
r = jsmn_parse_string(js, cur_token);
- jsmn_assert(r == 0, -2);
+ jsmn_assert(r == 0, JSMN_ERROR_INVAL);
p = &js[cur_token->end];
break;
@@ -165,7 +165,7 @@ int jsmn_parse(const unsigned char *js, jsontok_t *tokens, size_t num_tokens, in
break;
default:
- jsmn_assert(0, -1); /* Assert always fails */
+ jsmn_return(JSMN_ERROR_INVAL);
}
p++;
}
diff --git a/jsmn.h b/jsmn.h
index 06f2f516a..408c53843 100644
--- a/jsmn.h
+++ b/jsmn.h
@@ -17,6 +17,13 @@ typedef enum {
JSON_NUMBER
} jsontype_t;
+typedef enum {
+ JSMN_ERROR_NOMEM = -1,
+ JSMN_ERROR_INVAL = -2,
+ JSMN_ERROR_PART = -3,
+ JSMN_SUCCESS = 0
+} jsmnerr_t;
+
/**
* JSON token description.
* @param type type (object, array, string etc.)