summaryrefslogtreecommitdiff
path: root/json_tokener.c
diff options
context:
space:
mode:
authorEric Haszlakiewicz <erh+git@nimenees.com>2012-02-22 08:24:40 -0600
committerEric Haszlakiewicz <erh+git@nimenees.com>2012-02-22 08:24:40 -0600
commit2f9091f55962ac64c2aedcd3287e9b280fce0b6a (patch)
treec3109446ed467197c8b0fea774f27e1d93f83176 /json_tokener.c
parentb21b1378053285b3204857e87879fb3dc0197f8d (diff)
Add json_tokener_get_error() and json_tokener_error_desc() to better encapsulate the process of retrieving errors while parsing.
Add documentation for the json_tokener_parse_ex() function.
Diffstat (limited to 'json_tokener.c')
-rw-r--r--json_tokener.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/json_tokener.c b/json_tokener.c
index 1921de6..6d973ec 100644
--- a/json_tokener.c
+++ b/json_tokener.c
@@ -43,6 +43,7 @@ static const char* json_null_str = "null";
static const char* json_true_str = "true";
static const char* json_false_str = "false";
+// XXX after v0.10 this array will become static:
const char* json_tokener_errors[] = {
"success",
"continue",
@@ -60,6 +61,18 @@ const char* json_tokener_errors[] = {
"expected comment",
};
+const char *json_tokener_error_desc(enum json_tokener_error jerr)
+{
+ if (jerr < 0 || jerr > sizeof(json_tokener_errors))
+ return "Unknown error, invalid json_tokener_error value passed to json_tokener_error_desc()";
+ return json_tokener_errors[jerr];
+}
+
+enum json_tokener_error json_tokener_get_error(json_tokener *tok)
+{
+ return tok->err;
+}
+
/* Stuff for decoding unicode sequences */
#define IS_HIGH_SURROGATE(uc) (((uc) & 0xFC00) == 0xD800)
#define IS_LOW_SURROGATE(uc) (((uc) & 0xFC00) == 0xDC00)