MCPcopy Create free account
hub / github.com/0xShug0/audio.cpp / parse_array

Function parse_array

external/cJSON/cJSON.c:1497–1592  ·  view source on GitHub ↗

Build an array from input text. */

Source from the content-addressed store, hash-verified

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

Callers 1

parse_valueFunction · 0.85

Calls 4

buffer_skip_whitespaceFunction · 0.85
cJSON_New_ItemFunction · 0.85
parse_valueFunction · 0.85
cJSON_DeleteFunction · 0.85

Tested by

no test coverage detected