| 2313 | } |
| 2314 | |
| 2315 | CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement) |
| 2316 | { |
| 2317 | if ((parent == NULL) || (parent->child == NULL) || (replacement == NULL) || (item == NULL)) |
| 2318 | { |
| 2319 | return false; |
| 2320 | } |
| 2321 | |
| 2322 | if (replacement == item) |
| 2323 | { |
| 2324 | return true; |
| 2325 | } |
| 2326 | |
| 2327 | replacement->next = item->next; |
| 2328 | replacement->prev = item->prev; |
| 2329 | |
| 2330 | if (replacement->next != NULL) |
| 2331 | { |
| 2332 | replacement->next->prev = replacement; |
| 2333 | } |
| 2334 | if (parent->child == item) |
| 2335 | { |
| 2336 | if (parent->child->prev == parent->child) |
| 2337 | { |
| 2338 | replacement->prev = replacement; |
| 2339 | } |
| 2340 | parent->child = replacement; |
| 2341 | } |
| 2342 | else |
| 2343 | { /* |
| 2344 | * To find the last item in array quickly, we use prev in array. |
| 2345 | * We can't modify the last item's next pointer where this item was the parent's child |
| 2346 | */ |
| 2347 | if (replacement->prev != NULL) |
| 2348 | { |
| 2349 | replacement->prev->next = replacement; |
| 2350 | } |
| 2351 | if (replacement->next == NULL) |
| 2352 | { |
| 2353 | parent->child->prev = replacement; |
| 2354 | } |
| 2355 | } |
| 2356 | |
| 2357 | item->next = NULL; |
| 2358 | item->prev = NULL; |
| 2359 | cJSON_Delete(item); |
| 2360 | |
| 2361 | return true; |
| 2362 | } |
| 2363 | |
| 2364 | CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem) |
| 2365 | { |
no test coverage detected