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.
This commit is contained in:
Eric Haszlakiewicz
2012-02-22 08:24:40 -06:00
parent b21b137805
commit 2f9091f559
2 changed files with 102 additions and 0 deletions

View File

@@ -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)