Build an array from input text. */
| 1452 | |
| 1453 | /* Build an array from input text. */ |
| 1454 | static cJSON_bool parse_array(cJSON * const item, parse_buffer * const input_buffer) |
| 1455 | { |
| 1456 | cJSON *head = NULL; /* head of the linked list */ |
| 1457 | cJSON *current_item = NULL; |
| 1458 | |
| 1459 | if (input_buffer->depth >= CJSON_NESTING_LIMIT) |
| 1460 | { |
| 1461 | return false; /* to deeply nested */ |
| 1462 | } |
| 1463 | input_buffer->depth++; |
| 1464 | |
| 1465 | if (buffer_at_offset(input_buffer)[0] != '[') |
| 1466 | { |
| 1467 | /* not an array */ |
| 1468 | goto fail; |
| 1469 | } |
| 1470 | |
| 1471 | input_buffer->offset++; |
| 1472 | buffer_skip_whitespace(input_buffer); |
| 1473 | if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == ']')) |
| 1474 | { |
| 1475 | /* empty array */ |
| 1476 | goto success; |
| 1477 | } |
| 1478 | |
| 1479 | /* check if we skipped to the end of the buffer */ |
| 1480 | if (cannot_access_at_index(input_buffer, 0)) |
| 1481 | { |
| 1482 | input_buffer->offset--; |
| 1483 | goto fail; |
| 1484 | } |
| 1485 | |
| 1486 | /* step back to character in front of the first element */ |
| 1487 | input_buffer->offset--; |
| 1488 | /* loop through the comma separated array elements */ |
| 1489 | do |
| 1490 | { |
| 1491 | /* allocate next item */ |
| 1492 | cJSON *new_item = cJSON_New_Item(&(input_buffer->hooks)); |
| 1493 | if (new_item == NULL) |
| 1494 | { |
| 1495 | goto fail; /* allocation failure */ |
| 1496 | } |
| 1497 | |
| 1498 | /* attach next item to list */ |
| 1499 | if (head == NULL) |
| 1500 | { |
| 1501 | /* start the linked list */ |
| 1502 | current_item = head = new_item; |
| 1503 | } |
| 1504 | else |
| 1505 | { |
| 1506 | /* add to the end and advance */ |
| 1507 | current_item->next = new_item; |
| 1508 | new_item->prev = current_item; |
| 1509 | current_item = new_item; |
| 1510 | } |
| 1511 |
no test coverage detected