Browse Source

refactor cJSONUtils_ApplyPatches

pull/159/head
Max Bruckner 8 years ago
parent
commit
bde341edd8
  1. 20
      cJSON_Utils.c
  2. 2
      cJSON_Utils.h

20
cJSON_Utils.c

@ -814,26 +814,30 @@ cleanup:
return status; 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)) if (!cJSON_IsArray(patches))
{ {
/* malformed patches. */ /* malformed patches. */
return 1; 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; return 0;

2
cJSON_Utils.h

@ -30,7 +30,7 @@ CJSON_PUBLIC(cJSON *) cJSONUtils_GeneratePatches(cJSON *from, cJSON *to);
/* Utility for generating patch array entries. */ /* Utility for generating patch array entries. */
CJSON_PUBLIC(void) cJSONUtils_AddPatchToArray(cJSON *array, const char *op, const char *path, cJSON *val); CJSON_PUBLIC(void) cJSONUtils_AddPatchToArray(cJSON *array, const char *op, const char *path, cJSON *val);
/* Returns 0 for success. */ /* Returns 0 for success. */
CJSON_PUBLIC(int) cJSONUtils_ApplyPatches(cJSON *object, cJSON *patches); CJSON_PUBLIC(int) cJSONUtils_ApplyPatches(cJSON * const object, const cJSON * const patches);
/* /*
// Note that ApplyPatches is NOT atomic on failure. To implement an atomic ApplyPatches, use: // Note that ApplyPatches is NOT atomic on failure. To implement an atomic ApplyPatches, use:

Loading…
Cancel
Save