MCPcopy Create free account
hub / github.com/alibaba/CicadaPlayer / parse_object

Function parse_object

framework/utils/cJSON.c:1497–1603  ·  view source on GitHub ↗

Build an object from the text. */

Source from the content-addressed store, hash-verified

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