| 299 | } |
| 300 | |
| 301 | static 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 | |
| 348 | CJSON_PUBLIC(cJSON *) cJSONUtils_GetPointer(cJSON * const object, const char *pointer) |
| 349 | { |
no test coverage detected
searching dependent graphs…