Render an object to text. */
| 1768 | |
| 1769 | /* Render an object to text. */ |
| 1770 | static cJSON_bool print_object(const cJSON * const item, printbuffer * const output_buffer) |
| 1771 | { |
| 1772 | unsigned char *output_pointer = NULL; |
| 1773 | size_t length = 0; |
| 1774 | cJSON *current_item = item->child; |
| 1775 | |
| 1776 | if (output_buffer == NULL) |
| 1777 | { |
| 1778 | return false; |
| 1779 | } |
| 1780 | |
| 1781 | /* Compose the output: */ |
| 1782 | length = (size_t) (output_buffer->format ? 2 : 1); /* fmt: {\n */ |
| 1783 | output_pointer = ensure(output_buffer, length + 1); |
| 1784 | if (output_pointer == NULL) |
| 1785 | { |
| 1786 | return false; |
| 1787 | } |
| 1788 | |
| 1789 | *output_pointer++ = '{'; |
| 1790 | output_buffer->depth++; |
| 1791 | if (output_buffer->format) |
| 1792 | { |
| 1793 | *output_pointer++ = '\n'; |
| 1794 | } |
| 1795 | output_buffer->offset += length; |
| 1796 | |
| 1797 | while (current_item) |
| 1798 | { |
| 1799 | if (output_buffer->format) |
| 1800 | { |
| 1801 | size_t i; |
| 1802 | output_pointer = ensure(output_buffer, output_buffer->depth); |
| 1803 | if (output_pointer == NULL) |
| 1804 | { |
| 1805 | return false; |
| 1806 | } |
| 1807 | for (i = 0; i < output_buffer->depth; i++) |
| 1808 | { |
| 1809 | *output_pointer++ = '\t'; |
| 1810 | } |
| 1811 | output_buffer->offset += output_buffer->depth; |
| 1812 | } |
| 1813 | |
| 1814 | /* print key */ |
| 1815 | if (!print_string_ptr((unsigned char*)current_item->string, output_buffer)) |
| 1816 | { |
| 1817 | return false; |
| 1818 | } |
| 1819 | update_offset(output_buffer); |
| 1820 | |
| 1821 | length = (size_t) (output_buffer->format ? 2 : 1); |
| 1822 | output_pointer = ensure(output_buffer, length); |
| 1823 | if (output_pointer == NULL) |
| 1824 | { |
| 1825 | return false; |
| 1826 | } |
| 1827 | *output_pointer++ = ':'; |
no test coverage detected
searching dependent graphs…