MCPcopy Create free account
hub / github.com/MariaDB/server / json_find_path

Function json_find_path

strings/json_lib.c:1521–1621  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1519
1520
1521int json_find_path(json_engine_t *je,
1522 json_path_t *p, json_path_step_t **p_cur_step,
1523 MEM_ROOT_DYNAMIC_ARRAY *array_counters)
1524{
1525 json_string_t key_name;
1526 int res= 0, value= 0, *value_ptr= NULL;
1527
1528 json_string_set_cs(&key_name, p->s.cs);
1529
1530 do
1531 {
1532 json_path_step_t *cur_step= *p_cur_step,
1533 *initial_step=
1534 (json_path_step_t*)(p->steps.buffer),
1535 *last_step=
1536 (json_path_step_t*)(p->steps.buffer) + p->last_step_idx;
1537 switch (je->state)
1538 {
1539 case JST_KEY:
1540 DBUG_ASSERT(cur_step->type & JSON_PATH_KEY);
1541 if (!(cur_step->type & JSON_PATH_WILD))
1542 {
1543 json_string_set_str(&key_name, cur_step->key, cur_step->key_end);
1544 if (!json_key_matches(je, &key_name))
1545 {
1546 if (json_skip_key(je))
1547 goto exit;
1548 continue;
1549 }
1550 }
1551 if (cur_step == last_step ||
1552 handle_match(je, p, p_cur_step, array_counters))
1553 goto exit;
1554 break;
1555 case JST_VALUE:
1556 DBUG_ASSERT(cur_step->type & JSON_PATH_ARRAY);
1557 if (cur_step->type & JSON_PATH_ARRAY_RANGE)
1558 {
1559 value_ptr= ((int*)(array_counters->buffer) + (cur_step - initial_step));
1560 res= (cur_step->n_item <= (value_ptr ? *value_ptr : 0) &&
1561 cur_step->n_item_end >= (value_ptr ? *value_ptr : 0));
1562 value= (value_ptr ? *value_ptr : 0) + 1;
1563
1564 *((int*)(array_counters->buffer)+(cur_step-initial_step))= value;
1565 }
1566 else
1567 {
1568 value= *((int*)(array_counters->buffer) + (cur_step - initial_step));
1569 res= cur_step->n_item == (value++);
1570 *((int*)(array_counters->buffer)+(cur_step-initial_step))= value;
1571 }
1572 if (res || (cur_step->type & JSON_PATH_WILD))
1573 {
1574 /* Array item matches. */
1575 if (cur_step == last_step ||
1576 handle_match(je, p, p_cur_step, array_counters))
1577 goto exit;
1578 }

Callers 6

fill_column_valuesMethod · 0.85
val_boolMethod · 0.85
extractMethod · 0.85
val_intMethod · 0.85
val_strMethod · 0.85
test_searchFunction · 0.85

Calls 6

json_string_set_csFunction · 0.85
json_string_set_strFunction · 0.85
json_key_matchesFunction · 0.85
json_skip_keyFunction · 0.85
handle_matchFunction · 0.85
json_scan_nextFunction · 0.85

Tested by 1

test_searchFunction · 0.68