Render an array to text */
| 1593 | |
| 1594 | /* Render an array to text */ |
| 1595 | static cJSON_bool print_array(const cJSON * const item, printbuffer * const output_buffer) |
| 1596 | { |
| 1597 | unsigned char *output_pointer = NULL; |
| 1598 | size_t length = 0; |
| 1599 | cJSON *current_element = item->child; |
| 1600 | |
| 1601 | if (output_buffer == NULL) |
| 1602 | { |
| 1603 | return false; |
| 1604 | } |
| 1605 | |
| 1606 | if (output_buffer->depth >= CJSON_NESTING_LIMIT) |
| 1607 | { |
| 1608 | return false; /* nesting is too deep */ |
| 1609 | } |
| 1610 | |
| 1611 | /* Compose the output array. */ |
| 1612 | /* opening square bracket */ |
| 1613 | output_pointer = ensure(output_buffer, 1); |
| 1614 | if (output_pointer == NULL) |
| 1615 | { |
| 1616 | return false; |
| 1617 | } |
| 1618 | |
| 1619 | *output_pointer = '['; |
| 1620 | output_buffer->offset++; |
| 1621 | output_buffer->depth++; |
| 1622 | |
| 1623 | while (current_element != NULL) |
| 1624 | { |
| 1625 | if (!print_value(current_element, output_buffer)) |
| 1626 | { |
| 1627 | return false; |
| 1628 | } |
| 1629 | update_offset(output_buffer); |
| 1630 | if (current_element->next) |
| 1631 | { |
| 1632 | length = (size_t) (output_buffer->format ? 2 : 1); |
| 1633 | output_pointer = ensure(output_buffer, length + 1); |
| 1634 | if (output_pointer == NULL) |
| 1635 | { |
| 1636 | return false; |
| 1637 | } |
| 1638 | *output_pointer++ = ','; |
| 1639 | if(output_buffer->format) |
| 1640 | { |
| 1641 | *output_pointer++ = ' '; |
| 1642 | } |
| 1643 | *output_pointer = '\0'; |
| 1644 | output_buffer->offset += length; |
| 1645 | } |
| 1646 | current_element = current_element->next; |
| 1647 | } |
| 1648 | |
| 1649 | output_pointer = ensure(output_buffer, 2); |
| 1650 | if (output_pointer == NULL) |
| 1651 | { |
| 1652 | return false; |
no test coverage detected