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