csonpath 0.9.0__tar.gz → 0.10.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {csonpath-0.9.0/csonpath.egg-info → csonpath-0.10.0}/PKG-INFO +1 -1
- {csonpath-0.9.0 → csonpath-0.10.0/csonpath.egg-info}/PKG-INFO +1 -1
- {csonpath-0.9.0 → csonpath-0.10.0}/csonpath.h +81 -67
- {csonpath-0.9.0 → csonpath-0.10.0}/csonpath_do.h +54 -0
- {csonpath-0.9.0 → csonpath-0.10.0}/csonpath_python.c +11 -0
- {csonpath-0.9.0 → csonpath-0.10.0}/pyproject.toml +2 -2
- {csonpath-0.9.0 → csonpath-0.10.0}/LICENSE +0 -0
- {csonpath-0.9.0 → csonpath-0.10.0}/MANIFEST.in +0 -0
- {csonpath-0.9.0 → csonpath-0.10.0}/README.md +0 -0
- {csonpath-0.9.0 → csonpath-0.10.0}/csonpath.egg-info/SOURCES.txt +0 -0
- {csonpath-0.9.0 → csonpath-0.10.0}/csonpath.egg-info/dependency_links.txt +0 -0
- {csonpath-0.9.0 → csonpath-0.10.0}/csonpath.egg-info/requires.txt +0 -0
- {csonpath-0.9.0 → csonpath-0.10.0}/csonpath.egg-info/top_level.txt +0 -0
- {csonpath-0.9.0 → csonpath-0.10.0}/setup.cfg +0 -0
|
@@ -57,6 +57,7 @@ enum csonpath_instuction_raw {
|
|
|
57
57
|
CSONPATH_INST_FILTER_AND,
|
|
58
58
|
CSONPATH_INST_GET_ALL,
|
|
59
59
|
CSONPATH_INST_FIND_ALL,
|
|
60
|
+
CSONPATH_INST_RANGE,
|
|
60
61
|
CSONPATH_INST_OR,
|
|
61
62
|
CSONPATH_INST_END,
|
|
62
63
|
CSONPATH_INST_BROKEN
|
|
@@ -80,6 +81,7 @@ CSONPATH_UNUSED static const char *csonpath_instuction_str[] = {
|
|
|
80
81
|
"FILTER_AND",
|
|
81
82
|
"GET_ALL",
|
|
82
83
|
"FIND_ALL",
|
|
84
|
+
"RANGE",
|
|
83
85
|
"OR",
|
|
84
86
|
"END",
|
|
85
87
|
"BROKEN"
|
|
@@ -240,6 +242,43 @@ static inline _Bool csonpath_is_dot_operand(int c)
|
|
|
240
242
|
return isalnum(c) || c == '_' || c == '-';
|
|
241
243
|
}
|
|
242
244
|
|
|
245
|
+
|
|
246
|
+
static int csonpath_fill_walker_with_int(char *walker, int num, int first_ret)
|
|
247
|
+
{
|
|
248
|
+
if (num < 100) {
|
|
249
|
+
*walker = num;
|
|
250
|
+
return first_ret;
|
|
251
|
+
}
|
|
252
|
+
union {
|
|
253
|
+
int n;
|
|
254
|
+
char c[4];
|
|
255
|
+
} u = {.n=num};
|
|
256
|
+
walker[0] = u.c[0];
|
|
257
|
+
walker[1] = u.c[1];
|
|
258
|
+
walker[2] = u.c[2];
|
|
259
|
+
walker[3] = u.c[3];
|
|
260
|
+
return first_ret + 1;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
static int csonpath_int_from_walker(int operand_instruction, char *walker)
|
|
264
|
+
{
|
|
265
|
+
switch(operand_instruction) {
|
|
266
|
+
case CSONPATH_INST_FILTER_OPERAND_BYTE:
|
|
267
|
+
case CSONPATH_INST_GET_ARRAY_SMALL:
|
|
268
|
+
return *walker;
|
|
269
|
+
case CSONPATH_INST_GET_ARRAY_BIG:
|
|
270
|
+
case CSONPATH_INST_FILTER_OPERAND_INT:
|
|
271
|
+
{
|
|
272
|
+
union {int n; char c[4];} to_num =
|
|
273
|
+
{ .c= { walker[0], walker[1], walker[2], walker[3] } };
|
|
274
|
+
return to_num.n;
|
|
275
|
+
}
|
|
276
|
+
default:
|
|
277
|
+
break;
|
|
278
|
+
}
|
|
279
|
+
return -1;
|
|
280
|
+
}
|
|
281
|
+
|
|
243
282
|
static int csonpath_compile(struct csonpath cjp[static 1])
|
|
244
283
|
{
|
|
245
284
|
char *walker = cjp->path;
|
|
@@ -479,20 +518,8 @@ static int csonpath_compile(struct csonpath cjp[static 1])
|
|
|
479
518
|
|
|
480
519
|
n = atoi(walker);
|
|
481
520
|
to_check = *next;
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
csonpath_push_inst(cjp, CSONPATH_INST_FILTER_OPERAND_BYTE, &inst_idx);
|
|
485
|
-
} else {
|
|
486
|
-
union {
|
|
487
|
-
int n;
|
|
488
|
-
char c[4];
|
|
489
|
-
} u = {.n=n};
|
|
490
|
-
walker[0] = u.c[0];
|
|
491
|
-
walker[1] = u.c[1];
|
|
492
|
-
walker[2] = u.c[2];
|
|
493
|
-
walker[3] = u.c[3];
|
|
494
|
-
csonpath_push_inst(cjp, CSONPATH_INST_FILTER_OPERAND_INT, &inst_idx);
|
|
495
|
-
}
|
|
521
|
+
csonpath_push_inst(cjp, csonpath_fill_walker_with_int(
|
|
522
|
+
walker, n, CSONPATH_INST_FILTER_OPERAND_BYTE), &inst_idx);
|
|
496
523
|
}
|
|
497
524
|
|
|
498
525
|
/* skip space */
|
|
@@ -537,11 +564,23 @@ static int csonpath_compile(struct csonpath cjp[static 1])
|
|
|
537
564
|
|
|
538
565
|
next = walker;
|
|
539
566
|
do {
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
567
|
+
if (*next == ':') {
|
|
568
|
+
csonpath_push_inst(cjp, CSONPATH_INST_RANGE, &inst_idx);
|
|
569
|
+
num = atoi(walker);
|
|
570
|
+
csonpath_push_inst(
|
|
571
|
+
cjp, csonpath_fill_walker_with_int(
|
|
572
|
+
walker, num, CSONPATH_INST_GET_ARRAY_SMALL),
|
|
573
|
+
&inst_idx);
|
|
574
|
+
cjp->inst_lst[inst_idx - 1].next = next - walker + 1;
|
|
575
|
+
walker = next + 1;
|
|
576
|
+
++next;
|
|
577
|
+
continue;
|
|
578
|
+
}
|
|
579
|
+
if (*next < '0' || *next > '9') {
|
|
580
|
+
CSONPATH_COMPILE_ERR(tmp, walker - orig,
|
|
581
|
+
"unexpected '%c', sting, filter or number require\n", *next);
|
|
582
|
+
}
|
|
583
|
+
next++;
|
|
545
584
|
} while (*next && *next != ']');
|
|
546
585
|
if (!*next) {
|
|
547
586
|
CSONPATH_COMPILE_ERR(tmp, walker - orig,
|
|
@@ -549,20 +588,9 @@ static int csonpath_compile(struct csonpath cjp[static 1])
|
|
|
549
588
|
}
|
|
550
589
|
*next = 0;
|
|
551
590
|
num = atoi(walker);
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
} else {
|
|
556
|
-
union {
|
|
557
|
-
int n;
|
|
558
|
-
char c[4];
|
|
559
|
-
} u = {.n=num};
|
|
560
|
-
walker[0] = u.c[0];
|
|
561
|
-
walker[1] = u.c[1];
|
|
562
|
-
walker[2] = u.c[2];
|
|
563
|
-
walker[3] = u.c[3];
|
|
564
|
-
csonpath_push_inst(cjp, CSONPATH_INST_GET_ARRAY_BIG, &inst_idx);
|
|
565
|
-
}
|
|
591
|
+
csonpath_push_inst(cjp, csonpath_fill_walker_with_int(
|
|
592
|
+
walker, num, CSONPATH_INST_GET_ARRAY_SMALL),
|
|
593
|
+
&inst_idx);
|
|
566
594
|
cjp->inst_lst[inst_idx - 1].next = next - walker + 1;
|
|
567
595
|
walker = next + 1;
|
|
568
596
|
to_check = *walker;
|
|
@@ -656,19 +684,6 @@ static int csonpath_compile(struct csonpath cjp[static 1])
|
|
|
656
684
|
return -1;
|
|
657
685
|
}
|
|
658
686
|
|
|
659
|
-
static int csonpath_int_from_walker(int operand_instruction, char *walker)
|
|
660
|
-
{
|
|
661
|
-
if (operand_instruction == CSONPATH_INST_FILTER_OPERAND_BYTE)
|
|
662
|
-
return *walker;
|
|
663
|
-
else if (operand_instruction == CSONPATH_INST_FILTER_OPERAND_INT) {
|
|
664
|
-
union {int n; char c[4];} to_num =
|
|
665
|
-
{ .c= { walker[0], walker[1], walker[2], walker[3] } };
|
|
666
|
-
|
|
667
|
-
return to_num.n;
|
|
668
|
-
}
|
|
669
|
-
return -1;
|
|
670
|
-
}
|
|
671
|
-
|
|
672
687
|
static _Bool csonpath_do_match(int operand_instruction, CSONPATH_JSON el2, char *owalker)
|
|
673
688
|
{
|
|
674
689
|
switch (operand_instruction) {
|
|
@@ -881,15 +896,26 @@ need_reloop_in = 0;
|
|
|
881
896
|
#define CSONPATH_DO_FILTER_FIND nb_res += tret;
|
|
882
897
|
|
|
883
898
|
#define CSONPATH_DO_FIND_ALL ({ \
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
899
|
+
if (tret < 0) return -1; \
|
|
900
|
+
nb_res += tret; \
|
|
901
|
+
if (need_reloop_in){ goto again; }; \
|
|
902
|
+
})
|
|
903
|
+
|
|
904
|
+
#define CSONPATH_DO_RANGE ({ \
|
|
905
|
+
if (tret < 0) return -1; \
|
|
906
|
+
nb_res += tret; \
|
|
907
|
+
--end; \
|
|
908
|
+
if (need_reloop_in){ goto range_again; }; \
|
|
909
|
+
})
|
|
888
910
|
|
|
889
911
|
#define CSONPATH_DO_EXTRA_DECLATION , struct csonpath_child_info child_info, int *need_reloop
|
|
890
912
|
|
|
891
913
|
#define CSONPATH_DO_EXTRA_ARGS_IN , (struct csonpath_child_info) {.type = CSONPATH_NONE}, NULL
|
|
892
914
|
|
|
915
|
+
#define CSONPATH_DO_RANGE_PRE_LOOP \
|
|
916
|
+
int need_reloop_in; \
|
|
917
|
+
range_again:
|
|
918
|
+
|
|
893
919
|
#define CSONPATH_DO_FILTER_PRE_LOOP \
|
|
894
920
|
int need_reloop_in;
|
|
895
921
|
|
|
@@ -1046,17 +1072,16 @@ static int csonpath_sync_root_obj(CSONPATH_JSON parent, CSONPATH_JSON to_update)
|
|
|
1046
1072
|
#define CSONPATH_DO_RETURN \
|
|
1047
1073
|
if (tmp == value) { \
|
|
1048
1074
|
*need_reloop = 1; \
|
|
1049
|
-
CSONPATH_CALL_CALLBACK(callback, ctx, child_info, tmp, udata); \
|
|
1050
|
-
return 1; \
|
|
1051
1075
|
} \
|
|
1052
|
-
|
|
1076
|
+
CSONPATH_CALL_CALLBACK(callback, ctx, child_info, tmp, udata); \
|
|
1077
|
+
return 1;
|
|
1053
1078
|
|
|
1054
1079
|
#define CSONPATH_DO_EXTRA_ARGS_FIND_ALL , callback, udata, NULL, need_reloop
|
|
1055
1080
|
#define CSONPATH_DO_EXTRA_ARGS_NEESTED , callback, udata, \
|
|
1056
1081
|
csonpath_child_info_set(&(struct csonpath_child_info ){}, tmp, (intptr_t)key_idx), \
|
|
1057
1082
|
&need_reloop_in
|
|
1058
1083
|
#define CSONPATH_DO_EXTRA_ARGS , CSONPATH_CALLBACK callback, CSONPATH_CALLBACK_DATA udata
|
|
1059
|
-
#define CSONPATH_DO_EXTRA_ARGS_IN , callback, udata,
|
|
1084
|
+
#define CSONPATH_DO_EXTRA_ARGS_IN , callback, udata, &(struct csonpath_child_info ){}, NULL
|
|
1060
1085
|
#define CSONPATH_DO_EXTRA_DECLATION CSONPATH_DO_EXTRA_ARGS, struct csonpath_child_info *child_info, int *need_reloop
|
|
1061
1086
|
#define CSONPATH_DO_FIND_ALL nb_res += tret;
|
|
1062
1087
|
#define CSONPATH_DO_FILTER_FIND CSONPATH_GOTO_ON_RELOOP(filter_again)
|
|
@@ -1075,19 +1100,8 @@ static int csonpath_sync_root_obj(CSONPATH_JSON parent, CSONPATH_JSON to_update)
|
|
|
1075
1100
|
}
|
|
1076
1101
|
|
|
1077
1102
|
#define CSONPATH_PRE_GET(this_idx) \
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
do { \
|
|
1081
|
-
to_check = cjp->inst_lst[check_at].inst; \
|
|
1082
|
-
++check_at; \
|
|
1083
|
-
} while (to_check == CSONPATH_INST_GET_ALL || to_check == CSONPATH_INST_FIND_ALL); \
|
|
1084
|
-
if (to_check == CSONPATH_INST_END || to_check == CSONPATH_INST_OR) { \
|
|
1085
|
-
CSONPATH_CALL_CALLBACK( \
|
|
1086
|
-
callback, ctx, \
|
|
1087
|
-
csonpath_child_info_set(&(struct csonpath_child_info ){}, \
|
|
1088
|
-
ctx, (intptr_t)this_idx), tmp, udata); \
|
|
1089
|
-
return 1; \
|
|
1090
|
-
}
|
|
1103
|
+
int to_check = cjp->inst_lst[idx].inst; \
|
|
1104
|
+
csonpath_child_info_set(child_info, ctx, (intptr_t)this_idx)
|
|
1091
1105
|
|
|
1092
1106
|
|
|
1093
1107
|
#define CSONPATH_DO_GET_NOTFOUND(this_idx) \
|
|
@@ -93,6 +93,18 @@
|
|
|
93
93
|
#define CSONPATH_DO_FILTER_LOOP_PRE_SET
|
|
94
94
|
#endif
|
|
95
95
|
|
|
96
|
+
#ifndef CSONPATH_DO_RANGE
|
|
97
|
+
#define CSONPATH_DO_RANGE CSONPATH_DO_FIND_ALL
|
|
98
|
+
#endif
|
|
99
|
+
|
|
100
|
+
#ifndef CSONPATH_DO_RANGE
|
|
101
|
+
#define CSONPATH_DO_RANGE CSONPATH_DO_FIND_ALL
|
|
102
|
+
#endif
|
|
103
|
+
|
|
104
|
+
#ifndef CSONPATH_DO_RANGE_PRE_LOOP
|
|
105
|
+
#define CSONPATH_DO_RANGE_PRE_LOOP CSONPATH_DO_FIND_ALL_PRE_LOOP
|
|
106
|
+
#endif
|
|
107
|
+
|
|
96
108
|
#ifndef CAT
|
|
97
109
|
# define CATCAT(a, b, c) a ## b ## c
|
|
98
110
|
# define CAT(a, b) a ## b
|
|
@@ -234,6 +246,46 @@ static CSONPATH_DO_RET_TYPE csonpath_do_internal(struct csonpath cjp[static 1],
|
|
|
234
246
|
CSONPATH_DO_FIND_ALL_CLEAUP;
|
|
235
247
|
return tret;
|
|
236
248
|
}
|
|
249
|
+
case CSONPATH_INST_RANGE:
|
|
250
|
+
{
|
|
251
|
+
if (!CSONPATH_IS_ARRAY(tmp)) {
|
|
252
|
+
return CSONPATH_NONE_FOUND_RET;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
CSONPATH_JSON el;
|
|
256
|
+
intptr_t key_idx;
|
|
257
|
+
|
|
258
|
+
(void)key_idx;
|
|
259
|
+
int next_0 = cjp->inst_lst[idx].next;
|
|
260
|
+
int next_1 = cjp->inst_lst[idx + 1].next;
|
|
261
|
+
int next_2 = cjp->inst_lst[idx + 2].next;
|
|
262
|
+
unsigned int beg = csonpath_int_from_walker(cjp->inst_lst[idx + 1].inst, walker + next_0);
|
|
263
|
+
unsigned int end = csonpath_int_from_walker(cjp->inst_lst[idx + 2].inst,
|
|
264
|
+
walker + next_0 + next_1);
|
|
265
|
+
|
|
266
|
+
if (!end)
|
|
267
|
+
end = -1;
|
|
268
|
+
|
|
269
|
+
CSONPATH_DO_RANGE_PRE_LOOP;
|
|
270
|
+
CSONPATH_FOREACH_ARRAY(tmp, el, key_idx) {
|
|
271
|
+
if (key_idx < beg) {
|
|
272
|
+
key_idx = beg - 1;
|
|
273
|
+
continue;
|
|
274
|
+
}
|
|
275
|
+
if (key_idx >= end)
|
|
276
|
+
break;
|
|
277
|
+
CSONPATH_DO_FOREACH_PRE_SET
|
|
278
|
+
CSONPATH_DO_RET_TYPE tret =
|
|
279
|
+
csonpath_do_internal(cjp, origin, el, tmp, idx + 3,
|
|
280
|
+
walker + next_0 + next_1 + next_2
|
|
281
|
+
CSONPATH_DO_EXTRA_ARGS_NEESTED);
|
|
282
|
+
|
|
283
|
+
CSONPATH_DO_RANGE;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
CSONPATH_DO_GET_ALL_OUT;
|
|
287
|
+
break;
|
|
288
|
+
}
|
|
237
289
|
case CSONPATH_INST_GET_ALL:
|
|
238
290
|
{
|
|
239
291
|
CSONPATH_JSON el;
|
|
@@ -361,5 +413,7 @@ static CSONPATH_DO_RET_TYPE csonpath_do_(struct csonpath cjp[static 1],
|
|
|
361
413
|
#undef CSONPATH_DO_FILTER_PRE_LOOP
|
|
362
414
|
#undef CSONPATH_DO_FILTER_FIND
|
|
363
415
|
#undef CSONPATH_DO_FILTER_LOOP_PRE_SET
|
|
416
|
+
#undef CSONPATH_DO_RANGE
|
|
417
|
+
#undef CSONPATH_DO_RANGE_PRE_LOOP
|
|
364
418
|
|
|
365
419
|
#endif
|
|
@@ -131,7 +131,18 @@ static int python_set_or_insert_item(PyObject *array, Py_ssize_t at, PyObject *
|
|
|
131
131
|
) (array, at, el)
|
|
132
132
|
|
|
133
133
|
|
|
134
|
+
#if PY_MAJOR_VERSION > 3 || (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 13)
|
|
135
|
+
/* PyList_Clear was introduced in Python 3.13 */
|
|
134
136
|
#define CSONPATH_ARRAY_CLEAR(o) PyList_Clear(o)
|
|
137
|
+
#else
|
|
138
|
+
/* For older versions, manually clear the list */
|
|
139
|
+
#define CSONPATH_ARRAY_CLEAR(o) \
|
|
140
|
+
do { \
|
|
141
|
+
while (PyList_Size(o) > 0) { \
|
|
142
|
+
PyList_SetSlice(o, 0, PyList_Size(o), NULL); \
|
|
143
|
+
} \
|
|
144
|
+
} while (0)
|
|
145
|
+
#endif
|
|
135
146
|
|
|
136
147
|
#define CSONPATH_OBJ_CLEAR(o) PyDict_Clear(o)
|
|
137
148
|
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "csonpath"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.10.0"
|
|
8
8
|
readme = "README.md"
|
|
9
9
|
|
|
10
10
|
[tool.setuptools]
|
|
@@ -22,7 +22,7 @@ dev = [
|
|
|
22
22
|
testpaths = ["tests/python"]
|
|
23
23
|
|
|
24
24
|
[tool.bumpversion]
|
|
25
|
-
current_version = "0.
|
|
25
|
+
current_version = "0.10.0"
|
|
26
26
|
parse = "(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)"
|
|
27
27
|
serialize = ["{major}.{minor}.{patch}"]
|
|
28
28
|
search = "{current_version}"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|