MCPcopy Create free account
hub / github.com/Tencent/Hardcoder / parse_object

Function parse_object

libapp2sys/src/main/cpp/cjson/cJSON.c:1501–1607  ·  view source on GitHub ↗

Build an object from the text. */

Source from the content-addressed store, hash-verified

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