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

14
LINES

< > BotCompany Repo | #1030301 // htmlencode_forParams_v2 - also encodes entities

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

Libraryless. Click here for Pure Java version (39L/1K).

sS htmlencode_forParams_v2(S 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 > 127 || c == '"' || c == '<' || c == '>' || c == '&') {
          out.append("&#");
          out.append((int) c);
          out.append(';');
      } else
          out.append(c);
  }
  ret out.toString();
}

Author comment

Began life as a copy of #1012893

download  show line numbers  debug dex  old transpilations   

Travelled to 8 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, vouqrxazstgt, wnsclhtenguj

No comments. add comment

Snippet ID: #1030301
Snippet name: htmlencode_forParams_v2 - also encodes entities
Eternal ID of this version: #1030301/1
Text MD5: 49822b106ee40918e71c74bf8d18a965
Transpilation MD5: 3d8c9224a141761c270aa7af010daa8f
Author: stefan
Category: javax / html
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-11-28 12:55:11
Source code size: 428 bytes / 14 lines
Pitched / IR pitched: No / No
Views / Downloads: 195 / 1180
Referenced in: [show references]