MCPcopy Create free account
hub / github.com/antlr/codebuff / escapeHTML

Method escapeHTML

output/java/1.4.17/StringRenderer.java:70–100  ·  view source on GitHub ↗
(String s)

Source from the content-addressed store, hash-verified

68 }
69
70 public static String escapeHTML(String s) {
71 if ( s==null ) {
72 return null;
73 }
74
75 StringBuilder buf = new StringBuilder(s.length());
76 int len = s.length();
77 for (int i = 0; i < len; i++) {
78 char c = s.charAt(i);
79 switch ( c ) {
80 case '&' : buf.append("&amp;");
81 break;
82 case '<' : buf.append("&lt;");
83 break;
84 case '>' : buf.append("&gt;");
85 break;
86 case '\r' : case '\n' : case '\t' : buf.append(c);
87 break;
88 default:
89 boolean control = c<' '; // 32
90 boolean aboveASCII = c>126;
91 if ( control || aboveASCII ) {
92 buf.append("&#");
93 buf.append((int)c);
94 buf.append(";");
95 }
96 else buf.append(c);
97 }
98 }
99 return buf.toString();
100 }
101}

Callers 3

toStringMethod · 0.95
toStringMethod · 0.95

Calls 3

toStringMethod · 0.65
lengthMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected