@Test public void testUnescapeXml() { assert (escapedStrings.length == unescapedStrings.length); for (int i = 0; i < escapedStrings.length; i++) { if (escapedStrings[i] == null) { assert (Strings.unescapeXml(escapedStrings[i]) == null); } else { assert (Strings.unescapeXml(escapedStrings[i]).compareTo(unescapedStrings[i]) == 0); } } }
public static String unescapeXml(String s) { initializeEscapeMap(); if (!initializeUnescapePattern()) { return s; } if (s == null || s.length() == 0) { return s; } if (s.contains("\\u")) { StringBuffer sUnescaped = new StringBuffer(); Matcher m = unescapePattern.matcher(s); while (m.find() == true) { String slashes = m.group(1); String digits = m.group(3); int escapeCode; try { escapeCode = Integer.parseInt(digits, 16); } catch (NumberFormatException nfe) { System.err.println("Impossible error: escape sequence '" + digits + "' is not a valid hex number! " + "Exception: " + nfe.toString()); return s; } if (slashes != null && slashes.length() % 2 == 0 && isInvalidXMLCharacter(escapeCode)) { Character escapedSequence = Character.valueOf((char) escapeCode); m.appendReplacement(sUnescaped, slashes + slashes + escapedSequence.toString()); } } m.appendTail(sUnescaped); s = sUnescaped.toString(); } return StringEscapeUtils.unescapeXml(s); }
Strings { public static String unescapeXml(String s) { initializeEscapeMap(); if (!initializeUnescapePattern()) { return s; } if (s == null || s.length() == 0) { return s; } if (s.contains("\\u")) { StringBuffer sUnescaped = new StringBuffer(); Matcher m = unescapePattern.matcher(s); while (m.find() == true) { String slashes = m.group(1); String digits = m.group(3); int escapeCode; try { escapeCode = Integer.parseInt(digits, 16); } catch (NumberFormatException nfe) { System.err.println("Impossible error: escape sequence '" + digits + "' is not a valid hex number! " + "Exception: " + nfe.toString()); return s; } if (slashes != null && slashes.length() % 2 == 0 && isInvalidXMLCharacter(escapeCode)) { Character escapedSequence = Character.valueOf((char) escapeCode); m.appendReplacement(sUnescaped, slashes + slashes + escapedSequence.toString()); } } m.appendTail(sUnescaped); s = sUnescaped.toString(); } return StringEscapeUtils.unescapeXml(s); } }
Strings { public static String unescapeXml(String s) { initializeEscapeMap(); if (!initializeUnescapePattern()) { return s; } if (s == null || s.length() == 0) { return s; } if (s.contains("\\u")) { StringBuffer sUnescaped = new StringBuffer(); Matcher m = unescapePattern.matcher(s); while (m.find() == true) { String slashes = m.group(1); String digits = m.group(3); int escapeCode; try { escapeCode = Integer.parseInt(digits, 16); } catch (NumberFormatException nfe) { System.err.println("Impossible error: escape sequence '" + digits + "' is not a valid hex number! " + "Exception: " + nfe.toString()); return s; } if (slashes != null && slashes.length() % 2 == 0 && isInvalidXMLCharacter(escapeCode)) { Character escapedSequence = Character.valueOf((char) escapeCode); m.appendReplacement(sUnescaped, slashes + slashes + escapedSequence.toString()); } } m.appendTail(sUnescaped); s = sUnescaped.toString(); } return StringEscapeUtils.unescapeXml(s); }  }
Strings { public static String unescapeXml(String s) { initializeEscapeMap(); if (!initializeUnescapePattern()) { return s; } if (s == null || s.length() == 0) { return s; } if (s.contains("\\u")) { StringBuffer sUnescaped = new StringBuffer(); Matcher m = unescapePattern.matcher(s); while (m.find() == true) { String slashes = m.group(1); String digits = m.group(3); int escapeCode; try { escapeCode = Integer.parseInt(digits, 16); } catch (NumberFormatException nfe) { System.err.println("Impossible error: escape sequence '" + digits + "' is not a valid hex number! " + "Exception: " + nfe.toString()); return s; } if (slashes != null && slashes.length() % 2 == 0 && isInvalidXMLCharacter(escapeCode)) { Character escapedSequence = Character.valueOf((char) escapeCode); m.appendReplacement(sUnescaped, slashes + slashes + escapedSequence.toString()); } } m.appendTail(sUnescaped); s = sUnescaped.toString(); } return StringEscapeUtils.unescapeXml(s); }  @Deprecated static String replace(String source, String find, String repl); @Deprecated static String toString(final Object[] a); static String trimComma(String s); static void initializeEscapeMap(); static String escapeXml(String s); static boolean initializeUnescapePattern(); static String unescapeXml(String s); static String escapeLFCRBackSlash(String s); }
Strings { public static String unescapeXml(String s) { initializeEscapeMap(); if (!initializeUnescapePattern()) { return s; } if (s == null || s.length() == 0) { return s; } if (s.contains("\\u")) { StringBuffer sUnescaped = new StringBuffer(); Matcher m = unescapePattern.matcher(s); while (m.find() == true) { String slashes = m.group(1); String digits = m.group(3); int escapeCode; try { escapeCode = Integer.parseInt(digits, 16); } catch (NumberFormatException nfe) { System.err.println("Impossible error: escape sequence '" + digits + "' is not a valid hex number! " + "Exception: " + nfe.toString()); return s; } if (slashes != null && slashes.length() % 2 == 0 && isInvalidXMLCharacter(escapeCode)) { Character escapedSequence = Character.valueOf((char) escapeCode); m.appendReplacement(sUnescaped, slashes + slashes + escapedSequence.toString()); } } m.appendTail(sUnescaped); s = sUnescaped.toString(); } return StringEscapeUtils.unescapeXml(s); }  @Deprecated static String replace(String source, String find, String repl); @Deprecated static String toString(final Object[] a); static String trimComma(String s); static void initializeEscapeMap(); static String escapeXml(String s); static boolean initializeUnescapePattern(); static String unescapeXml(String s); static String escapeLFCRBackSlash(String s);  }