Render an object to text. */
| 548 | |
| 549 | /* Render an object to text. */ |
| 550 | static char *print_object(cJSON *item,int depth,int fmt,printbuffer *p) |
| 551 | { |
| 552 | char **entries=0,**names=0; |
| 553 | char *out=0,*ptr,*ret,*str;int len=7,i=0,j; |
| 554 | cJSON *child=item->child; |
| 555 | int numentries=0,fail=0; |
| 556 | size_t tmplen=0; |
| 557 | /* Count the number of entries. */ |
| 558 | while (child) numentries++,child=child->next; |
| 559 | /* Explicitly handle empty object case */ |
| 560 | if (!numentries) |
| 561 | { |
| 562 | if (p) out=ensure(p,fmt?depth+4:3); |
| 563 | else out=(char*)cJSON_malloc(fmt?depth+4:3); |
| 564 | if (!out) return 0; |
| 565 | ptr=out;*ptr++='{'; |
| 566 | if (fmt) {*ptr++='\n';for (i=0;i<depth-1;i++) *ptr++='\t';} |
| 567 | *ptr++='}';*ptr++=0; |
| 568 | return out; |
| 569 | } |
| 570 | if (p) |
| 571 | { |
| 572 | /* Compose the output: */ |
| 573 | i=p->offset; |
| 574 | len=fmt?2:1; ptr=ensure(p,len+1); if (!ptr) return 0; |
| 575 | *ptr++='{'; if (fmt) *ptr++='\n'; *ptr=0; p->offset+=len; |
| 576 | child=item->child;depth++; |
| 577 | while (child) |
| 578 | { |
| 579 | if (fmt) |
| 580 | { |
| 581 | ptr=ensure(p,depth); if (!ptr) return 0; |
| 582 | for (j=0;j<depth;j++) *ptr++='\t'; |
| 583 | p->offset+=depth; |
| 584 | } |
| 585 | print_string_ptr(child->string,p); |
| 586 | p->offset=update(p); |
| 587 | |
| 588 | len=fmt?2:1; |
| 589 | ptr=ensure(p,len); if (!ptr) return 0; |
| 590 | *ptr++=':';if (fmt) *ptr++='\t'; |
| 591 | p->offset+=len; |
| 592 | |
| 593 | print_value(child,depth,fmt,p); |
| 594 | p->offset=update(p); |
| 595 | |
| 596 | len=(fmt?1:0)+(child->next?1:0); |
| 597 | ptr=ensure(p,len+1); if (!ptr) return 0; |
| 598 | if (child->next) *ptr++=','; |
| 599 | if (fmt) *ptr++='\n';*ptr=0; |
| 600 | p->offset+=len; |
| 601 | child=child->next; |
| 602 | } |
| 603 | ptr=ensure(p,fmt?(depth+1):2); if (!ptr) return 0; |
| 604 | if (fmt) for (i=0;i<depth-1;i++) *ptr++='\t'; |
| 605 | *ptr++='}';*ptr=0; |
| 606 | out=(p->buffer)+i; |
| 607 | } |
no test coverage detected
searching dependent graphs…