MCPcopy Create free account
hub / github.com/VolmitSoftware/Adapt / escape

Method escape

src/main/java/com/volmit/adapt/util/XML.java:91–116  ·  view source on GitHub ↗

Replace special characters with XML escapes: & (ampersand) is replaced by & < (less than) is replaced by < > (greater than) is replaced by > " (double quote) is replaced by " @par

(String string)

Source from the content-addressed store, hash-verified

89 * @return The escaped string.
90 */
91 public static String escape(String string) {
92 StringBuilder sb = new StringBuilder(string.length());
93 for (int i = 0, length = string.length(); i < length; i++) {
94 char c = string.charAt(i);
95 switch (c) {
96 case '&':
97 sb.append("&amp;");
98 break;
99 case '<':
100 sb.append("&lt;");
101 break;
102 case '>':
103 sb.append("&gt;");
104 break;
105 case '"':
106 sb.append("&quot;");
107 break;
108 case '\'':
109 sb.append("&apos;");
110 break;
111 default:
112 sb.append(c);
113 }
114 }
115 return sb.toString();
116 }
117
118 /**
119 * Throw an exception if the string contains whitespace. Whitespace is not

Callers 2

toStringMethod · 0.95
toStringMethod · 0.95

Calls 3

lengthMethod · 0.45
appendMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected