mirror of
https://github.com/DaveGamble/cJSON.git
synced 2023-08-10 21:13:26 +03: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;
|
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 *patch = cJSON_CreateObject();
|
||||||
cJSON_AddItemToObject(patch,"op",cJSON_CreateString(op));
|
cJSON_AddItemToObject(patch, "op", cJSON_CreateString(op));
|
||||||
if (suffix)
|
if (suffix)
|
||||||
{
|
{
|
||||||
char *newpath=(char*)malloc(strlen(path)+cJSONUtils_PointerEncodedstrlen(suffix)+2);
|
char *newpath = (char*)malloc(strlen(path) + cJSONUtils_PointerEncodedstrlen(suffix) + 2);
|
||||||
cJSONUtils_PointerEncodedstrcpy(newpath+sprintf(newpath,"%s/",path),suffix);
|
cJSONUtils_PointerEncodedstrcpy(newpath + sprintf(newpath, "%s/", path), suffix);
|
||||||
cJSON_AddItemToObject(patch,"path",cJSON_CreateString(newpath));
|
cJSON_AddItemToObject(patch, "path", cJSON_CreateString(newpath));
|
||||||
free(newpath);
|
free(newpath);
|
||||||
}
|
}
|
||||||
else cJSON_AddItemToObject(patch,"path",cJSON_CreateString(path));
|
else
|
||||||
if (val) cJSON_AddItemToObject(patch,"value",cJSON_Duplicate(val,1));
|
{
|
||||||
cJSON_AddItemToArray(patches,patch);
|
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);}
|
void cJSONUtils_AddPatchToArray(cJSON *array,const char *op,const char *path,cJSON *val) {cJSONUtils_GeneratePatch(array,op,path,0,val);}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user