Parse an object - create a new root, and populate. */
| 884 | |
| 885 | /* Parse an object - create a new root, and populate. */ |
| 886 | cJSON *cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cjbool require_null_terminated) |
| 887 | { |
| 888 | const unsigned char *end = NULL; |
| 889 | /* use global error pointer if no specific one was given */ |
| 890 | const unsigned char **ep = return_parse_end ? (const unsigned char**)return_parse_end : &global_ep; |
| 891 | cJSON *c = cJSON_New_Item(); |
| 892 | *ep = NULL; |
| 893 | if (!c) /* memory fail */ |
| 894 | { |
| 895 | return NULL; |
| 896 | } |
| 897 | |
| 898 | end = parse_value(c, skip((const unsigned char*)value), ep); |
| 899 | if (!end) |
| 900 | { |
| 901 | /* parse failure. ep is set. */ |
| 902 | cJSON_Delete(c); |
| 903 | return NULL; |
| 904 | } |
| 905 | |
| 906 | /* if we require null-terminated JSON without appended garbage, skip and then check for a null terminator */ |
| 907 | if (require_null_terminated) |
| 908 | { |
| 909 | end = skip(end); |
| 910 | if (*end) |
| 911 | { |
| 912 | cJSON_Delete(c); |
| 913 | *ep = end; |
| 914 | return NULL; |
| 915 | } |
| 916 | } |
| 917 | if (return_parse_end) |
| 918 | { |
| 919 | *return_parse_end = (const char*)end; |
| 920 | } |
| 921 | |
| 922 | return c; |
| 923 | } |
| 924 | |
| 925 | /* Default options for cJSON_Parse */ |
| 926 | cJSON *cJSON_Parse(const char *value) |
no test coverage detected