Merge pull request #123 from jjwchoy/decode-ignore-int

Implemented a decode option to only decode numbers to reals
This commit is contained in:
Petri Lehtinen
2013-06-11 22:23:40 -07:00
5 changed files with 51 additions and 5 deletions

View File

@@ -236,9 +236,10 @@ json_t *json_deep_copy(json_t *value);
/* decoding */
#define JSON_REJECT_DUPLICATES 0x1
#define JSON_DISABLE_EOF_CHECK 0x2
#define JSON_DECODE_ANY 0x4
#define JSON_REJECT_DUPLICATES 0x1
#define JSON_DISABLE_EOF_CHECK 0x2
#define JSON_DECODE_ANY 0x4
#define JSON_DECODE_INT_AS_REAL 0x8
typedef size_t (*json_load_callback_t)(void *buffer, size_t buflen, void *data);

View File

@@ -775,6 +775,7 @@ error:
static json_t *parse_value(lex_t *lex, size_t flags, json_error_t *error)
{
json_t *json;
double value;
switch(lex->token) {
case TOKEN_STRING: {
@@ -783,7 +784,15 @@ static json_t *parse_value(lex_t *lex, size_t flags, json_error_t *error)
}
case TOKEN_INTEGER: {
json = json_integer(lex->value.integer);
if (flags & JSON_DECODE_INT_AS_REAL) {
if(jsonp_strtod(&lex->saved_text, &value)) {
error_set(error, lex, "real number overflow");
return NULL;
}
json = json_real(value);
} else {
json = json_integer(lex->value.integer);
}
break;
}