MCPcopy Create free account
hub / github.com/ading2210/linuxpdf / json_object_set

Function json_object_set

tinyemu/json.c:122–146  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

120}
121
122int json_object_set(JSONValue val, const char *name, JSONValue prop_val)
123{
124 JSONObject *obj;
125 JSONProperty *f;
126 int new_size;
127
128 if (val.type != JSON_OBJ)
129 return -1;
130 obj = val.u.obj;
131 f = json_object_get2(obj, name);
132 if (f) {
133 json_free(f->value);
134 f->value = prop_val;
135 } else {
136 if (obj->len >= obj->size) {
137 new_size = max_int(obj->len + 1, obj->size * 3 / 2);
138 obj->props = realloc(obj->props, new_size * sizeof(JSONProperty));
139 obj->size = new_size;
140 }
141 f = &obj->props[obj->len++];
142 f->name = json_string_new(name);
143 f->value = prop_val;
144 }
145 return 0;
146}
147
148JSONValue json_array_get(JSONValue val, unsigned int idx)
149{

Callers 1

json_parse_value2Function · 0.85

Calls 4

json_object_get2Function · 0.85
json_freeFunction · 0.85
max_intFunction · 0.85
json_string_newFunction · 0.85

Tested by

no test coverage detected