Libraryless. Click here for Pure Java version (11242L/62K).
1 | scope replaceKeywordBlock_dyn |
2 | |
3 | sinterface #IReplacer { |
4 | S[] get(LS tok, int iOpening, int iClosing); |
5 | } |
6 | |
7 | static LS replaceKeywordBlock_dyn(S bracket default "{", LS tok, S keyword, IReplacer func) { |
8 | for (int i = 0; i < 1000; i++) { |
9 | int idx = findCodeTokens(tok, keyword, bracket); |
10 | if (idx < 0) |
11 | break; |
12 | int j = findEndOfBracketPart(tok, idx+2); |
13 | |
14 | S[] be = func?.get(tok, idx+2, j-1); |
15 | tok.set(idx, unnull(first(be))); |
16 | tok.set(idx+1, " "); |
17 | tok.set(idx+2, ""); |
18 | tok.set(j-1, unnull(second(be))); |
19 | reTok(tok, idx, j); |
20 | } |
21 | ret tok; |
22 | } |
23 | |
24 | end scope |
Began life as a copy of #1018806
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt
No comments. add comment
Snippet ID: | #1031419 |
Snippet name: | replaceKeywordBlock_dyn - finally the interface version we all want |
Eternal ID of this version: | #1031419/10 |
Text MD5: | b1f297564a54ab21441b7331e37696bd |
Transpilation MD5: | 507125547f388fe729d20ce29c1ea4f0 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2023-07-26 21:59:38 |
Source code size: | 607 bytes / 24 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 289 / 511 |
Version history: | 9 change(s) |
Referenced in: | [show references] |