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).

1  
sS htmlencode_forParams_v2(S s) {
2  
  if (s == null) ret "";
3  
  StringBuilder out = new StringBuilder(Math.max(16, s.length()));
4  
  for (int i = 0; i < s.length(); i++) {
5  
      char c = s.charAt(i);
6  
      if (c > 127 || c == '"' || c == '<' || c == '>' || c == '&') {
7  
          out.append("&#");
8  
          out.append((int) c);
9  
          out.append(';');
10  
      } else
11  
          out.append(c);
12  
  }
13  
  ret out.toString();
14  
}

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: 128 / 1097
Referenced in: [show references]