StringUtil { @Deprecated public static void appendXmlEscaped(StringBuilder buf, String src, boolean supportUTF8) { char c; int i = 0; while (i < src.length()) { c = src.charAt(i++); if (c > '~') { if (!supportUTF8) { int codepoint = c; if (Character.isHighSurrogate(c)) { char low = src.charAt(i++); codepoint = Character.toCodePoint(c, low); } buf.append("&#x").append(Integer.toHexString(codepoint)).append(';'); } else { buf.append(c); } } else if (c == '&') { buf.append("&amp;"); } else if (c == '"') { buf.append("&quot;"); } else if (c == '<') { buf.append("&lt;"); } else if (c == '>') { buf.append("&gt;"); } else { buf.append(c); } } } private  StringUtil(); static int lineNumberAt(CharSequence charSeq, int offsetInclusive); static int columnNumberAt(CharSequence charSeq, final int offsetInclusive); static String percentageString(double val, int numDecimals); @Deprecated static boolean startsWithAny(String text, String... prefixes); static boolean isAnyOf(String text, String... tests); static String withoutPrefixes(String text, String... prefixes); @Deprecated static boolean isNotEmpty(String value); @Deprecated static boolean isEmpty(String value); @Deprecated static boolean isMissing(String value); @Deprecated static boolean areSemanticEquals(String a, String b); @Deprecated static String replaceString(final String original, final String oldString, final String newString); @Deprecated static void appendXmlEscaped(StringBuilder buf, String src, boolean supportUTF8); static String removedInvalidXml10Characters(String text); static String escapeWhitespace(Object o); @Deprecated static String replaceString(final String original, char oldChar, final String newString); @Deprecated static String[] substringsOf(String source, char delimiter); @Deprecated static String[] substringsOf(String str, String separator); @Deprecated static void asStringOn(StringBuffer sb, Iterator<?> iter, String separator); @Deprecated static void asStringOn(StringBuilder sb, Object[] items, String separator); static int maxCommonLeadingWhitespaceForAll(String[] strings); static int lengthOfShortestIn(String[] strings); static String[] trimStartOn(String[] strings, int trimDepth); @Deprecated static String lpad(String s, int length); static boolean isSame(String s1, String s2, boolean trim, boolean ignoreCase,
                                 boolean standardizeWhitespace); static String asString(Object[] items, String separator); static String[] getEmptyStrings(); static String toCamelCase(String name); static String toCamelCase(String name, boolean forceLowerCase); static String escapeJava(String str);  }
@Test public void testUTF8NotSupported() { StringBuilder sb = new StringBuilder(); String test = "é"; StringUtil.appendXmlEscaped(sb, test, false); assertEquals("&#xe9;", sb.toString()); }
@Test public void testUTF8NotSupportedSurrogates() { StringBuilder sb = new StringBuilder(); String test = new String(new char[] {0xd834, 0xdd1e}); StringUtil.appendXmlEscaped(sb, test, false); assertEquals("&#x1d11e;", sb.toString()); }
@Test public void testUTF8Supported() { StringBuilder sb = new StringBuilder(); String test = "é"; StringUtil.appendXmlEscaped(sb, test, true); assertEquals("é", sb.toString()); }