MCPcopy Index your code
hub / github.com/DaveGamble/cJSON / detach_path

Function detach_path

cJSON_Utils.c:430–481  ·  view source on GitHub ↗

detach an item at the given path */

Source from the content-addressed store, hash-verified

428
429/* detach an item at the given path */
430static cJSON *detach_path(cJSON *object, const unsigned char *path, const cJSON_bool case_sensitive)
431{
432 unsigned char *parent_pointer = NULL;
433 unsigned char *child_pointer = NULL;
434 cJSON *parent = NULL;
435 cJSON *detached_item = NULL;
436
437 /* copy path and split it in parent and child */
438 parent_pointer = cJSONUtils_strdup(path);
439 if (parent_pointer == NULL) {
440 goto cleanup;
441 }
442
443 child_pointer = (unsigned char*)strrchr((char*)parent_pointer, '/'); /* last '/' */
444 if (child_pointer == NULL)
445 {
446 goto cleanup;
447 }
448 /* split strings */
449 child_pointer[0] = '\0';
450 child_pointer++;
451
452 parent = get_item_from_pointer(object, (char*)parent_pointer, case_sensitive);
453 decode_pointer_inplace(child_pointer);
454
455 if (cJSON_IsArray(parent))
456 {
457 size_t index = 0;
458 if (!decode_array_index_from_pointer(child_pointer, &index))
459 {
460 goto cleanup;
461 }
462 detached_item = detach_item_from_array(parent, index);
463 }
464 else if (cJSON_IsObject(parent))
465 {
466 detached_item = cJSON_DetachItemFromObject(parent, (char*)child_pointer);
467 }
468 else
469 {
470 /* Couldn't find object to remove child from. */
471 goto cleanup;
472 }
473
474cleanup:
475 if (parent_pointer != NULL)
476 {
477 cJSON_free(parent_pointer);
478 }
479
480 return detached_item;
481}
482
483/* sort lists using mergesort */
484static cJSON *sort_list(cJSON *list, const cJSON_bool case_sensitive)

Callers 1

apply_patchFunction · 0.85

Calls 9

cJSONUtils_strdupFunction · 0.85
get_item_from_pointerFunction · 0.85
decode_pointer_inplaceFunction · 0.85
cJSON_IsArrayFunction · 0.85
detach_item_from_arrayFunction · 0.85
cJSON_IsObjectFunction · 0.85
cJSON_freeFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…