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