MCPcopy Create free account
hub / github.com/alibaba/CicadaPlayer / cJSON_ParseWithOpts

Function cJSON_ParseWithOpts

framework/utils/cJSON.c:1000–1077  ·  view source on GitHub ↗

Parse an object - create a new root, and populate. */

Source from the content-addressed store, hash-verified

998
999/* Parse an object - create a new root, and populate. */
1000CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated)
1001{
1002 parse_buffer buffer = { 0, 0, 0, 0, { 0, 0, 0 } };
1003 cJSON *item = NULL;
1004
1005 /* reset error position */
1006 global_error.json = NULL;
1007 global_error.position = 0;
1008
1009 if (value == NULL)
1010 {
1011 goto fail;
1012 }
1013
1014 buffer.content = (const unsigned char*)value;
1015 buffer.length = strlen((const char*)value) + sizeof("");
1016 buffer.offset = 0;
1017 buffer.hooks = global_hooks;
1018
1019 item = cJSON_New_Item(&global_hooks);
1020 if (item == NULL) /* memory fail */
1021 {
1022 goto fail;
1023 }
1024
1025 if (!parse_value(item, buffer_skip_whitespace(skip_utf8_bom(&buffer))))
1026 {
1027 /* parse failure. ep is set. */
1028 goto fail;
1029 }
1030
1031 /* if we require null-terminated JSON without appended garbage, skip and then check for a null terminator */
1032 if (require_null_terminated)
1033 {
1034 buffer_skip_whitespace(&buffer);
1035 if ((buffer.offset >= buffer.length) || buffer_at_offset(&buffer)[0] != '\0')
1036 {
1037 goto fail;
1038 }
1039 }
1040 if (return_parse_end)
1041 {
1042 *return_parse_end = (const char*)buffer_at_offset(&buffer);
1043 }
1044
1045 return item;
1046
1047 fail:
1048 if (item != NULL)
1049 {
1050 cJSON_Delete(item);
1051 }
1052
1053 if (value != NULL)
1054 {
1055 error local_error;
1056 local_error.json = (const unsigned char*)value;
1057 local_error.position = 0;

Callers 1

cJSON_ParseFunction · 0.85

Calls 5

cJSON_New_ItemFunction · 0.85
parse_valueFunction · 0.85
buffer_skip_whitespaceFunction · 0.85
skip_utf8_bomFunction · 0.85
cJSON_DeleteFunction · 0.85

Tested by

no test coverage detected