MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / print_object

Function print_object

lib/cJSON.c:1515–1793  ·  view source on GitHub ↗

Render an object to text. */

Source from the content-addressed store, hash-verified

1513
1514/* Render an object to text. */
1515static unsigned char *print_object(const cJSON *item, size_t depth, cjbool fmt, printbuffer *p)
1516{
1517 unsigned char **entries = NULL;
1518 unsigned char **names = NULL;
1519 unsigned char *out = NULL;
1520 unsigned char *ptr = NULL;
1521 unsigned char *ret = NULL;
1522 unsigned char *str = NULL;
1523 size_t len = 7;
1524 size_t i = 0;
1525 size_t j = 0;
1526 cJSON *child = item->child;
1527 size_t numentries = 0;
1528 cjbool fail = false;
1529 size_t tmplen = 0;
1530
1531 /* Count the number of entries. */
1532 while (child)
1533 {
1534 numentries++;
1535 child = child->next;
1536 }
1537
1538 /* Explicitly handle empty object case */
1539 if (!numentries)
1540 {
1541 if (p)
1542 {
1543 out = ensure(p, fmt ? depth + 4 : 3);
1544 }
1545 else
1546 {
1547 out = (unsigned char*)cJSON_malloc(fmt ? depth + 4 : 3);
1548 }
1549 if (!out)
1550 {
1551 return NULL;
1552 }
1553 ptr = out;
1554 *ptr++ = '{';
1555 if (fmt) {
1556 *ptr++ = '\n';
1557 for (i = 0; i < depth; i++)
1558 {
1559 *ptr++ = '\t';
1560 }
1561 }
1562 *ptr++ = '}';
1563 *ptr++ = '\0';
1564
1565 return out;
1566 }
1567
1568 if (p)
1569 {
1570 /* Compose the output: */
1571 i = p->offset;
1572 len = fmt ? 2 : 1; /* fmt: {\n */

Callers 1

print_valueFunction · 0.70

Calls 4

ensureFunction · 0.85
print_string_ptrFunction · 0.70
updateFunction · 0.70
print_valueFunction · 0.70

Tested by

no test coverage detected