| 1972 | } |
| 1973 | |
| 1974 | static cJSON_bool add_item_to_array(cJSON *array, cJSON *item) |
| 1975 | { |
| 1976 | cJSON *child = NULL; |
| 1977 | |
| 1978 | if ((item == NULL) || (array == NULL) || (array == item)) |
| 1979 | { |
| 1980 | return false; |
| 1981 | } |
| 1982 | |
| 1983 | child = array->child; |
| 1984 | /* |
| 1985 | * To find the last item in array quickly, we use prev in array |
| 1986 | */ |
| 1987 | if (child == NULL) |
| 1988 | { |
| 1989 | /* list is empty, start new one */ |
| 1990 | array->child = item; |
| 1991 | item->prev = item; |
| 1992 | item->next = NULL; |
| 1993 | } |
| 1994 | else |
| 1995 | { |
| 1996 | /* append to the end */ |
| 1997 | if (child->prev) |
| 1998 | { |
| 1999 | suffix_object(child->prev, item); |
| 2000 | array->child->prev = item; |
| 2001 | } |
| 2002 | } |
| 2003 | |
| 2004 | return true; |
| 2005 | } |
| 2006 | |
| 2007 | /* Add item to array/object. */ |
| 2008 | CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToArray(cJSON *array, cJSON *item) |
no test coverage detected