MCPcopy Create free account
hub / github.com/OpenIPC/firmware / parse_object

Function parse_object

general/package/xmdp/src/cjson/cJSON.c:1595–1705  ·  view source on GitHub ↗

Build an object from the text. */

Source from the content-addressed store, hash-verified

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