Build an object from the text. */
| 1511 | |
| 1512 | /* Build an object from the text. */ |
| 1513 | static cJSON_bool parse_object(cJSON * const item, parse_buffer * const input_buffer) |
| 1514 | { |
| 1515 | cJSON *head = NULL; /* linked list head */ |
| 1516 | cJSON *current_item = NULL; |
| 1517 | |
| 1518 | if (input_buffer->depth >= CJSON_NESTING_LIMIT) |
| 1519 | { |
| 1520 | return false; /* to deeply nested */ |
| 1521 | } |
| 1522 | input_buffer->depth++; |
| 1523 | |
| 1524 | if (cannot_access_at_index(input_buffer, 0) || (buffer_at_offset(input_buffer)[0] != '{')) |
| 1525 | { |
| 1526 | goto fail; /* not an object */ |
| 1527 | } |
| 1528 | |
| 1529 | input_buffer->offset++; |
| 1530 | buffer_skip_whitespace(input_buffer); |
| 1531 | if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '}')) |
| 1532 | { |
| 1533 | goto success; /* empty object */ |
| 1534 | } |
| 1535 | |
| 1536 | /* check if we skipped to the end of the buffer */ |
| 1537 | if (cannot_access_at_index(input_buffer, 0)) |
| 1538 | { |
| 1539 | input_buffer->offset--; |
| 1540 | goto fail; |
| 1541 | } |
| 1542 | |
| 1543 | /* step back to character in front of the first element */ |
| 1544 | input_buffer->offset--; |
| 1545 | /* loop through the comma separated array elements */ |
| 1546 | do |
| 1547 | { |
| 1548 | /* allocate next item */ |
| 1549 | cJSON *new_item = cJSON_New_Item(&(input_buffer->hooks)); |
| 1550 | if (new_item == NULL) |
| 1551 | { |
| 1552 | goto fail; /* allocation failure */ |
| 1553 | } |
| 1554 | |
| 1555 | /* attach next item to list */ |
| 1556 | if (head == NULL) |
| 1557 | { |
| 1558 | /* start the linked list */ |
| 1559 | current_item = head = new_item; |
| 1560 | } |
| 1561 | else |
| 1562 | { |
| 1563 | /* add to the end and advance */ |
| 1564 | current_item->next = new_item; |
| 1565 | new_item->prev = current_item; |
| 1566 | current_item = new_item; |
| 1567 | } |
| 1568 | |
| 1569 | /* parse the name of the child */ |
| 1570 | input_buffer->offset++; |
no test coverage detected