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

Function get_item_from_pointer

cJSON_Utils.c:301–346  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

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

Used in the wild real call sites across dependent graphs

searching dependent graphs…