MCPcopy Create free account
hub / github.com/apache/tomcat / escape

Method escape

java/org/apache/tomcat/util/json/JSONFilter.java:32–48  ·  view source on GitHub ↗

Escape the given char. @param c the char @return a char array with the escaped sequence

(char c)

Source from the content-addressed store, hash-verified

30 * @return a char array with the escaped sequence
31 */
32 public static char[] escape(char c) {
33 if (c < 0x20 || c == 0x22 || c == 0x5c || Character.isHighSurrogate(c) || Character.isLowSurrogate(c)) {
34 char popular = getPopularChar(c);
35 if (popular > 0) {
36 return new char[] { '\\', popular };
37 } else {
38 StringBuilder escaped = new StringBuilder(6);
39 escaped.append("\\u");
40 escaped.append(String.format("%04X", Integer.valueOf(c)));
41 return escaped.toString().toCharArray();
42 }
43 } else {
44 char[] result = new char[1];
45 result[0] = c;
46 return result;
47 }
48 }
49
50 /**
51 * Escape the given string.

Callers 8

renderJSONMethod · 0.95
testStringEscapingMethod · 0.95
reportMethod · 0.95
escapeJsonStringMethod · 0.95
writeVMStateMethod · 0.95
writeConnectorStateMethod · 0.95
writeContextMethod · 0.95
writeWrapperMethod · 0.95

Calls 9

getPopularCharMethod · 0.95
toCharArrayMethod · 0.80
lengthMethod · 0.80
charAtMethod · 0.80
subSequenceMethod · 0.80
formatMethod · 0.65
toStringMethod · 0.65
appendMethod · 0.45
valueOfMethod · 0.45

Tested by 1

testStringEscapingMethod · 0.76