refactor cJSONUtils_ApplyPatches

This commit is contained in:
Max Bruckner
2017-04-30 13:12:32 +02:00
parent 48c97985d6
commit bde341edd8
2 changed files with 13 additions and 9 deletions

View File

@ -814,26 +814,30 @@ cleanup:
return status;
}
CJSON_PUBLIC(int) cJSONUtils_ApplyPatches(cJSON *object, cJSON *patches)
CJSON_PUBLIC(int) cJSONUtils_ApplyPatches(cJSON * const object, const cJSON * const patches)
{
int err = 0;
const cJSON *current_patch = NULL;
int status = 0;
if (!cJSON_IsArray(patches))
{
/* malformed patches. */
return 1;
}
if (patches)
if (patches != NULL)
{
patches = patches->child;
current_patch = patches->child;
}
while (patches)
while (current_patch != NULL)
{
if ((err = cJSONUtils_ApplyPatch(object, patches)))
status = cJSONUtils_ApplyPatch(object, current_patch);
if (status != 0)
{
return err;
return status;
}
patches = patches->next;
current_patch = current_patch->next;
}
return 0;