diff options
Diffstat (limited to 'src/string.c')
-rw-r--r-- | src/string.c | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/src/string.c b/src/string.c index 2aea375..e5847b8 100644 --- a/src/string.c +++ b/src/string.c @@ -4,22 +4,28 @@ #include <json.h> #include "internal.h" -char *json_string_get(const struct json *str) { +char *json_string_get_mut(struct json *str) { if (str->type != JSON_STRING) return NULL; return str->string; } +const char *json_string_get_const(const struct json *string) { + return json_string_get_mut((struct json *)string); +} + enum json_parse_result parse_string(struct json **json_out, struct raw_json *raw) { - struct json *json = json_new_string(); - if (!json) + char *str; + enum json_parse_result ret = parse_raw_string(&str, raw); + if (ret != JSON_PARSE_OK) { + return ret; + } + struct json *json = json_string_from(str); + if (!json) { + free(str); return JSON_OOM; - enum json_parse_result ret = parse_raw_string(&json->string, raw); - if (ret == JSON_PARSE_OK) { - *json_out = json; - } else { - json_delete(json); } + *json_out = json; return ret; } @@ -267,6 +273,8 @@ void json_string_set(struct json *dest, const char *string) { json_clear(dest); dest->key = key; dest->type = JSON_STRING; + dest->string = strdup(string); + return; } free(dest->string); dest->string = strdup(string); |