| 2293 | } |
| 2294 | |
| 2295 | CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement) |
| 2296 | { |
| 2297 | if ((parent == NULL) || (replacement == NULL) || (item == NULL)) |
| 2298 | { |
| 2299 | return false; |
| 2300 | } |
| 2301 | |
| 2302 | if (replacement == item) |
| 2303 | { |
| 2304 | return true; |
| 2305 | } |
| 2306 | |
| 2307 | replacement->next = item->next; |
| 2308 | replacement->prev = item->prev; |
| 2309 | |
| 2310 | if (replacement->next != NULL) |
| 2311 | { |
| 2312 | replacement->next->prev = replacement; |
| 2313 | } |
| 2314 | if (parent->child == item) |
| 2315 | { |
| 2316 | if (parent->child->prev == parent->child) |
| 2317 | { |
| 2318 | replacement->prev = replacement; |
| 2319 | } |
| 2320 | parent->child = replacement; |
| 2321 | } |
| 2322 | else |
| 2323 | { /* |
| 2324 | * To find the last item in array quickly, we use prev in array. |
| 2325 | * We can't modify the last item's next pointer where this item was the parent's child |
| 2326 | */ |
| 2327 | if (replacement->prev != NULL) |
| 2328 | { |
| 2329 | replacement->prev->next = replacement; |
| 2330 | } |
| 2331 | if (replacement->next == NULL) |
| 2332 | { |
| 2333 | parent->child->prev = replacement; |
| 2334 | } |
| 2335 | } |
| 2336 | |
| 2337 | item->next = NULL; |
| 2338 | item->prev = NULL; |
| 2339 | cJSON_Delete(item); |
| 2340 | |
| 2341 | return true; |
| 2342 | } |
| 2343 | |
| 2344 | CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem) |
| 2345 | { |
no test coverage detected