mirror of
https://github.com/DaveGamble/cJSON.git
synced 2023-08-10 21:13:26 +03: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. */
|
/* 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;}
|
void cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem)
|
||||||
newitem->next=c;newitem->prev=c->prev;c->prev=newitem;if (c==array->child) array->child=newitem; else newitem->prev->next=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;
|
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;
|
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);}
|
if (c==array->child) array->child=newitem; else newitem->prev->next=newitem;c->next=c->prev=0;cJSON_Delete(c);}
|
||||||
|
Loading…
Reference in New Issue
Block a user