MCPcopy Create free account
hub / github.com/antirez/botlib / parse_object

Function parse_object

cJSON.c:1597–1707  ·  view source on GitHub ↗

Build an object from the text. */

Source from the content-addressed store, hash-verified

1595
1596/* Build an object from the text. */
1597static cJSON_bool parse_object(cJSON * const item, parse_buffer * const input_buffer)
1598{
1599 cJSON *head = NULL; /* linked list head */
1600 cJSON *current_item = NULL;
1601
1602 if (input_buffer->depth >= CJSON_NESTING_LIMIT)
1603 {
1604 return false; /* to deeply nested */
1605 }
1606 input_buffer->depth++;
1607
1608 if (cannot_access_at_index(input_buffer, 0) || (buffer_at_offset(input_buffer)[0] != '{'))
1609 {
1610 goto fail; /* not an object */
1611 }
1612
1613 input_buffer->offset++;
1614 buffer_skip_whitespace(input_buffer);
1615 if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '}'))
1616 {
1617 goto success; /* empty object */
1618 }
1619
1620 /* check if we skipped to the end of the buffer */
1621 if (cannot_access_at_index(input_buffer, 0))
1622 {
1623 input_buffer->offset--;
1624 goto fail;
1625 }
1626
1627 /* step back to character in front of the first element */
1628 input_buffer->offset--;
1629 /* loop through the comma separated array elements */
1630 do
1631 {
1632 /* allocate next item */
1633 cJSON *new_item = cJSON_New_Item(&(input_buffer->hooks));
1634 if (new_item == NULL)
1635 {
1636 goto fail; /* allocation failure */
1637 }
1638
1639 /* attach next item to list */
1640 if (head == NULL)
1641 {
1642 /* start the linked list */
1643 current_item = head = new_item;
1644 }
1645 else
1646 {
1647 /* add to the end and advance */
1648 current_item->next = new_item;
1649 new_item->prev = current_item;
1650 current_item = new_item;
1651 }
1652
1653 /* parse the name of the child */
1654 input_buffer->offset++;

Callers 1

parse_valueFunction · 0.85

Calls 5

buffer_skip_whitespaceFunction · 0.85
cJSON_New_ItemFunction · 0.85
parse_stringFunction · 0.85
parse_valueFunction · 0.85
cJSON_DeleteFunction · 0.85

Tested by

no test coverage detected