MCPcopy Create free account
hub / github.com/SVF-tools/SVF / parse_object

Function parse_object

svf/lib/Util/cJSON.cpp:1605–1716  ·  view source on GitHub ↗

Build an object from the text. */

Source from the content-addressed store, hash-verified

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