Render an object to text. */
| 1620 | |
| 1621 | /* Render an object to text. */ |
| 1622 | static cJSON_bool print_object(const cJSON * const item, printbuffer * const output_buffer) |
| 1623 | { |
| 1624 | unsigned char *output_pointer = NULL; |
| 1625 | size_t length = 0; |
| 1626 | cJSON *current_item = item->child; |
| 1627 | |
| 1628 | if (output_buffer == NULL) |
| 1629 | { |
| 1630 | return false; |
| 1631 | } |
| 1632 | |
| 1633 | /* Compose the output: */ |
| 1634 | length = (size_t) (output_buffer->format ? 2 : 1); /* fmt: {\n */ |
| 1635 | output_pointer = ensure(output_buffer, length + 1); |
| 1636 | if (output_pointer == NULL) |
| 1637 | { |
| 1638 | return false; |
| 1639 | } |
| 1640 | |
| 1641 | *output_pointer++ = '{'; |
| 1642 | output_buffer->depth++; |
| 1643 | if (output_buffer->format) |
| 1644 | { |
| 1645 | *output_pointer++ = '\n'; |
| 1646 | } |
| 1647 | output_buffer->offset += length; |
| 1648 | |
| 1649 | while (current_item) |
| 1650 | { |
| 1651 | if (output_buffer->format) |
| 1652 | { |
| 1653 | size_t i; |
| 1654 | output_pointer = ensure(output_buffer, output_buffer->depth); |
| 1655 | if (output_pointer == NULL) |
| 1656 | { |
| 1657 | return false; |
| 1658 | } |
| 1659 | for (i = 0; i < output_buffer->depth; i++) |
| 1660 | { |
| 1661 | *output_pointer++ = '\t'; |
| 1662 | } |
| 1663 | output_buffer->offset += output_buffer->depth; |
| 1664 | } |
| 1665 | |
| 1666 | /* print key */ |
| 1667 | if (!print_string_ptr((unsigned char*)current_item->string, output_buffer)) |
| 1668 | { |
| 1669 | return false; |
| 1670 | } |
| 1671 | update_offset(output_buffer); |
| 1672 | |
| 1673 | length = (size_t) (output_buffer->format ? 2 : 1); |
| 1674 | output_pointer = ensure(output_buffer, length); |
| 1675 | if (output_pointer == NULL) |
| 1676 | { |
| 1677 | return false; |
| 1678 | } |
| 1679 | *output_pointer++ = ':'; |
no test coverage detected