Build an object from the text. */
| 513 | |
| 514 | /* Build an object from the text. */ |
| 515 | static const char *parse_object(cJSON *item,const char *value) |
| 516 | { |
| 517 | cJSON *child; |
| 518 | if (*value!='{') {ep=value;return 0;} /* not an object! */ |
| 519 | |
| 520 | item->type=cJSON_Object; |
| 521 | value=skip(value+1); |
| 522 | if (*value=='}') return value+1; /* empty array. */ |
| 523 | |
| 524 | item->child=child=cJSON_New_Item(); |
| 525 | if (!item->child) return 0; |
| 526 | value=skip(parse_string(child,skip(value))); |
| 527 | if (!value) return 0; |
| 528 | child->string=child->valuestring;child->valuestring=0; |
| 529 | if (*value!=':') {ep=value;return 0;} /* fail! */ |
| 530 | value=skip(parse_value(child,skip(value+1))); /* skip any spacing, get the value. */ |
| 531 | if (!value) return 0; |
| 532 | |
| 533 | while (*value==',') |
| 534 | { |
| 535 | cJSON *new_item; |
| 536 | if (!(new_item=cJSON_New_Item())) return 0; /* memory fail */ |
| 537 | child->next=new_item;new_item->prev=child;child=new_item; |
| 538 | value=skip(parse_string(child,skip(value+1))); |
| 539 | if (!value) return 0; |
| 540 | child->string=child->valuestring;child->valuestring=0; |
| 541 | if (*value!=':') {ep=value;return 0;} /* fail! */ |
| 542 | value=skip(parse_value(child,skip(value+1))); /* skip any spacing, get the value. */ |
| 543 | if (!value) return 0; |
| 544 | } |
| 545 | |
| 546 | if (*value=='}') return value+1; /* end of array */ |
| 547 | ep=value;return 0; /* malformed. */ |
| 548 | } |
| 549 | |
| 550 | /* Render an object to text. */ |
| 551 | static char *print_object(cJSON *item,int depth,int fmt,printbuffer *p) |
no test coverage detected