MCPcopy Create free account
hub / github.com/DaveGamble/cJSON / print_array

Function print_array

cJSON.c:1590–1649  ·  view source on GitHub ↗

Render an array to text */

Source from the content-addressed store, hash-verified

1588
1589/* Render an array to text */
1590static 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

Callers 2

print_valueFunction · 0.85
assert_print_arrayFunction · 0.85

Calls 3

ensureFunction · 0.85
print_valueFunction · 0.85
update_offsetFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…