From 1dd3e1c8d7deb0fa6fe6208b2dd8d236d1f3fc2e Mon Sep 17 00:00:00 2001 From: "Anna (navi) Figueiredo Gomes" Date: Fri, 12 Apr 2024 12:18:03 +0200 Subject: libjson: new api a lot... changed... Signed-off-by: Anna (navi) Figueiredo Gomes --- src/literal.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'src/literal.c') 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; } -- cgit v1.2.3