MCPcopy Create free account
hub / github.com/antirez/botlib / add_item_to_array

Function add_item_to_array

cJSON.c:1952–1983  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1950}
1951
1952static cJSON_bool add_item_to_array(cJSON *array, cJSON *item)
1953{
1954 cJSON *child = NULL;
1955
1956 if ((item == NULL) || (array == NULL) || (array == item))
1957 {
1958 return false;
1959 }
1960
1961 child = array->child;
1962 /*
1963 * To find the last item in array quickly, we use prev in array
1964 */
1965 if (child == NULL)
1966 {
1967 /* list is empty, start new one */
1968 array->child = item;
1969 item->prev = item;
1970 item->next = NULL;
1971 }
1972 else
1973 {
1974 /* append to the end */
1975 if (child->prev)
1976 {
1977 suffix_object(child->prev, item);
1978 array->child->prev = item;
1979 }
1980 }
1981
1982 return true;
1983}
1984
1985/* Add item to array/object. */
1986CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToArray(cJSON *array, cJSON *item)

Callers 4

cJSON_AddItemToArrayFunction · 0.85
add_item_to_objectFunction · 0.85
cJSON_InsertItemInArrayFunction · 0.85

Calls 1

suffix_objectFunction · 0.85

Tested by

no test coverage detected