MCPcopy Create free account
hub / github.com/TheForceEngine/TheForceEngine / parse_object

Function parse_object

TheForceEngine/TFE_System/cJSON.c:1606–1716  ·  view source on GitHub ↗

Build an object from the text. */

Source from the content-addressed store, hash-verified

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