text
stringlengths 0
14.1k
|
---|
/* |
* Add to containers |
*/ |
bool json_list_append(struct JsonValue *list, struct JsonValue *val) |
{ |
if (!val) |
return false; |
if (!has_type(list, JSON_LIST)) |
return false; |
if (!is_unattached(val)) |
return false; |
set_parent(val, list); |
set_next(val, NULL); |
real_list_append(list, val); |
return true; |
} |
bool json_list_append_null(struct JsonValue *list) |
{ |
struct JsonValue *v; |
v = json_new_null(get_context(list)); |
return json_list_append(list, v); |
} |
bool json_list_append_bool(struct JsonValue *list, bool val) |
{ |
struct JsonValue *v; |
v = json_new_bool(get_context(list), val); |
return json_list_append(list, v); |
} |
bool json_list_append_int(struct JsonValue *list, int64_t val) |
{ |
struct JsonValue *v; |
v = json_new_int(get_context(list), val); |
return json_list_append(list, v); |
} |
bool json_list_append_float(struct JsonValue *list, double val) |
{ |
struct JsonValue *v; |
v = json_new_float(get_context(list), val); |
return json_list_append(list, v); |
} |
bool json_list_append_string(struct JsonValue *list, const char *val) |
{ |
struct JsonValue *v; |
v = json_new_string(get_context(list), val); |
return json_list_append(list, v); |
} |
bool json_dict_put(struct JsonValue *dict, const char *key, struct JsonValue *val) |
{ |
struct JsonValue *kjv; |
struct JsonContainer *c; |
if (!key || !val) |
return false; |
if (!has_type(dict, JSON_DICT)) |
return false; |
if (!is_unattached(val)) |
return false; |
c = get_container(dict); |
kjv = json_new_string(c->c_ctx, key); |
if (!kjv) |
return false; |
if (!real_dict_add_key(c->c_ctx, dict, kjv)) |
return false; |
set_next(kjv, val); |
set_next(val, NULL); |
set_parent(val, dict); |
return true; |
} |
bool json_dict_put_null(struct JsonValue *dict, const char *key) |
{ |
struct JsonValue *v; |
v = json_new_null(get_context(dict)); |
return json_dict_put(dict, key, v); |
} |
bool json_dict_put_bool(struct JsonValue *dict, const char *key, bool val) |
{ |
struct JsonValue *v; |
v = json_new_bool(get_context(dict), val); |