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,13 +725,27 @@ 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!target || (target->type != cJSON_Object))
|
||||||
|
{
|
||||||
|
cJSON_Delete(target);
|
||||||
|
target = cJSON_CreateObject();
|
||||||
|
}
|
||||||
|
|
||||||
patch = patch->child;
|
patch = patch->child;
|
||||||
while (patch)
|
while (patch)
|
||||||
{
|
{
|
||||||
if (patch->type == cJSON_NULL) cJSON_DeleteItemFromObject(target,patch->string);
|
if (patch->type == cJSON_NULL)
|
||||||
|
{
|
||||||
|
/* NULL is the indicator to remove a value, see RFC7396 */
|
||||||
|
cJSON_DeleteItemFromObject(target, patch->string);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cJSON *replaceme = cJSON_DetachItemFromObject(target, patch->string);
|
cJSON *replaceme = cJSON_DetachItemFromObject(target, patch->string);
|
||||||
|
Loading…
Reference in New Issue
Block a user