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