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

27
LINES

< > BotCompany Repo | #1031867 // htmlencode_noQuotes_prettier [dev.]

JavaX fragment (include)

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


private static final HashMap<String, CharSequence> htmlencode_noQuotes_prettier_lookupMap;

static {
  htmlencode_noQuotes_prettier_lookupMap = new HashMap<String, CharSequence>();
  for (CharSequence[] seq : htmldecode_escapes()) 
    htmlencode_noQuotes_prettier_lookupMap.put(seq[0].toString(), seq[1]);
}

Author comment

Began life as a copy of #1011153

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx

No comments. add comment

Snippet ID: #1031867
Snippet name: htmlencode_noQuotes_prettier [dev.]
Eternal ID of this version: #1031867/1
Text MD5: bad7abea41b3391f4738f4d034b6d52f
Author: stefan
Category: javax / html
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-07-21 15:48:35
Source code size: 878 bytes / 27 lines
Pitched / IR pitched: No / No
Views / Downloads: 71 / 92
Referenced in: [show references]