MCPcopy Index your code
hub / github.com/antirez/botlib / parse_array

Function parse_array

cJSON.c:1437–1532  ·  view source on GitHub ↗

Build an array from input text. */

Source from the content-addressed store, hash-verified

1435
1436/* Build an array from input text. */
1437static cJSON_bool parse_array(cJSON * const item, parse_buffer * const input_buffer)
1438{
1439 cJSON *head = NULL; /* head of the linked list */
1440 cJSON *current_item = NULL;
1441
1442 if (input_buffer->depth >= CJSON_NESTING_LIMIT)
1443 {
1444 return false; /* to deeply nested */
1445 }
1446 input_buffer->depth++;
1447
1448 if (buffer_at_offset(input_buffer)[0] != '[')
1449 {
1450 /* not an array */
1451 goto fail;
1452 }
1453
1454 input_buffer->offset++;
1455 buffer_skip_whitespace(input_buffer);
1456 if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == ']'))
1457 {
1458 /* empty array */
1459 goto success;
1460 }
1461
1462 /* check if we skipped to the end of the buffer */
1463 if (cannot_access_at_index(input_buffer, 0))
1464 {
1465 input_buffer->offset--;
1466 goto fail;
1467 }
1468
1469 /* step back to character in front of the first element */
1470 input_buffer->offset--;
1471 /* loop through the comma separated array elements */
1472 do
1473 {
1474 /* allocate next item */
1475 cJSON *new_item = cJSON_New_Item(&(input_buffer->hooks));
1476 if (new_item == NULL)
1477 {
1478 goto fail; /* allocation failure */
1479 }
1480
1481 /* attach next item to list */
1482 if (head == NULL)
1483 {
1484 /* start the linked list */
1485 current_item = head = new_item;
1486 }
1487 else
1488 {
1489 /* add to the end and advance */
1490 current_item->next = new_item;
1491 new_item->prev = current_item;
1492 current_item = new_item;
1493 }
1494

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