Build an object from the text. */
| 642 | |
| 643 | /* Build an object from the text. */ |
| 644 | static const char *parse_object(cJSON *item, const char *value, const char **ep) |
| 645 | { |
| 646 | cJSON *child; |
| 647 | if (*value != '{') |
| 648 | { |
| 649 | *ep = value; |
| 650 | return 0; |
| 651 | } /* not an object! */ |
| 652 | |
| 653 | item->type = cJSON_Object; |
| 654 | value = skip(value + 1); |
| 655 | if (*value == '}') |
| 656 | return value + 1; /* empty array. */ |
| 657 | |
| 658 | item->child = child = cJSON_New_Item(); |
| 659 | if (!item->child) |
| 660 | return 0; |
| 661 | value = skip(parse_string(child, skip(value), ep)); |
| 662 | if (!value) |
| 663 | return 0; |
| 664 | child->string = child->valuestring; |
| 665 | child->valuestring = 0; |
| 666 | if (*value != ':') |
| 667 | { |
| 668 | *ep = value; |
| 669 | return 0; |
| 670 | } /* fail! */ |
| 671 | value = skip(parse_value(child, skip(value + 1), ep)); /* skip any spacing, get the value. */ |
| 672 | if (!value) |
| 673 | return 0; |
| 674 | |
| 675 | while (*value == ',') |
| 676 | { |
| 677 | cJSON *new_item; |
| 678 | if (!(new_item = cJSON_New_Item())) |
| 679 | return 0; /* memory fail */ |
| 680 | child->next = new_item; |
| 681 | new_item->prev = child; |
| 682 | child = new_item; |
| 683 | value = skip(parse_string(child, skip(value + 1), ep)); |
| 684 | if (!value) |
| 685 | return 0; |
| 686 | child->string = child->valuestring; |
| 687 | child->valuestring = 0; |
| 688 | if (*value != ':') |
| 689 | { |
| 690 | *ep = value; |
| 691 | return 0; |
| 692 | } /* fail! */ |
| 693 | value = skip(parse_value(child, skip(value + 1), ep)); /* skip any spacing, get the value. */ |
| 694 | if (!value) |
| 695 | return 0; |
| 696 | } |
| 697 | |
| 698 | if (*value == '}') |
| 699 | return value + 1; /* end of array */ |
| 700 | *ep = value; |
| 701 | return 0; /* malformed. */ |
no test coverage detected