mirror of
https://github.com/DaveGamble/cJSON.git
synced 2024-12-26 21:04:24 +08:00
reformatting: cJSON_InsertItemInArray
This commit is contained in:
parent
207bb05e8c
commit
69dcfcf238
28
cJSON.c
28
cJSON.c
@ -1769,8 +1769,32 @@ void cJSON_DeleteItemFromObject(cJSON *object, const char *string)
|
||||
}
|
||||
|
||||
/* Replace array/object items with new ones. */
|
||||
void cJSON_InsertItemInArray(cJSON *array,int which,cJSON *newitem) {cJSON *c=array->child;while (c && which>0) c=c->next,which--;if (!c) {cJSON_AddItemToArray(array,newitem);return;}
|
||||
newitem->next=c;newitem->prev=c->prev;c->prev=newitem;if (c==array->child) array->child=newitem; else newitem->prev->next=newitem;}
|
||||
void cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem)
|
||||
{
|
||||
cJSON *c = array->child;
|
||||
while (c && (which > 0))
|
||||
{
|
||||
c = c->next;
|
||||
which--;
|
||||
}
|
||||
if (!c)
|
||||
{
|
||||
cJSON_AddItemToArray(array, newitem);
|
||||
return;
|
||||
}
|
||||
newitem->next = c;
|
||||
newitem->prev = c->prev;
|
||||
c->prev = newitem;
|
||||
if (c == array->child)
|
||||
{
|
||||
array->child = newitem;
|
||||
}
|
||||
else
|
||||
{
|
||||
newitem->prev->next = newitem;
|
||||
}
|
||||
}
|
||||
|
||||
void cJSON_ReplaceItemInArray(cJSON *array,int which,cJSON *newitem) {cJSON *c=array->child;while (c && which>0) c=c->next,which--;if (!c) return;
|
||||
newitem->next=c->next;newitem->prev=c->prev;if (newitem->next) newitem->next->prev=newitem;
|
||||
if (c==array->child) array->child=newitem; else newitem->prev->next=newitem;c->next=c->prev=0;cJSON_Delete(c);}
|
||||
|
Loading…
x
Reference in New Issue
Block a user