MCPcopy Create free account
hub / github.com/antirez/botlib / cJSON_InsertItemInArray

Function cJSON_InsertItemInArray

cJSON.c:2259–2286  ·  view source on GitHub ↗

Replace array/object items with new ones. */

Source from the content-addressed store, hash-verified

2257
2258/* Replace array/object items with new ones. */
2259CJSON_PUBLIC(cJSON_bool) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem)
2260{
2261 cJSON *after_inserted = NULL;
2262
2263 if (which < 0)
2264 {
2265 return false;
2266 }
2267
2268 after_inserted = get_array_item(array, (size_t)which);
2269 if (after_inserted == NULL)
2270 {
2271 return add_item_to_array(array, newitem);
2272 }
2273
2274 newitem->next = after_inserted;
2275 newitem->prev = after_inserted->prev;
2276 after_inserted->prev = newitem;
2277 if (after_inserted == array->child)
2278 {
2279 array->child = newitem;
2280 }
2281 else
2282 {
2283 newitem->prev->next = newitem;
2284 }
2285 return true;
2286}
2287
2288CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement)
2289{

Callers

nothing calls this directly

Calls 2

get_array_itemFunction · 0.85
add_item_to_arrayFunction · 0.85

Tested by

no test coverage detected