mirror of
https://github.com/DaveGamble/cJSON.git
synced 2023-08-10 21:13:26 +03:00
Add cJSON_DetachItemViaPointer
This commit is contained in:
30
cJSON.c
30
cJSON.c
@ -1814,6 +1814,36 @@ CJSON_PUBLIC(void) cJSON_AddItemReferenceToObject(cJSON *object, const char *str
|
||||
cJSON_AddItemToObject(object, string, create_reference(item, &global_hooks));
|
||||
}
|
||||
|
||||
CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, cJSON * const item)
|
||||
{
|
||||
if ((parent == NULL) || (item == NULL))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (item->prev != NULL)
|
||||
{
|
||||
/* not the first element */
|
||||
item->prev->next = item->next;
|
||||
}
|
||||
if (item->next != NULL)
|
||||
{
|
||||
/* not the last element */
|
||||
item->next->prev = item->prev;
|
||||
}
|
||||
|
||||
if (item == parent->child)
|
||||
{
|
||||
/* first element */
|
||||
parent->child = item->next;
|
||||
}
|
||||
/* make sure the detached item doesn't point anywhere anymore */
|
||||
item->prev = NULL;
|
||||
item->next = NULL;
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
static cJSON *DetachItemFromArray(cJSON *array, size_t which)
|
||||
{
|
||||
cJSON *c = array->child;
|
||||
|
Reference in New Issue
Block a user