/** * Append escaped version of character to the end of the StringBuilder */ private static void transform(final StringBuilder sb, final int codePoint, final TransformPolicy policy) { if (!validXml(codePoint)) { sb.append(policy.handle((char)codePoint)); } else { String charRef = getEntityRef(codePoint); if (charRef != null) { sb.append("&").append(charRef).append(";"); } else if ((codePoint >= ' ' && codePoint <= _lastPrintable && codePoint != 0xF7) || codePoint == '\n' || codePoint == '\r' || codePoint == '\t') { // If the character is not printable, print as character reference. // Non printables are below ASCII space but not tab or line // terminator, ASCII delete, or above a certain Unicode threshold. sb.append(Character.toChars(codePoint)); } else { sb.append("&#").append(codePoint).append(";"); } } }
/** * Append escaped version of character to the end of the StringBuilder */ private static void transform(final StringBuilder sb, final char ch, final TransformPolicy policy) { if (!validXml(ch)) { sb.append(policy.handle(ch)); } else { String charRef = getEntityRef(ch); if (charRef != null) { sb.append("&").append(charRef).append(";"); } else if ((ch >= ' ' && ch <= _lastPrintable && ch != 0xF7) || ch == '\n' || ch == '\r' || ch == '\t') { // If the character is not printable, print as character reference. // Non printables are below ASCII space but not tab or line // terminator, ASCII delete, or above a certain Unicode threshold. sb.append(ch); } else { sb.append("&#").append(Integer.toString(ch)).append(";"); } } }