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

29
LINES

< > BotCompany Repo | #1011153 // htmlencode_noQuotes - now with extended unicode characters

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

Libraryless. Click here for Pure Java version (3981L/23K).

sS htmlencode_noQuotes(S s) {
  if (s == null) ret "";
  int n = s.length();
  StringBuilder out = null;
  
  macro builder {
    out if null = new StringBuilder(Math.max(16, n)).append(takeFirst(i, s));
    out
  }
  
  for i to n: {
    char c = s.charAt(i);
    if (c == '<') {
      builder.append("&lt;");
    }
    else if (c == '>') {
      builder.append("&gt;");
    }
    else if (c > 127 || c == '&') {
      int cp = s.codePointAt(i);
      builder.append("&#x");
      out.append(intToHex_flexLength(cp));
      out.append(';');
      i += Character.charCount(cp)-1;
    } else
      out?.append(c);
  }
  ret out == null ? s : out.toString();
}

Author comment

Began life as a copy of #1001263

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ekrmjmnbrukm, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1011153
Snippet name: htmlencode_noQuotes - now with extended unicode characters
Eternal ID of this version: #1011153/10
Text MD5: 2f0d6ada07a1dbcb7b54fe488b26d2d4
Transpilation MD5: 2fe144c2f73830c0fb07de4eeaf91bb2
Author: stefan
Category: javax / html
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-10-10 23:52:32
Source code size: 686 bytes / 29 lines
Pitched / IR pitched: No / No
Views / Downloads: 482 / 721
Version history: 9 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)
#1011306 - htmlencode_noQuote - synonym of htmlencode_noQuotes
#1012985 - htmlencode2 - synonym of htmlencode_noQuotes - use this for stuff not in HTML tag parameters
#1031867 - htmlencode_noQuotes_prettier [dev.]
#1032927 - htmlencode_noQuotes_unoptimized