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

Function parse_array

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

Build an array from input text. */

Source from the content-addressed store, hash-verified

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

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