| 2025 | } |
| 2026 | |
| 2027 | static cJSON_bool add_item_to_array(cJSON *array, cJSON *item) |
| 2028 | { |
| 2029 | cJSON *child = NULL; |
| 2030 | |
| 2031 | if ((item == NULL) || (array == NULL) || (array == item)) |
| 2032 | { |
| 2033 | return false; |
| 2034 | } |
| 2035 | |
| 2036 | child = array->child; |
| 2037 | /* |
| 2038 | * To find the last item in array quickly, we use prev in array |
| 2039 | */ |
| 2040 | if (child == NULL) |
| 2041 | { |
| 2042 | /* list is empty, start new one */ |
| 2043 | array->child = item; |
| 2044 | item->prev = item; |
| 2045 | item->next = NULL; |
| 2046 | } |
| 2047 | else |
| 2048 | { |
| 2049 | /* append to the end */ |
| 2050 | if (child->prev) |
| 2051 | { |
| 2052 | suffix_object(child->prev, item); |
| 2053 | array->child->prev = item; |
| 2054 | } |
| 2055 | } |
| 2056 | |
| 2057 | return true; |
| 2058 | } |
| 2059 | |
| 2060 | /* Add item to array/object. */ |
| 2061 | CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToArray(cJSON *array, cJSON *item) |
no test coverage detected