/** * Get the character(s) represented by the named entity * * @param name entity (e.g. "lt" or "amp") * @return the string value of the character(s) represented by this entity, or "" if not defined */ public static String getByName(String name) { String val = multipoints.get(name); if (val != null) return val; int codepoint = extended.codepointForName(name); if (codepoint != empty) return new String(new int[]{codepoint}, 0, 1); return emptyName; }
@Override public OutputSettings clone() { OutputSettings clone; try { clone = (OutputSettings) super.clone(); } catch (CloneNotSupportedException e) { throw new RuntimeException(e); } clone.charset(charset.name()); // new charset and charset encoder clone.escapeMode = Entities.EscapeMode.valueOf(escapeMode.name()); // indentAmount, prettyPrint are primitives so object.clone() will handle return clone; } }
private static void appendEncoded(Appendable accum, EscapeMode escapeMode, int codePoint) throws IOException { final String name = escapeMode.nameForCodepoint(codePoint); if (name != emptyName) // ok for identity check accum.append('&').append(name).append(';'); else accum.append("&#x").append(Integer.toHexString(codePoint)).append(';'); }
public static int codepointsForName(final String name, final int[] codepoints) { String val = multipoints.get(name); if (val != null) { codepoints[0] = val.codePointAt(0); codepoints[1] = val.codePointAt(1); return 2; } int codepoint = extended.codepointForName(name); if (codepoint != empty) { codepoints[0] = codepoint; return 1; } return 0; }
/** * Get the Character value of the named entity * * @param name named entity (e.g. "lt" or "amp") * @return the Character value of the named entity (e.g. '{@literal <}' or '{@literal &}') * @deprecated does not support characters outside the BMP or multiple character names */ public static Character getCharacterByName(String name) { return (char) extended.codepointForName(name); }
/** * Check if the input is a known named entity * * @param name the possible entity name (e.g. "lt" or "amp") * @return true if a known named entity */ public static boolean isNamedEntity(final String name) { return extended.codepointForName(name) != empty; }
/** * Check if the input is a known named entity in the base entity set. * * @param name the possible entity name (e.g. "lt" or "amp") * @return true if a known named entity in the base set * @see #isNamedEntity(String) */ public static boolean isBaseNamedEntity(final String name) { return base.codepointForName(name) != empty; }