non-broken cJSON_DetachItemFromArray */
| 398 | |
| 399 | /* non-broken cJSON_DetachItemFromArray */ |
| 400 | static cJSON *detach_item_from_array(cJSON *array, size_t which) |
| 401 | { |
| 402 | cJSON *c = array->child; |
| 403 | while (c && (which > 0)) |
| 404 | { |
| 405 | c = c->next; |
| 406 | which--; |
| 407 | } |
| 408 | if (!c) |
| 409 | { |
| 410 | /* item doesn't exist */ |
| 411 | return NULL; |
| 412 | } |
| 413 | if (c != array->child) |
| 414 | { |
| 415 | /* not the first element */ |
| 416 | c->prev->next = c->next; |
| 417 | } |
| 418 | if (c->next) |
| 419 | { |
| 420 | c->next->prev = c->prev; |
| 421 | } |
| 422 | if (c == array->child) |
| 423 | { |
| 424 | array->child = c->next; |
| 425 | } |
| 426 | else if (c->next == NULL) |
| 427 | { |
| 428 | array->child->prev = c->prev; |
| 429 | } |
| 430 | /* make sure the detached item doesn't point anywhere anymore */ |
| 431 | c->prev = c->next = NULL; |
| 432 | |
| 433 | return c; |
| 434 | } |
| 435 | |
| 436 | /* detach an item at the given path */ |
| 437 | static cJSON *detach_path(cJSON *object, const unsigned char *path, const cJSON_bool case_sensitive) |