MCPcopy Create free account
hub / github.com/Tencent/Hardcoder / cJSON_InsertItemInArray

Function cJSON_InsertItemInArray

libapp2sys/src/main/cpp/cjson/cJSON.c:2149–2176  ·  view source on GitHub ↗

Replace array/object items with new ones. */

Source from the content-addressed store, hash-verified

2147
2148/* Replace array/object items with new ones. */
2149CJSON_PUBLIC(void) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem)
2150{
2151 cJSON *after_inserted = NULL;
2152
2153 if (which < 0)
2154 {
2155 return;
2156 }
2157
2158 after_inserted = get_array_item(array, (size_t)which);
2159 if (after_inserted == NULL)
2160 {
2161 add_item_to_array(array, newitem);
2162 return;
2163 }
2164
2165 newitem->next = after_inserted;
2166 newitem->prev = after_inserted->prev;
2167 after_inserted->prev = newitem;
2168 if (after_inserted == array->child)
2169 {
2170 array->child = newitem;
2171 }
2172 else
2173 {
2174 newitem->prev->next = newitem;
2175 }
2176}
2177
2178CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement)
2179{

Callers

nothing calls this directly

Calls 2

get_array_itemFunction · 0.85
add_item_to_arrayFunction · 0.85

Tested by

no test coverage detected