Break up the wall of text a little

This commit is contained in:
Eric Fischer
2014-02-05 18:03:12 -08:00
parent e195aa54c3
commit 8aec0ed9d2
+20
View File
@@ -106,6 +106,8 @@ json_object *json_parse(FILE *f, json_object *current) {
return NULL; return NULL;
} }
/////////////////////////// Whitespace
while (c == ' ' || c == '\t' || c == '\r' || c == '\n') { while (c == ' ' || c == '\t' || c == '\r' || c == '\n') {
c = getc(f); c = getc(f);
if (c == EOF) { if (c == EOF) {
@@ -113,6 +115,8 @@ json_object *json_parse(FILE *f, json_object *current) {
} }
} }
/////////////////////////// Arrays
if (c == '[') { if (c == '[') {
return json_parse(f, add_object(JSON_ARRAY, current)); return json_parse(f, add_object(JSON_ARRAY, current));
} else if (c == ']') { } else if (c == ']') {
@@ -123,6 +127,8 @@ json_object *json_parse(FILE *f, json_object *current) {
return current->parent; return current->parent;
} }
/////////////////////////// Hashes
if (c == '{') { if (c == '{') {
return json_parse(f, add_object(JSON_HASH, current)); return json_parse(f, add_object(JSON_HASH, current));
} else if (c == '}') { } else if (c == '}') {
@@ -133,6 +139,8 @@ json_object *json_parse(FILE *f, json_object *current) {
return current->parent; return current->parent;
} }
/////////////////////////// Null
if (c == 'n') { if (c == 'n') {
if (getc(f) != 'u' || getc(f) != 'l' || getc(f) != 'l') { if (getc(f) != 'u' || getc(f) != 'l' || getc(f) != 'l') {
json_error("misspelled null\n"); json_error("misspelled null\n");
@@ -141,6 +149,8 @@ json_object *json_parse(FILE *f, json_object *current) {
return add_object(JSON_NULL, current); return add_object(JSON_NULL, current);
} }
/////////////////////////// True
if (c == 't') { if (c == 't') {
if (getc(f) != 'r' || getc(f) != 'u' || getc(f) != 'e') { if (getc(f) != 'r' || getc(f) != 'u' || getc(f) != 'e') {
json_error("misspelled true\n"); json_error("misspelled true\n");
@@ -149,6 +159,8 @@ json_object *json_parse(FILE *f, json_object *current) {
return add_object(JSON_TRUE, current); return add_object(JSON_TRUE, current);
} }
/////////////////////////// False
if (c == 'f') { if (c == 'f') {
if (getc(f) != 'a' || getc(f) != 'l' || getc(f) != 's' || getc(f) != 'e') { if (getc(f) != 'a' || getc(f) != 'l' || getc(f) != 's' || getc(f) != 'e') {
json_error("misspelled false\n"); json_error("misspelled false\n");
@@ -157,6 +169,8 @@ json_object *json_parse(FILE *f, json_object *current) {
return add_object(JSON_FALSE, current); return add_object(JSON_FALSE, current);
} }
/////////////////////////// Comma
if (c == ',') { if (c == ',') {
if (current->parent == NULL || if (current->parent == NULL ||
(current->parent->type != JSON_ARRAY && (current->parent->type != JSON_ARRAY &&
@@ -167,6 +181,8 @@ json_object *json_parse(FILE *f, json_object *current) {
return json_parse(f, current->parent); return json_parse(f, current->parent);
} }
/////////////////////////// Colon
if (c == ':') { if (c == ':') {
if (current->parent == NULL || current->parent->type != JSON_HASH) { if (current->parent == NULL || current->parent->type != JSON_HASH) {
json_error(": not in hash\n"); json_error(": not in hash\n");
@@ -178,6 +194,8 @@ json_object *json_parse(FILE *f, json_object *current) {
return json_parse(f, current->parent); return json_parse(f, current->parent);
} }
/////////////////////////// Numbers
if (c == '-' || (c >= '0' && c <= '9')) { if (c == '-' || (c >= '0' && c <= '9')) {
struct string val; struct string val;
string_init(&val); string_init(&val);
@@ -232,6 +250,8 @@ json_object *json_parse(FILE *f, json_object *current) {
return n; return n;
} }
/////////////////////////// Strings
if (c == '"') { if (c == '"') {
struct string val; struct string val;
string_init(&val); string_init(&val);