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

16
LINES

< > BotCompany Repo | #1027480 // regexpQuote_useBackslashes

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

Libraryless. Click here for Pure Java version (2244L/14K).

sS regexpQuote_useBackslashes(S s) {
  if (s == null) null;
  StringBuilder buf = null;
  int n = l(s);
  for i to n: {
    char c = s.charAt(i);
    if (regexpSpecialCharacters().indexOf(c) < 0) {
      if (buf != null) buf.append(c);
    } else {
      if (buf == null) buf = new StringBuilder(takeFirst(i, s));
      buf.append('\\');
      buf.append(c);
    }
  }
  ret buf == null ? s : buf.toString();
}

Author comment

Began life as a copy of #1027465

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1027480
Snippet name: regexpQuote_useBackslashes
Eternal ID of this version: #1027480/4
Text MD5: 60230da54e872234c05aee1097d555f1
Transpilation MD5: c06565a63d4e6e5e4f34f1805d016d23
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-03-22 14:30:58
Source code size: 425 bytes / 16 lines
Pitched / IR pitched: No / No
Views / Downloads: 180 / 267
Version history: 3 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)