Libraryless. Click here for Pure Java version (5788L/32K).
1 | static S jreplace1(S s, S in, S out) { |
2 | ret jreplace1(s, in, out, null); |
3 | } |
4 | |
5 | static S jreplace1(S s, S in, S out, O condition) { |
6 | L<S> tok = javaTok(s); |
7 | ret jreplace1(tok, in, out, condition) ? join(tok) : s; |
8 | } |
9 | |
10 | // leaves tok properly tokenized |
11 | // returns true iff anything was replaced |
12 | static boolean jreplace1(L<S> tok, S in, S out) { |
13 | ret jreplace1(tok, in, out, false, true, null); |
14 | } |
15 | |
16 | static boolean jreplace1(L<S> tok, S in, S out, O condition) { |
17 | ret jreplace1(tok, in, out, false, true, condition); |
18 | } |
19 | |
20 | static boolean jreplace1(L<S> tok, S in, S out, boolean ignoreCase, boolean reTok, O condition) { |
21 | L<S> tokin = javaTok(in); |
22 | jfind_preprocess(tokin); |
23 | |
24 | boolean anyChange = false; |
25 | int i = 1; |
26 | while ((i = findCodeTokens(tok, i, ignoreCase, toStringArray(codeTokensOnly(tokin)), condition)) >= 0) { |
27 | L<S> subList = tok.subList(i-1, i+l(tokin)-1); // N to N |
28 | S expansion = jreplaceExpandRefs(out, subList); |
29 | int end = i+l(tokin)-2; |
30 | clearAllTokens(tok, i, end); // C to C |
31 | tok.set(i, expansion); |
32 | int l = l(tok); |
33 | if (reTok) // would this ever be false?? |
34 | reTok(tok, i, end); |
35 | i = end+l(tok)-l; |
36 | anyChange = true; |
37 | } |
38 | ret anyChange; |
39 | } |
40 | |
41 | static bool jreplace1_debug; |
Began life as a copy of #1002133
download show line numbers debug dex old transpilations
Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1004948 |
Snippet name: | jreplace1 - go through code just once |
Eternal ID of this version: | #1004948/4 |
Text MD5: | cb080431e11cff13e66527b7c5fa2521 |
Transpilation MD5: | 059498dceddcac4eead0ef7021e5517b |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-03-07 21:42:29 |
Source code size: | 1255 bytes / 41 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 633 / 811 |
Version history: | 3 change(s) |
Referenced in: | [show references] |