Skip to content

Commit

Permalink
implement AddItemToObject using AddItemToObjectCS
Browse files Browse the repository at this point in the history
  • Loading branch information
FSMaxB committed Feb 15, 2017
1 parent 57d105d commit cf862d0
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions cJSON.c
Original file line number Diff line number Diff line change
Expand Up @@ -1775,19 +1775,10 @@ void cJSON_AddItemToArray(cJSON *array, cJSON *item)

void cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item)
{
if (!item)
{
return;
}

/* free old key and set new one */
if (!(item->type & cJSON_StringIsConst) && item->string)
{
cJSON_free(item->string);
}
item->string = (char*)cJSON_strdup((const unsigned char*)string);

cJSON_AddItemToArray(object,item);
/* call cJSON_AddItemToObjectCS for code reuse */
cJSON_AddItemToObjectCS(object, (char*)cJSON_strdup((const unsigned char*)string), item);
/* remove cJSON_StringIsConst flag */
item->type &= ~cJSON_StringIsConst;
}

/* Add an item to an object with constant string as key */
Expand Down

0 comments on commit cf862d0

Please sign in to comment.