MCPcopy Create free account
hub / github.com/Tencent/Hardcoder / parse_array

Function parse_array

libapp2sys/src/main/cpp/cjson/cJSON.c:1345–1436  ·  view source on GitHub ↗

Build an array from input text. */

Source from the content-addressed store, hash-verified

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

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