MCPcopy Create free account
hub / github.com/Netis/cloud-probe / get_item_from_pointer

Function get_item_from_pointer

cpworker/src/cJSON/cJSON_Utils.c:306–352  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

304}
305
306static cJSON *get_item_from_pointer(cJSON *const object, const char *pointer, const cJSON_bool case_sensitive)
307{
308 cJSON *current_element = object;
309
310 if (pointer == NULL)
311 {
312 return NULL;
313 }
314
315 /* follow path of the pointer */
316 while ((pointer[0] == '/') && (current_element != NULL))
317 {
318 pointer++;
319 if (cJSON_IsArray(current_element))
320 {
321 size_t index = 0;
322 if (!decode_array_index_from_pointer((const unsigned char *)pointer, &index))
323 {
324 return NULL;
325 }
326
327 current_element = get_array_item(current_element, index);
328 }
329 else if (cJSON_IsObject(current_element))
330 {
331 current_element = current_element->child;
332 /* GetObjectItem. */
333 while ((current_element != NULL) && !compare_pointers((unsigned char *)current_element->string,
334 (const unsigned char *)pointer, case_sensitive))
335 {
336 current_element = current_element->next;
337 }
338 }
339 else
340 {
341 return NULL;
342 }
343
344 /* skip to the next path token or end of string */
345 while ((pointer[0] != '\0') && (pointer[0] != '/'))
346 {
347 pointer++;
348 }
349 }
350
351 return current_element;
352}
353
354CJSON_PUBLIC(cJSON *) cJSONUtils_GetPointer(cJSON *const object, const char *pointer)
355{

Callers 4

cJSONUtils_GetPointerFunction · 0.85
detach_pathFunction · 0.85
apply_patchFunction · 0.85

Calls 5

cJSON_IsArrayFunction · 0.85
cJSON_IsObjectFunction · 0.85
compare_pointersFunction · 0.85
get_array_itemFunction · 0.70

Tested by

no test coverage detected