mirror of
https://github.com/DaveGamble/cJSON
synced 2025-01-12 01:39:46 +00:00
reformatting: cJSONUtils_GeneratePatch
This commit is contained in:
parent
e8a67f0e4b
commit
d6a6abeca0
@ -482,20 +482,26 @@ int cJSONUtils_ApplyPatches(cJSON *object, cJSON *patches)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void cJSONUtils_GeneratePatch(cJSON *patches,const char *op,const char *path,const char *suffix,cJSON *val)
|
||||
static void cJSONUtils_GeneratePatch(cJSON *patches, const char *op, const char *path, const char *suffix, cJSON *val)
|
||||
{
|
||||
cJSON *patch=cJSON_CreateObject();
|
||||
cJSON_AddItemToObject(patch,"op",cJSON_CreateString(op));
|
||||
if (suffix)
|
||||
{
|
||||
char *newpath=(char*)malloc(strlen(path)+cJSONUtils_PointerEncodedstrlen(suffix)+2);
|
||||
cJSONUtils_PointerEncodedstrcpy(newpath+sprintf(newpath,"%s/",path),suffix);
|
||||
cJSON_AddItemToObject(patch,"path",cJSON_CreateString(newpath));
|
||||
free(newpath);
|
||||
}
|
||||
else cJSON_AddItemToObject(patch,"path",cJSON_CreateString(path));
|
||||
if (val) cJSON_AddItemToObject(patch,"value",cJSON_Duplicate(val,1));
|
||||
cJSON_AddItemToArray(patches,patch);
|
||||
cJSON *patch = cJSON_CreateObject();
|
||||
cJSON_AddItemToObject(patch, "op", cJSON_CreateString(op));
|
||||
if (suffix)
|
||||
{
|
||||
char *newpath = (char*)malloc(strlen(path) + cJSONUtils_PointerEncodedstrlen(suffix) + 2);
|
||||
cJSONUtils_PointerEncodedstrcpy(newpath + sprintf(newpath, "%s/", path), suffix);
|
||||
cJSON_AddItemToObject(patch, "path", cJSON_CreateString(newpath));
|
||||
free(newpath);
|
||||
}
|
||||
else
|
||||
{
|
||||
cJSON_AddItemToObject(patch, "path", cJSON_CreateString(path));
|
||||
}
|
||||
if (val)
|
||||
{
|
||||
cJSON_AddItemToObject(patch, "value", cJSON_Duplicate(val, 1));
|
||||
}
|
||||
cJSON_AddItemToArray(patches, patch);
|
||||
}
|
||||
|
||||
void cJSONUtils_AddPatchToArray(cJSON *array,const char *op,const char *path,cJSON *val) {cJSONUtils_GeneratePatch(array,op,path,0,val);}
|
||||
|
Loading…
Reference in New Issue
Block a user