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

Function cJSON_ReplaceItemViaPointer

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

Source from the content-addressed store, hash-verified

2176}
2177
2178CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement)
2179{
2180 if ((parent == NULL) || (replacement == NULL) || (item == NULL))
2181 {
2182 return false;
2183 }
2184
2185 if (replacement == item)
2186 {
2187 return true;
2188 }
2189
2190 replacement->next = item->next;
2191 replacement->prev = item->prev;
2192
2193 if (replacement->next != NULL)
2194 {
2195 replacement->next->prev = replacement;
2196 }
2197 if (replacement->prev != NULL)
2198 {
2199 replacement->prev->next = replacement;
2200 }
2201 if (parent->child == item)
2202 {
2203 parent->child = replacement;
2204 }
2205
2206 item->next = NULL;
2207 item->prev = NULL;
2208 cJSON_Delete(item);
2209
2210 return true;
2211}
2212
2213CJSON_PUBLIC(void) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem)
2214{

Callers 2

cJSON_ReplaceItemInArrayFunction · 0.85
replace_item_in_objectFunction · 0.85

Calls 1

cJSON_DeleteFunction · 0.85

Tested by

no test coverage detected