MCPcopy Create free account
hub / github.com/0xShug0/audio.cpp / cJSON_InsertItemInArray

Function cJSON_InsertItemInArray

external/cJSON/cJSON.c:2334–2366  ·  view source on GitHub ↗

Replace array/object items with new ones. */

Source from the content-addressed store, hash-verified

2332
2333/* Replace array/object items with new ones. */
2334CJSON_PUBLIC(cJSON_bool) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem)
2335{
2336 cJSON *after_inserted = NULL;
2337
2338 if (which < 0 || newitem == NULL)
2339 {
2340 return false;
2341 }
2342
2343 after_inserted = get_array_item(array, (size_t)which);
2344 if (after_inserted == NULL)
2345 {
2346 return add_item_to_array(array, newitem);
2347 }
2348
2349 if (after_inserted != array->child && after_inserted->prev == NULL) {
2350 /* return false if after_inserted is a corrupted array item */
2351 return false;
2352 }
2353
2354 newitem->next = after_inserted;
2355 newitem->prev = after_inserted->prev;
2356 after_inserted->prev = newitem;
2357 if (after_inserted == array->child)
2358 {
2359 array->child = newitem;
2360 }
2361 else
2362 {
2363 newitem->prev->next = newitem;
2364 }
2365 return true;
2366}
2367
2368CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement)
2369{

Callers

nothing calls this directly

Calls 2

get_array_itemFunction · 0.85
add_item_to_arrayFunction · 0.85

Tested by

no test coverage detected