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

Function compose_patch

cJSON_Utils.c:1096–1134  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1094}
1095
1096static void compose_patch(cJSON * const patches, const unsigned char * const operation, const unsigned char * const path, const unsigned char *suffix, const cJSON * const value)
1097{
1098 cJSON *patch = NULL;
1099
1100 if ((patches == NULL) || (operation == NULL) || (path == NULL))
1101 {
1102 return;
1103 }
1104
1105 patch = cJSON_CreateObject();
1106 if (patch == NULL)
1107 {
1108 return;
1109 }
1110 cJSON_AddItemToObject(patch, "op", cJSON_CreateString((const char*)operation));
1111
1112 if (suffix == NULL)
1113 {
1114 cJSON_AddItemToObject(patch, "path", cJSON_CreateString((const char*)path));
1115 }
1116 else
1117 {
1118 size_t suffix_length = pointer_encoded_length(suffix);
1119 size_t path_length = strlen((const char*)path);
1120 unsigned char *full_path = (unsigned char*)cJSON_malloc(path_length + suffix_length + sizeof("/"));
1121
1122 sprintf((char*)full_path, "%s/", (const char*)path);
1123 encode_string_as_pointer(full_path + path_length + 1, suffix);
1124
1125 cJSON_AddItemToObject(patch, "path", cJSON_CreateString((const char*)full_path));
1126 cJSON_free(full_path);
1127 }
1128
1129 if (value != NULL)
1130 {
1131 cJSON_AddItemToObject(patch, "value", cJSON_Duplicate(value, 1));
1132 }
1133 cJSON_AddItemToArray(patches, patch);
1134}
1135
1136CJSON_PUBLIC(void) cJSONUtils_AddPatchToArray(cJSON * const array, const char * const operation, const char * const path, const cJSON * const value)
1137{

Callers 2

create_patchesFunction · 0.85

Calls 9

cJSON_CreateObjectFunction · 0.85
cJSON_AddItemToObjectFunction · 0.85
cJSON_CreateStringFunction · 0.85
pointer_encoded_lengthFunction · 0.85
cJSON_mallocFunction · 0.85
encode_string_as_pointerFunction · 0.85
cJSON_freeFunction · 0.85
cJSON_DuplicateFunction · 0.85
cJSON_AddItemToArrayFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…