static bool flexMatchIC_debug; static bool flexMatchIC(S pat, S s) { ret flexMatchIC(pat, s, null); } static bool flexMatchIC(S pat, S s, Matches m) { L<S> tokpat = codeTokens(javaTok(pat)); L<S> tokfull = joinBrackets(javaTok(s)); L<S> tok = codeTokens(tokfull); new BitSet bla; if (!flexMatchIC_impl(tokpat, 0, tok, 0, bla)) ret false; if (m != null) { new L<S> l; for (int i = 1; i < l(tokfull); i += 2) { if (bla.get(i/2)) { int j = i; while (j < l(tokfull) && bla.get(j/2)) j += 2; l.add(join(subList(tokfull, i, j-1))); i = j-2; } } m.m = toStringArray(l); } ret true; } static bool flexMatchIC_impl(L<S> pat, int ipat, L<S> tok, int itok, BitSet bla) { if (flexMatchIC_debug) print("flexMatchIC " + structure(subList(pat, ipat)) + " " + structure(subList(tok, itok)) + " " + structure(bla)); if (ipat >= l(pat)) ret itok >= l(tok); S t = pat.get(ipat); if (eq(t, "*")) if (itok >= l(tok)) // nothing to consume - just advance in pattern ret flexMatchIC_impl(pat, ipat+1, tok, itok, bla); else { // something to consume - try both continuing and ending to fill "*" bla.set(itok); if (flexMatchIC_impl(pat, ipat, tok, itok+1, bla) || flexMatchIC_impl(pat, ipat+1, tok, itok+1, bla)) ret true; // success, leave mark bla.clear(itok); // fail, undo marking ret false; } if (itok >= l(tok)) { if (flexMatchIC_debug) print("too much pattern"); ret false; } if (neqic(tok.get(itok), t)) { if (flexMatchIC_debug) print("mismatch"); ret false; } // ok, consume and proceed ret flexMatchIC_impl(pat, ipat+1, tok, itok+1, bla); }
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: | 544 / 530 |
Version history: | 1 change(s) |
Referenced in: | #1005501 - flexMatchIC2 - flexMatch (ignore case, with (a|b), does not drop punctuation) #1005507 - flexMatchIC - flexMatch (ignore case), fixing the empty "*" bug |