sbool matchDoubleRest(S pat, S s) { ret matchDoubleRest(pat, s, null); } // matches are as you expect, plus an extra item for half of the rest string sbool matchDoubleRest(S pat, S s, Matches matches) { if (s == null) false; ret matchDoubleRest(pat, parse3_cachedInput(s), matches); } sbool matchDoubleRest(S pat, LS toks, Matches matches) { if (toks == null) false; LS tokpat = parse3_cachedPattern(pat); int n = toks.size(), nPat = tokpat.size(); if (n <= nPat || odd((n-nPat)/2)) ret false; int nRest = (n-nPat)/4; ifdef matchDoubleRest_debug print(+nRest); endifdef S[] m = match2(tokpat, subList(toks, 0, nPat)); if (m == null) false; for (int i = nPat; i < nPat+nRest*2; i += 2) if (neqic(toks.get(i), toks.get(i+nRest*2))) { ifdef matchDoubleRest_debug print("fail at " + i + ": " + toks.get(i) + " / " + toks.get(i+nRest*2)); endifdef ret false; } if (matches != null) { matches.m = new S[m.length+1]; arraycopy(m, matches.m); matches.m[m.length] = joinSubList(toks, nPat, nPat+nRest*2-1); // for Matches.rest() } true; }
Began life as a copy of #1001793
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: | #1023234 |
Snippet name: | matchDoubleRest function - e.g. "is" matches "is green green" or "is good luck good luck" |
Eternal ID of this version: | #1023234/8 |
Text MD5: | 9675fd28101292c6e3478afc523a66a2 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2019-05-19 00:09:07 |
Source code size: | 1155 bytes / 37 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 289 / 350 |
Version history: | 7 change(s) |
Referenced in: | [show references] |