/** * Decode a string containing references. * Change all numeric character reference and character entity references * to unicode characters. * @param string The string to translate. */ public static String decode (String string) { return decode(string, null); }
/** * Numeric character reference and character entity reference to unicode codec. * Translate the <code>System.in</code> input into an encoded or decoded * stream and send the results to <code>System.out</code>. * @param args If arg[0] is <code>-encode</code> perform an encoding on * <code>System.in</code>, otherwise perform a decoding. */ public static void main (String[] args) { boolean encode; if (0 < args.length && args[0].equalsIgnoreCase ("-encode")) encode = true; else encode = false; if (encode) encode (System.in, System.out); else decode (System.in, System.out); } }
/** * Look up a reference by character. * Use a combination of direct table lookup and binary search to find * the reference corresponding to the character. * @param character The character to be looked up. * @return The entity reference for that character or <code>null</code>. */ public static CharacterReference lookup (char character) { int index; CharacterReference ret; if (character < BREAKPOINT) ret = mCharacterList[character]; else { index = lookup (mCharacterList, character, BREAKPOINT, mCharacterList.length - 1); if (index < mCharacterList.length) { ret = mCharacterList[index]; if (character != ret.getCharacter ()) ret = null; } else ret = null; } return (ret); }
/** * Convert a character to a numeric character reference. * Convert a unicode character to a numeric character reference of * the form &#xxxx;. * @param character The character to convert. * @return The converted character. * @deprecated Use {@link #encode(int) encode}. */ public static String convertToString (int character) { return (encode (character)); }
/** * Look up a reference by character. * Use a combination of direct table lookup and binary search to find * the reference corresponding to the character. * @param character The character to be looked up. * @return The entity reference for that character or <code>null</code>. */ public static CharacterReference lookup (char character) { int index; CharacterReference ret; if (character < BREAKPOINT) ret = mCharacterList[character]; else { index = lookup (mCharacterList, character, BREAKPOINT, mCharacterList.length - 1); if (index < mCharacterList.length) { ret = mCharacterList[index]; if (character != ret.getCharacter ()) ret = null; } else ret = null; } return (ret); }
s = Translate.encode (ret.toString ()); children = null != tag.getChildren (); ret = new StringBuilder (s.length () + 13 + (children ? 16 : 0));
/** * Decodes entities in a string if it isn't null.<p> * * @param value the string for which to decode entities * * @return the string with the decoded entities */ protected static String decodeEntities(String value) { if (value != null) { value = Translate.decode(value); } return value; }
/** * Numeric character reference and character entity reference to unicode codec. * Translate the <code>System.in</code> input into an encoded or decoded * stream and send the results to <code>System.out</code>. * @param args If arg[0] is <code>-encode</code> perform an encoding on * <code>System.in</code>, otherwise perform a decoding. */ public static void main (String[] args) { boolean encode; if (0 < args.length && args[0].equalsIgnoreCase ("-encode")) encode = true; else encode = false; if (encode) encode (System.in, System.out); else decode (System.in, System.out); } }
candidate = lookup (c); if (null != candidate)
/** * Decode the characters in a string buffer containing references. * Change all numeric character reference and character entity references * to unicode characters. * @param buffer The StringBuffer containing references. * @return The decoded string. */ public static String decode (StringBuffer buffer) { return decode (buffer.toString()); }
candidate = lookup (c); if (null != candidate)
/** * Decode the characters in a string buffer containing references. * Change all numeric character reference and character entity references * to unicode characters. * @param buffer The StringBuilder containing references. * @return The decoded string. */ public static String decode (StringBuilder buffer) { return decode (buffer.toString()); }
/** * Look up a reference by kernel. * Use a binary search on the ordered list of known references. * <em>This is not very efficient, use {@link org.htmlparser.util.Translate#lookup(org.htmlparser.util.CharacterReference) lookup(CharacterReference)} * instead.</em> * @param kernel The string to lookup, i.e. "amp". * @param start The starting point in the string of the kernel. * @param end The ending point in the string of the kernel. * This should be the index of the semicolon if it exists, or failing that, * at least an index past the last character of the kernel. * @return The reference that matches the given string, or <code>null</code> * if it wasn't found. */ public static CharacterReference lookup (String kernel, int start, int end) { CharacterReferenceEx probe; probe = new CharacterReferenceEx (); probe.setKernel (kernel); probe.setStart (start); probe.setEnd (end); return (lookup (probe)); }
/** * Convert a reference to a unicode character. * Convert a single numeric character reference or character entity reference * to a unicode character. * @param string The string to convert. Of the form &xxxx; or &#xxxx; with * or without the leading ampersand or trailing semi-colon. * @return The converted character or '