mirror of
https://github.com/DaveGamble/cJSON.git
synced 2023-08-10 21:13:26 +03:00
reformatting: cJSONUtils_PatchDetach
This commit is contained in:
parent
a21a124d40
commit
1235c62235
@ -205,19 +205,41 @@ static void cJSONUtils_InplaceDecodePointerString(char *string)
|
|||||||
*s2 = '\0';
|
*s2 = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
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 */
|
||||||
parent=cJSONUtils_GetPointer(object,parentptr);
|
parentptr = strdup(path);
|
||||||
cJSONUtils_InplaceDecodePointerString(childptr);
|
childptr = strrchr(parentptr, '/'); /* last '/' */
|
||||||
|
if (childptr)
|
||||||
|
{
|
||||||
|
/* split strings */
|
||||||
|
*childptr++ = '\0';
|
||||||
|
}
|
||||||
|
parent = cJSONUtils_GetPointer(object, parentptr);
|
||||||
|
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. */
|
||||||
free(parentptr);
|
ret = 0;
|
||||||
return ret;
|
}
|
||||||
|
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);
|
||||||
|
|
||||||
|
/* return the detachted item */
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int cJSONUtils_Compare(cJSON *a,cJSON *b)
|
static int cJSONUtils_Compare(cJSON *a,cJSON *b)
|
||||||
|
Loading…
Reference in New Issue
Block a user