Libraryless. Click here for Pure Java version (3981L/23K).
1 | sS htmlencode_noQuotes(S s) {
|
2 | if (s == null) ret ""; |
3 | int n = s.length(); |
4 | StringBuilder out = null; |
5 | |
6 | macro builder {
|
7 | out if null = new StringBuilder(Math.max(16, n)).append(takeFirst(i, s)); |
8 | out |
9 | } |
10 | |
11 | for i to n: {
|
12 | char c = s.charAt(i); |
13 | if (c == '<') {
|
14 | builder.append("<");
|
15 | } |
16 | else if (c == '>') {
|
17 | builder.append(">");
|
18 | } |
19 | else if (c > 127 || c == '&') {
|
20 | int cp = s.codePointAt(i); |
21 | builder.append("&#x");
|
22 | out.append(intToHex_flexLength(cp)); |
23 | out.append(';');
|
24 | i += Character.charCount(cp)-1; |
25 | } else |
26 | out?.append(c); |
27 | } |
28 | ret out == null ? s : out.toString(); |
29 | } |
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: | 745 / 1041 |
| Version history: | 9 change(s) |
| Referenced in: | [show references] |