1 | static int findCodeTokens(L<S> tok, S... tokens) {
|
2 | ret findCodeTokens(tok, 1, false, tokens); |
3 | } |
4 | |
5 | static int findCodeTokens(L<S> tok, boolean ignoreCase, S... tokens) {
|
6 | ret findCodeTokens(tok, 1, ignoreCase, tokens); |
7 | } |
8 | |
9 | static int findCodeTokens(L<S> tok, int startIdx, boolean ignoreCase, S... tokens) {
|
10 | ret findCodeTokens(tok, startIdx, ignoreCase, tokens, null); |
11 | } |
12 | |
13 | static HashSet<S> findCodeTokens_specials = lithashset("*", "<quoted>", "<id>", "<int>", "\\*");
|
14 | static bool findCodeTokens_debug; |
15 | static int findCodeTokens_indexed, findCodeTokens_unindexed; |
16 | static int findCodeTokens_bails, findCodeTokens_nonbails; |
17 | |
18 | static int findCodeTokens(L<S> tok, int startIdx, boolean ignoreCase, S[] tokens, O condition) {
|
19 | if (findCodeTokens_debug) {
|
20 | if (eq(getClassName(tok), "main$IndexedList2")) |
21 | findCodeTokens_indexed++; |
22 | else |
23 | findCodeTokens_unindexed++; |
24 | } |
25 | // bail out early if first token not found (works great with IndexedList) |
26 | if (!ignoreCase && !findCodeTokens_specials.contains(tokens[0]) |
27 | && !tok.contains(tokens[0] /*, startIdx << no signature in List for this, unfortunately */)) {
|
28 | ++findCodeTokens_bails; |
29 | ret -1; |
30 | } |
31 | ++findCodeTokens_nonbails; |
32 | |
33 | int end = tok.size()-tokens.length*2+2, nTokens = tokens.length; |
34 | outer: for (int i = startIdx | 1; i < end; i += 2) {
|
35 | for (int j = 0; j < nTokens; j++) {
|
36 | S p = tokens[j], t = tok.get(i+j*2); |
37 | boolean match; |
38 | if (eq(p, "*")) match = true; |
39 | else if (eq(p, "<quoted>")) match = isQuoted(t); |
40 | else if (eq(p, "<id>")) match = isIdentifier(t); |
41 | else if (eq(p, "<int>")) match = isInteger(t); |
42 | else if (eq(p, "\\*")) match = eq("*", t);
|
43 | else match = ignoreCase ? eqic(p, t) : eq(p, t); |
44 | |
45 | if (!match) |
46 | continue outer; |
47 | } |
48 | |
49 | if (condition == null || checkTokCondition(condition, tok, i-1)) // pass N index |
50 | return i; |
51 | } |
52 | return -1; |
53 | } |
Began life as a copy of #1001193
download show line numbers debug dex old transpilations
Travelled to 7 computer(s): bhatertpkbcr, cfunsshuasjs, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1021950 |
| Snippet name: | findCodeTokens - backup |
| Eternal ID of this version: | #1021950/1 |
| Text MD5: | 5d267fe4e86dbed9d5ecc38623eb8a84 |
| Author: | stefan |
| Category: | javax |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2019-03-04 00:28:23 |
| Source code size: | 1966 bytes / 53 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 549 / 576 |
| Referenced in: | [show references] |