From c913f0eec1fa60131ab78f4f64647aaca3e78593 Mon Sep 17 00:00:00 2001 From: Eric Fischer Date: Wed, 5 Feb 2014 15:42:15 -0800 Subject: [PATCH] Add null, true, false --- json.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/json.c b/json.c index f8d143c..eb59839 100644 --- a/json.c +++ b/json.c @@ -45,7 +45,7 @@ json_object *parse(FILE *f, json_object *current) { return NULL; } - while (isspace(c)) { + while (c == ' ' || c == '\t' || c == '\r' || c == '\n') { c = getc(f); if (c == EOF) { return NULL; @@ -71,4 +71,28 @@ json_object *parse(FILE *f, json_object *current) { return current->parent; } + + if (c == 'n') { + if (getc(f) != 'u' || getc(f) != 'l' || getc(f) != 'l') { + json_error("misspelled null"); + } + + return new_object(JSON_NULL, current); + } + + if (c == 't') { + if (getc(f) != 'r' || getc(f) != 'u' || getc(f) != 'e') { + json_error("misspelled true"); + } + + return new_object(JSON_TRUE, current); + } + + if (c == 'f') { + if (getc(f) != 'a' || getc(f) != 'l' || getc(f) != 's' || getc(f) != 'e') { + json_error("misspelled false"); + } + + return new_object(JSON_TRUE, current); + } }