Libraryless. Click here for Pure Java version (57L/1K).
1 | static String htmlencode(Object o) {
|
2 | ret htmlencode(str(o)); |
3 | } |
4 | |
5 | static String htmlencode(String s) {
|
6 | if (s == null) ret ""; |
7 | StringBuilder out = new StringBuilder(Math.max(16, s.length())); |
8 | for (int i = 0; i < s.length(); i++) {
|
9 | char c = s.charAt(i); |
10 | if (c > 127 || c == '"' || c == '<' || c == '>' || c == '&') {
|
11 | int cp = s.codePointAt(i); |
12 | out.append("&#x");
|
13 | out.append(intToHex_flexLength(cp)); |
14 | out.append(';');
|
15 | i += Character.charCount(cp)-1; |
16 | } else |
17 | out.append(c); |
18 | } |
19 | ret out.toString(); |
20 | } |
http://stackoverflow.com/questions/1265282/recommended-method-for-escaping-html-in-java
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1001263 |
| Snippet name: | htmlencode |
| Eternal ID of this version: | #1001263/7 |
| Text MD5: | 2fbcc218224eea94068930c91d4f1a29 |
| Transpilation MD5: | d1fba18eab5f7930490101e19da1f0fd |
| Author: | stefan |
| Category: | |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2019-08-12 23:24:35 |
| Source code size: | 569 bytes / 20 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 1077 / 2688 |
| Version history: | 6 change(s) |
| Referenced in: | [show references] |