mirror of
https://github.com/DaveGamble/cJSON.git
synced 2023-08-10 21:13:26 +03:00
Add cJSONUtils_ApplyPatchesCaseSensitive
This commit is contained in:
@@ -873,6 +873,35 @@ CJSON_PUBLIC(int) cJSONUtils_ApplyPatches(cJSON * const object, const cJSON * co
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CJSON_PUBLIC(int) cJSONUtils_ApplyPatchesCaseSensitive(cJSON * const object, const cJSON * const patches)
|
||||||
|
{
|
||||||
|
const cJSON *current_patch = NULL;
|
||||||
|
int status = 0;
|
||||||
|
|
||||||
|
if (!cJSON_IsArray(patches))
|
||||||
|
{
|
||||||
|
/* malformed patches. */
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (patches != NULL)
|
||||||
|
{
|
||||||
|
current_patch = patches->child;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (current_patch != NULL)
|
||||||
|
{
|
||||||
|
status = apply_patch(object, current_patch, true);
|
||||||
|
if (status != 0)
|
||||||
|
{
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
current_patch = current_patch->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static void compose_patch(cJSON * const patches, const unsigned char * const operation, const unsigned char * const path, const unsigned char *suffix, const cJSON * const value)
|
static void compose_patch(cJSON * const patches, const unsigned char * const operation, const unsigned char * const path, const unsigned char *suffix, const cJSON * const value)
|
||||||
{
|
{
|
||||||
cJSON *patch = cJSON_CreateObject();
|
cJSON *patch = cJSON_CreateObject();
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ CJSON_PUBLIC(cJSON *) cJSONUtils_GeneratePatchesCaseSensitive(cJSON * const from
|
|||||||
CJSON_PUBLIC(void) cJSONUtils_AddPatchToArray(cJSON * const array, const char * const operation, const char * const path, const cJSON * const value);
|
CJSON_PUBLIC(void) cJSONUtils_AddPatchToArray(cJSON * const array, const char * const operation, const char * const path, const cJSON * const value);
|
||||||
/* Returns 0 for success. */
|
/* Returns 0 for success. */
|
||||||
CJSON_PUBLIC(int) cJSONUtils_ApplyPatches(cJSON * const object, const cJSON * const patches);
|
CJSON_PUBLIC(int) cJSONUtils_ApplyPatches(cJSON * const object, const cJSON * const patches);
|
||||||
|
CJSON_PUBLIC(int) cJSONUtils_ApplyPatchesCaseSensitive(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:
|
||||||
|
|||||||
Reference in New Issue
Block a user