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

Function parse_array

framework/utils/cJSON.c:1341–1432  ·  view source on GitHub ↗

Build an array from input text. */

Source from the content-addressed store, hash-verified

1339
1340/* Build an array from input text. */
1341static cJSON_bool parse_array(cJSON * const item, parse_buffer * const input_buffer)
1342{
1343 cJSON *head = NULL; /* head of the linked list */
1344 cJSON *current_item = NULL;
1345
1346 if (input_buffer->depth >= CJSON_NESTING_LIMIT)
1347 {
1348 return false; /* to deeply nested */
1349 }
1350 input_buffer->depth++;
1351
1352 if (buffer_at_offset(input_buffer)[0] != '[')
1353 {
1354 /* not an array */
1355 goto fail;
1356 }
1357
1358 input_buffer->offset++;
1359 buffer_skip_whitespace(input_buffer);
1360 if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == ']'))
1361 {
1362 /* empty array */
1363 goto success;
1364 }
1365
1366 /* check if we skipped to the end of the buffer */
1367 if (cannot_access_at_index(input_buffer, 0))
1368 {
1369 input_buffer->offset--;
1370 goto fail;
1371 }
1372
1373 /* step back to character in front of the first element */
1374 input_buffer->offset--;
1375 /* loop through the comma separated array elements */
1376 do
1377 {
1378 /* allocate next item */
1379 cJSON *new_item = cJSON_New_Item(&(input_buffer->hooks));
1380 if (new_item == NULL)
1381 {
1382 goto fail; /* allocation failure */
1383 }
1384
1385 /* attach next item to list */
1386 if (head == NULL)
1387 {
1388 /* start the linked list */
1389 current_item = head = new_item;
1390 }
1391 else
1392 {
1393 /* add to the end and advance */
1394 current_item->next = new_item;
1395 new_item->prev = current_item;
1396 current_item = new_item;
1397 }
1398

Callers 1

parse_valueFunction · 0.85

Calls 4

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

Tested by

no test coverage detected