From 73cf86acdbf9f28cc77ce71a84b8334f0c5b0dca Mon Sep 17 00:00:00 2001 From: Eric Fischer Date: Wed, 26 Feb 2014 17:00:10 -0800 Subject: [PATCH] Preserve the original string representation of numbers too. Not always useful, but sometimes it will be. --- README.md | 4 +++- jsonpull.c | 7 +++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ab59a29..4fb40bc 100644 --- a/README.md +++ b/README.md @@ -99,7 +99,9 @@ have no additional data. Strings have type JSON_STRING, with null-terminated UTF-8 text in string and length in length. -Numbers have type JSON_NUMBER, with value in number. +Numbers have type JSON_NUMBER, with value in number, +and also preserve the original representation of the number +in string and length in length. Arrays have type JSON_ARRAY. There are length elements in the array, and the elements are in array. diff --git a/jsonpull.c b/jsonpull.c index 16f6768..5977f8f 100644 --- a/jsonpull.c +++ b/jsonpull.c @@ -414,8 +414,11 @@ again: json_object *n = add_object(j, JSON_NUMBER); if (n != NULL) { n->number = atof(val.buf); + n->string = val.buf; + n->length = val.n; + } else { + string_free(&val); } - string_free(&val); return n; } @@ -542,7 +545,7 @@ void json_free(json_object *o) { free(k); free(v); - } else if (o->type == JSON_STRING) { + } else if (o->type == JSON_STRING || o->type == JSON_NUMBER) { free(o->string); }