| 2010 | } |
| 2011 | |
| 2012 | static cJSON_bool add_item_to_array(cJSON *array, cJSON *item) |
| 2013 | { |
| 2014 | cJSON *child = NULL; |
| 2015 | |
| 2016 | if ((item == NULL) || (array == NULL) || (array == item)) |
| 2017 | { |
| 2018 | return false; |
| 2019 | } |
| 2020 | |
| 2021 | child = array->child; |
| 2022 | /* |
| 2023 | * To find the last item in array quickly, we use prev in array |
| 2024 | */ |
| 2025 | if (child == NULL) |
| 2026 | { |
| 2027 | /* list is empty, start new one */ |
| 2028 | array->child = item; |
| 2029 | item->prev = item; |
| 2030 | item->next = NULL; |
| 2031 | } |
| 2032 | else |
| 2033 | { |
| 2034 | /* append to the end */ |
| 2035 | if (child->prev) |
| 2036 | { |
| 2037 | suffix_object(child->prev, item); |
| 2038 | array->child->prev = item; |
| 2039 | } |
| 2040 | } |
| 2041 | |
| 2042 | return true; |
| 2043 | } |
| 2044 | |
| 2045 | /* Add item to array/object. */ |
| 2046 | CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToArray(cJSON *array, cJSON *item) |
searching dependent graphs…