| 1959 | } |
| 1960 | |
| 1961 | static cJSON_bool add_item_to_array(cJSON *array, cJSON *item) |
| 1962 | { |
| 1963 | cJSON *child = NULL; |
| 1964 | |
| 1965 | if ((item == NULL) || (array == NULL) || (array == item)) |
| 1966 | { |
| 1967 | return false; |
| 1968 | } |
| 1969 | |
| 1970 | child = array->child; |
| 1971 | /* |
| 1972 | * To find the last item in array quickly, we use prev in array |
| 1973 | */ |
| 1974 | if (child == NULL) |
| 1975 | { |
| 1976 | /* list is empty, start new one */ |
| 1977 | array->child = item; |
| 1978 | item->prev = item; |
| 1979 | item->next = NULL; |
| 1980 | } |
| 1981 | else |
| 1982 | { |
| 1983 | /* append to the end */ |
| 1984 | if (child->prev) |
| 1985 | { |
| 1986 | suffix_object(child->prev, item); |
| 1987 | array->child->prev = item; |
| 1988 | } |
| 1989 | } |
| 1990 | |
| 1991 | return true; |
| 1992 | } |
| 1993 | |
| 1994 | /* Add item to array/object. */ |
| 1995 | CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToArray(cJSON *array, cJSON *item) |
no test coverage detected