Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

16
LINES

< > BotCompany Repo | #1030492 // replaceCharRanges

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (2862L/17K).

// no guarantees are made if you supply overlapping/out-of-bounds ranges
sS replaceCharRanges(S text, LPair<IntRange, S> replacements) {
  if (empty(replacements)) ret text;
  replacements = sortByPairsA(replacements);
  int iChar = 0, i = 0;
  new StringBuilder buf;
  while (i < l(replacements)) {
    Pair<IntRange, S> p = replacements.get(i++);
    buf.append(substring(text, iChar, p.a.start));
    buf.append(p.b);
    iChar = p.a.end;
  }
  if (iChar < l(text))
    buf.append(substring(text, iChar));
  ret str(buf);
}

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: 103 / 164
Version history: 2 change(s)
Referenced in: [show references]