MCPcopy Index your code
hub / github.com/antlr/codebuff / escapeHTML

Method escapeHTML

output/java8/1.4.17/StringRenderer.java:70–104  ·  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 '&' :
81 buf.append("&amp;");
82 break;
83 case '<' :
84 buf.append("&lt;");
85 break;
86 case '>' :
87 buf.append("&gt;");
88 break;
89 case '\r' : case '\n' : case '\t' :
90 buf.append(c);
91 break;
92 default:
93 boolean control = c<' '; // 32
94 boolean aboveASCII = c>126;
95 if ( control || aboveASCII ) {
96 buf.append("&#");
97 buf.append((int)c);
98 buf.append(";");
99 }
100 else buf.append(c);
101 }
102 }
103 return buf.toString();
104 }
105}

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