reformatting: cJSONUtils_PatchDetach

This commit is contained in:
Max Bruckner 2016-10-17 01:17:31 +07:00
parent a21a124d40
commit 1235c62235

View File

@ -207,16 +207,38 @@ static void cJSONUtils_InplaceDecodePointerString(char *string)
static cJSON *cJSONUtils_PatchDetach(cJSON *object, const char *path) static cJSON *cJSONUtils_PatchDetach(cJSON *object, const char *path)
{ {
char *parentptr=0,*childptr=0;cJSON *parent=0,*ret=0; char *parentptr = 0;
char *childptr = 0;
cJSON *parent = 0;
cJSON *ret = 0;
parentptr=strdup(path); childptr=strrchr(parentptr,'/'); if (childptr) *childptr++=0; /* copy path and split it in parent and child */
parentptr = strdup(path);
childptr = strrchr(parentptr, '/'); /* last '/' */
if (childptr)
{
/* split strings */
*childptr++ = '\0';
}
parent = cJSONUtils_GetPointer(object, parentptr); parent = cJSONUtils_GetPointer(object, parentptr);
cJSONUtils_InplaceDecodePointerString(childptr); cJSONUtils_InplaceDecodePointerString(childptr);
if (!parent) ret=0; /* Couldn't find object to remove child from. */ if (!parent)
else if (parent->type==cJSON_Array) ret=cJSON_DetachItemFromArray(parent,atoi(childptr)); {
else if (parent->type==cJSON_Object) ret=cJSON_DetachItemFromObject(parent,childptr); /* Couldn't find object to remove child from. */
ret = 0;
}
else if (parent->type == cJSON_Array)
{
ret = cJSON_DetachItemFromArray(parent, atoi(childptr));
}
else if (parent->type == cJSON_Object)
{
ret = cJSON_DetachItemFromObject(parent, childptr);
}
free(parentptr); free(parentptr);
/* return the detachted item */
return ret; return ret;
} }