mirror of
https://github.com/DaveGamble/cJSON.git
synced 2023-08-10 21:13:26 +03:00
reformatting: cJSON_AddItemToArray
This commit is contained in:
parent
09545c0eb2
commit
c26f9b918d
24
cJSON.c
24
cJSON.c
@ -1643,7 +1643,29 @@ static cJSON *create_reference(cJSON *item)
|
||||
}
|
||||
|
||||
/* Add item to array/object. */
|
||||
void cJSON_AddItemToArray(cJSON *array, cJSON *item) {cJSON *c=array->child;if (!item) return; if (!c) {array->child=item;} else {while (c && c->next) c=c->next; suffix_object(c,item);}}
|
||||
void cJSON_AddItemToArray(cJSON *array, cJSON *item)
|
||||
{
|
||||
cJSON *c = array->child;
|
||||
if (!item)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!c)
|
||||
{
|
||||
/* list is empty, start new one */
|
||||
array->child = item;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* append to the end */
|
||||
while (c && c->next)
|
||||
{
|
||||
c = c->next;
|
||||
}
|
||||
suffix_object(c, item);
|
||||
}
|
||||
}
|
||||
|
||||
void cJSON_AddItemToObject(cJSON *object,const char *string,cJSON *item) {if (!item) return; if (item->string) cJSON_free(item->string);item->string=cJSON_strdup(string);cJSON_AddItemToArray(object,item);}
|
||||
void cJSON_AddItemToObjectCS(cJSON *object,const char *string,cJSON *item) {if (!item) return; if (!(item->type&cJSON_StringIsConst) && item->string) cJSON_free(item->string);item->string=(char*)string;item->type|=cJSON_StringIsConst;cJSON_AddItemToArray(object,item);}
|
||||
void cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item) {cJSON_AddItemToArray(array,create_reference(item));}
|
||||
|
Loading…
Reference in New Issue
Block a user