1 | static bool flexMatchIC_debug; |
2 | |
3 | static bool flexMatchIC(S pat, S s) { |
4 | ret flexMatchIC(pat, s, null); |
5 | } |
6 | |
7 | static bool flexMatchIC(S pat, S s, Matches m) { |
8 | L<S> tokpat = codeTokens(javaTok(pat)); |
9 | L<S> tokfull = joinBrackets(javaTok(s)); |
10 | L<S> tok = codeTokens(tokfull); |
11 | new BitSet bla; |
12 | if (!flexMatchIC_impl(tokpat, 0, tok, 0, bla)) ret false; |
13 | if (m != null) { |
14 | new L<S> l; |
15 | for (int i = 1; i < l(tokfull); i += 2) { |
16 | if (bla.get(i/2)) { |
17 | int j = i; |
18 | while (j < l(tokfull) && bla.get(j/2)) j += 2; |
19 | l.add(join(subList(tokfull, i, j-1))); |
20 | i = j-2; |
21 | } |
22 | } |
23 | m.m = toStringArray(l); |
24 | } |
25 | ret true; |
26 | } |
27 | |
28 | static bool flexMatchIC_impl(L<S> pat, int ipat, L<S> tok, int itok, BitSet bla) { |
29 | if (flexMatchIC_debug) |
30 | print("flexMatchIC " + structure(subList(pat, ipat)) + " " + structure(subList(tok, itok)) + " " + structure(bla)); |
31 | if (ipat >= l(pat)) |
32 | ret itok >= l(tok); |
33 | S t = pat.get(ipat); |
34 | if (eq(t, "*")) |
35 | if (itok >= l(tok)) // nothing to consume - just advance in pattern |
36 | ret flexMatchIC_impl(pat, ipat+1, tok, itok, bla); |
37 | else { // something to consume - try both continuing and ending to fill "*" |
38 | bla.set(itok); |
39 | if (flexMatchIC_impl(pat, ipat, tok, itok+1, bla) |
40 | || flexMatchIC_impl(pat, ipat+1, tok, itok+1, bla)) |
41 | ret true; // success, leave mark |
42 | bla.clear(itok); // fail, undo marking |
43 | ret false; |
44 | } |
45 | if (itok >= l(tok)) { |
46 | if (flexMatchIC_debug) |
47 | print("too much pattern"); |
48 | ret false; |
49 | } |
50 | if (neqic(tok.get(itok), t)) { |
51 | if (flexMatchIC_debug) |
52 | print("mismatch"); |
53 | ret false; |
54 | } |
55 | // ok, consume and proceed |
56 | ret flexMatchIC_impl(pat, ipat+1, tok, itok+1, bla); |
57 | } |
Began life as a copy of #1003148
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1005459 |
Snippet name: | flexMatchIC - flexMatch (ignore case, OLD) |
Eternal ID of this version: | #1005459/2 |
Text MD5: | f61a2da98b063c071a01c22409a178b5 |
Author: | stefan |
Category: | javax / parsing |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2017-03-23 16:50:36 |
Source code size: | 1776 bytes / 57 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 603 / 593 |
Version history: | 1 change(s) |
Referenced in: | [show references] |