MCPcopy Create free account
hub / github.com/TheForceEngine/TheForceEngine / cJSON_InsertItemInArray

Function cJSON_InsertItemInArray

TheForceEngine/TFE_System/cJSON.c:2268–2300  ·  view source on GitHub ↗

Replace array/object items with new ones. */

Source from the content-addressed store, hash-verified

2266
2267/* Replace array/object items with new ones. */
2268CJSON_PUBLIC(cJSON_bool) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem)
2269{
2270 cJSON *after_inserted = NULL;
2271
2272 if (which < 0 || newitem == NULL)
2273 {
2274 return false;
2275 }
2276
2277 after_inserted = get_array_item(array, (size_t)which);
2278 if (after_inserted == NULL)
2279 {
2280 return add_item_to_array(array, newitem);
2281 }
2282
2283 if (after_inserted != array->child && after_inserted->prev == NULL) {
2284 /* return false if after_inserted is a corrupted array item */
2285 return false;
2286 }
2287
2288 newitem->next = after_inserted;
2289 newitem->prev = after_inserted->prev;
2290 after_inserted->prev = newitem;
2291 if (after_inserted == array->child)
2292 {
2293 array->child = newitem;
2294 }
2295 else
2296 {
2297 newitem->prev->next = newitem;
2298 }
2299 return true;
2300}
2301
2302CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement)
2303{

Callers

nothing calls this directly

Calls 2

get_array_itemFunction · 0.85
add_item_to_arrayFunction · 0.85

Tested by

no test coverage detected