MCPcopy Create free account
hub / github.com/0xShug0/audio.cpp / cJSON_ParseWithLengthOpts

Function cJSON_ParseWithLengthOpts

external/cJSON/cJSON.c:1147–1224  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

1145
1146/* Parse an object - create a new root, and populate. */
1147CJSON_PUBLIC(cJSON *) cJSON_ParseWithLengthOpts(const char *value, size_t buffer_length, const char **return_parse_end, cJSON_bool require_null_terminated)
1148{
1149 parse_buffer buffer = { 0, 0, 0, 0, { 0, 0, 0 } };
1150 cJSON *item = NULL;
1151
1152 /* reset error position */
1153 global_error.json = NULL;
1154 global_error.position = 0;
1155
1156 if (value == NULL || 0 == buffer_length)
1157 {
1158 goto fail;
1159 }
1160
1161 buffer.content = (const unsigned char*)value;
1162 buffer.length = buffer_length;
1163 buffer.offset = 0;
1164 buffer.hooks = global_hooks;
1165
1166 item = cJSON_New_Item(&global_hooks);
1167 if (item == NULL) /* memory fail */
1168 {
1169 goto fail;
1170 }
1171
1172 if (!parse_value(item, buffer_skip_whitespace(skip_utf8_bom(&buffer))))
1173 {
1174 /* parse failure. ep is set. */
1175 goto fail;
1176 }
1177
1178 /* if we require null-terminated JSON without appended garbage, skip and then check for a null terminator */
1179 if (require_null_terminated)
1180 {
1181 buffer_skip_whitespace(&buffer);
1182 if ((buffer.offset >= buffer.length) || buffer_at_offset(&buffer)[0] != '\0')
1183 {
1184 goto fail;
1185 }
1186 }
1187 if (return_parse_end)
1188 {
1189 *return_parse_end = (const char*)buffer_at_offset(&buffer);
1190 }
1191
1192 return item;
1193
1194fail:
1195 if (item != NULL)
1196 {
1197 cJSON_Delete(item);
1198 }
1199
1200 if (value != NULL)
1201 {
1202 error local_error;
1203 local_error.json = (const unsigned char*)value;
1204 local_error.position = 0;

Callers 3

parseFunction · 0.85
cJSON_ParseWithOptsFunction · 0.85
cJSON_ParseWithLengthFunction · 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