Libraryless. Click here for Pure Java version (2862L/17K).
1 | // no guarantees are made if you supply overlapping/out-of-bounds ranges |
2 | sS replaceCharRanges(S text, LPair<IntRange, S> replacements) { |
3 | if (empty(replacements)) ret text; |
4 | replacements = sortByPairsA(replacements); |
5 | int iChar = 0, i = 0; |
6 | new StringBuilder buf; |
7 | while (i < l(replacements)) { |
8 | Pair<IntRange, S> p = replacements.get(i++); |
9 | buf.append(substring(text, iChar, p.a.start)); |
10 | buf.append(p.b); |
11 | iChar = p.a.end; |
12 | } |
13 | if (iChar < l(text)) |
14 | buf.append(substring(text, iChar)); |
15 | ret str(buf); |
16 | } |
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt
No comments. add comment
Snippet ID: | #1030492 |
Snippet name: | replaceCharRanges |
Eternal ID of this version: | #1030492/3 |
Text MD5: | e3cba59c2a72ae735bfa49663e0172a7 |
Transpilation MD5: | cb7d1f39bafa078f36e6e2c333fecd32 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2020-12-28 01:13:47 |
Source code size: | 541 bytes / 16 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 183 / 264 |
Version history: | 2 change(s) |
Referenced in: | [show references] |