mirror of
https://github.com/DaveGamble/cJSON.git
synced 2023-08-10 21:13:26 +03:00
reformatting: cJSONUtils_MergePatch
This commit is contained in:
parent
c65514fcb4
commit
01a813f642
@ -725,21 +725,35 @@ void cJSONUtils_SortObject(cJSON *object)
|
||||
|
||||
cJSON* cJSONUtils_MergePatch(cJSON *target, cJSON *patch)
|
||||
{
|
||||
if (!patch || patch->type != cJSON_Object) {cJSON_Delete(target);return cJSON_Duplicate(patch,1);}
|
||||
if (!target || target->type != cJSON_Object) {cJSON_Delete(target);target=cJSON_CreateObject();}
|
||||
if (!patch || (patch->type != cJSON_Object))
|
||||
{
|
||||
/* scalar value, array or NULL, just duplicate */
|
||||
cJSON_Delete(target);
|
||||
return cJSON_Duplicate(patch, 1);
|
||||
}
|
||||
|
||||
patch=patch->child;
|
||||
while (patch)
|
||||
{
|
||||
if (patch->type == cJSON_NULL) cJSON_DeleteItemFromObject(target,patch->string);
|
||||
else
|
||||
{
|
||||
cJSON *replaceme=cJSON_DetachItemFromObject(target,patch->string);
|
||||
cJSON_AddItemToObject(target,patch->string,cJSONUtils_MergePatch(replaceme,patch));
|
||||
}
|
||||
patch=patch->next;
|
||||
}
|
||||
return target;
|
||||
if (!target || (target->type != cJSON_Object))
|
||||
{
|
||||
cJSON_Delete(target);
|
||||
target = cJSON_CreateObject();
|
||||
}
|
||||
|
||||
patch = patch->child;
|
||||
while (patch)
|
||||
{
|
||||
if (patch->type == cJSON_NULL)
|
||||
{
|
||||
/* NULL is the indicator to remove a value, see RFC7396 */
|
||||
cJSON_DeleteItemFromObject(target, patch->string);
|
||||
}
|
||||
else
|
||||
{
|
||||
cJSON *replaceme = cJSON_DetachItemFromObject(target, patch->string);
|
||||
cJSON_AddItemToObject(target, patch->string, cJSONUtils_MergePatch(replaceme, patch));
|
||||
}
|
||||
patch = patch->next;
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
cJSON *cJSONUtils_GenerateMergePatch(cJSON *from,cJSON *to)
|
||||
|
Loading…
Reference in New Issue
Block a user