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)
|
cJSON* cJSONUtils_MergePatch(cJSON *target, cJSON *patch)
|
||||||
{
|
{
|
||||||
if (!patch || patch->type != cJSON_Object) {cJSON_Delete(target);return cJSON_Duplicate(patch,1);}
|
if (!patch || (patch->type != cJSON_Object))
|
||||||
if (!target || target->type != cJSON_Object) {cJSON_Delete(target);target=cJSON_CreateObject();}
|
{
|
||||||
|
/* scalar value, array or NULL, just duplicate */
|
||||||
|
cJSON_Delete(target);
|
||||||
|
return cJSON_Duplicate(patch, 1);
|
||||||
|
}
|
||||||
|
|
||||||
patch=patch->child;
|
if (!target || (target->type != cJSON_Object))
|
||||||
while (patch)
|
{
|
||||||
{
|
cJSON_Delete(target);
|
||||||
if (patch->type == cJSON_NULL) cJSON_DeleteItemFromObject(target,patch->string);
|
target = cJSON_CreateObject();
|
||||||
else
|
}
|
||||||
{
|
|
||||||
cJSON *replaceme=cJSON_DetachItemFromObject(target,patch->string);
|
patch = patch->child;
|
||||||
cJSON_AddItemToObject(target,patch->string,cJSONUtils_MergePatch(replaceme,patch));
|
while (patch)
|
||||||
}
|
{
|
||||||
patch=patch->next;
|
if (patch->type == cJSON_NULL)
|
||||||
}
|
{
|
||||||
return target;
|
/* 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)
|
cJSON *cJSONUtils_GenerateMergePatch(cJSON *from,cJSON *to)
|
||||||
|
Loading…
Reference in New Issue
Block a user