summaryrefslogtreecommitdiff
path: root/src/literal.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/literal.c')
-rw-r--r--src/literal.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/src/literal.c b/src/literal.c
index 8723462..66fad7f 100644
--- a/src/literal.c
+++ b/src/literal.c
@@ -17,15 +17,14 @@ enum json_parse_result parse_literal(struct json **json_out, struct raw_json *ra
char *end;
/* is probably a number here, strtodl will tell */
double num = strtod(start, &end);
- if (end != start) {
- if (raw->data[raw->index] == '-')
- num = -num;
- json = json_new_number(num);
- raw->index = end - raw->data;
- } else {
+ if (end == start) {
ret = JSON_PARSE_INVALID_NUMBER_ERR;
goto err;
}
+ if (raw->data[raw->index] == '-')
+ num = -num;
+ json = json_number(num);
+ raw->index = end - raw->data;
} else {
size_t end_index;
for (end_index = raw->index; end_index < raw->size; end_index++) {
@@ -35,11 +34,11 @@ enum json_parse_result parse_literal(struct json **json_out, struct raw_json *ra
}
size_t len = end_index - raw->index;
if (len == 4 && strncmp(raw->data + raw->index, "true", len) == 0) {
- json = json_new_bool(true);
+ json = json_bool(true);
} else if (len == 5 && strncmp(raw->data + raw->index, "false", len) == 0) {
- json = json_new_bool(false);
+ json = json_bool(false);
} else if (len == 4 && strncmp(raw->data + raw->index, "null", len) == 0) {
- json = json_new_null();
+ json = json_new();
} else {
ret = JSON_PARSE_INVALID_TOKEN_ERR;
}