MCPcopy Index your code
hub / github.com/antirez/botlib / print_object

Function print_object

cJSON.c:1710–1821  ·  view source on GitHub ↗

Render an object to text. */

Source from the content-addressed store, hash-verified

1708
1709/* Render an object to text. */
1710static cJSON_bool print_object(const cJSON * const item, printbuffer * const output_buffer)
1711{
1712 unsigned char *output_pointer = NULL;
1713 size_t length = 0;
1714 cJSON *current_item = item->child;
1715
1716 if (output_buffer == NULL)
1717 {
1718 return false;
1719 }
1720
1721 /* Compose the output: */
1722 length = (size_t) (output_buffer->format ? 2 : 1); /* fmt: {\n */
1723 output_pointer = ensure(output_buffer, length + 1);
1724 if (output_pointer == NULL)
1725 {
1726 return false;
1727 }
1728
1729 *output_pointer++ = '{';
1730 output_buffer->depth++;
1731 if (output_buffer->format)
1732 {
1733 *output_pointer++ = '\n';
1734 }
1735 output_buffer->offset += length;
1736
1737 while (current_item)
1738 {
1739 if (output_buffer->format)
1740 {
1741 size_t i;
1742 output_pointer = ensure(output_buffer, output_buffer->depth);
1743 if (output_pointer == NULL)
1744 {
1745 return false;
1746 }
1747 for (i = 0; i < output_buffer->depth; i++)
1748 {
1749 *output_pointer++ = '\t';
1750 }
1751 output_buffer->offset += output_buffer->depth;
1752 }
1753
1754 /* print key */
1755 if (!print_string_ptr((unsigned char*)current_item->string, output_buffer))
1756 {
1757 return false;
1758 }
1759 update_offset(output_buffer);
1760
1761 length = (size_t) (output_buffer->format ? 2 : 1);
1762 output_pointer = ensure(output_buffer, length);
1763 if (output_pointer == NULL)
1764 {
1765 return false;
1766 }
1767 *output_pointer++ = ':';

Callers 1

print_valueFunction · 0.85

Calls 4

ensureFunction · 0.85
print_string_ptrFunction · 0.85
update_offsetFunction · 0.85
print_valueFunction · 0.85

Tested by

no test coverage detected