StringUtil { public static void simpleEscapeIRI(String str, Appendable appendable, boolean escapeUnicode) throws IOException { int strlen = str.length(); for (int i = 0; i < strlen; i++) { char c = str.charAt(i); if (ASCIIUtil.isLetterOrNumber(c)) { appendable.append(c); } else if (c < 0xA0) { if (Arrays.binarySearch(IRI_DONT_ESCAPE, c) > -1) { appendable.append(c); } else { appendable.append('%').append(hex(c)); } } else { if (escapeUnicode) { if (c <= 0xFF) { appendable.append("\\u00").append(hex(c)); } else if (c <= 0x0FFF) { appendable.append("\\u0").append(hex(c)); } else { if (Character.isSurrogate(c) && (i < strlen - 1)) { int code = str.codePointAt(i); i++; appendable.append("\\U000").append(hex(code)); } else { appendable.append("\\u").append(hex(c)); } } } else { appendable.append(c); } } } }  static String gsub(String olds, String news, String text); static void simpleEscapeIRI(String str, Appendable appendable, boolean escapeUnicode); static String getAllAfter(String string, char separatorChar); static String getAllBefore(String string, char separatorChar); static String encodeArray(String[] array); static String[] decodeArray(String encodedArray); static String deriveInitialText(String text); static boolean isGarbageText(String text); static void appendN(char c, int n, StringBuilder sb); static String trimDoubleQuotes(String text); static String concat(String... strings);  }
@Test public void testEncodeParsedASCII() throws IOException { String parsed = "http: StringBuffer out = new StringBuffer(); StringUtil.simpleEscapeIRI(str, out, true); String encoded = out.toString(); assertEquals("Encoded does not match parsed", encoded, parsed); }
@Test public void testEncodeParsed() throws IOException { String parsed = ParsedIRI.create(str).toString(); StringBuffer out = new StringBuffer(); StringUtil.simpleEscapeIRI(str, out, false); String encoded = out.toString(); assertEquals("Encoded does not match parsed", encoded, parsed); }