MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / merge_patch

Function merge_patch

lib/cJSON.c:2564–2606  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2562
2563
2564static cJSON *merge_patch(cJSON *target, const cJSON * const patch)
2565{
2566 cJSON *patch_child = NULL;
2567
2568 if (!cJSON_IsObject(patch))
2569 {
2570 /* scalar value, array or NULL, just duplicate */
2571 cJSON_Delete(target);
2572 return cJSON_Duplicate(patch, 1);
2573 }
2574
2575 if (!cJSON_IsObject(target))
2576 {
2577 cJSON_Delete(target);
2578 target = cJSON_CreateObject();
2579 }
2580
2581 patch_child = patch->child;
2582 while (patch_child != NULL)
2583 {
2584 if (cJSON_IsNull(patch_child))
2585 {
2586 cJSON_DeleteItemFromObject(target, patch_child->string);
2587 }
2588 else
2589 {
2590 cJSON *replace_me = NULL;
2591 cJSON *replacement = NULL;
2592
2593 replace_me = cJSON_DetachItemFromObject(target, patch_child->string);
2594
2595 replacement = merge_patch(replace_me, patch_child);
2596 if (replacement == NULL)
2597 {
2598 return NULL;
2599 }
2600
2601 cJSON_AddItemToObject(target, patch_child->string, replacement);
2602 }
2603 patch_child = patch_child->next;
2604 }
2605 return target;
2606}
2607
2608cJSON * cJSONUtils_MergePatch(cJSON *target, const cJSON * const patch)
2609{

Callers 1

cJSONUtils_MergePatchFunction · 0.85

Calls 8

cJSON_IsObjectFunction · 0.85
cJSON_DuplicateFunction · 0.85
cJSON_IsNullFunction · 0.85
cJSON_DeleteFunction · 0.70
cJSON_CreateObjectFunction · 0.70
cJSON_AddItemToObjectFunction · 0.70

Tested by

no test coverage detected