non broken version of cJSON_InsertItemInArray */
| 701 | |
| 702 | /* non broken version of cJSON_InsertItemInArray */ |
| 703 | static cJSON_bool insert_item_in_array(cJSON *array, size_t which, cJSON *newitem) |
| 704 | { |
| 705 | cJSON *child = array->child; |
| 706 | while (child && (which > 0)) |
| 707 | { |
| 708 | child = child->next; |
| 709 | which--; |
| 710 | } |
| 711 | if (which > 0) |
| 712 | { |
| 713 | /* item is after the end of the array */ |
| 714 | return 0; |
| 715 | } |
| 716 | if (child == NULL) |
| 717 | { |
| 718 | cJSON_AddItemToArray(array, newitem); |
| 719 | return 1; |
| 720 | } |
| 721 | |
| 722 | /* insert into the linked list */ |
| 723 | newitem->next = child; |
| 724 | newitem->prev = child->prev; |
| 725 | child->prev = newitem; |
| 726 | |
| 727 | /* was it at the beginning */ |
| 728 | if (child == array->child) |
| 729 | { |
| 730 | array->child = newitem; |
| 731 | } |
| 732 | else |
| 733 | { |
| 734 | newitem->prev->next = newitem; |
| 735 | } |
| 736 | |
| 737 | return 1; |
| 738 | } |
| 739 | |
| 740 | static cJSON *get_object_item(const cJSON *const object, const char *name, const cJSON_bool case_sensitive) |
| 741 | { |
no test coverage detected