/** * <p>Constructs a <code>NumericEntityEscaper</code> below the specified value (exclusive). </p> * * @param codepoint below which to escape * @return the newly created {@code NumericEntityEscaper} instance */ public static NumericEntityEscaper below(final int codepoint) { return outsideOf(codepoint, Integer.MAX_VALUE); }
/** * <p>Constructs a <code>NumericEntityEscaper</code> outside of the specified values (exclusive). </p> * * @param codepointLow below which to escape * @param codepointHigh above which to escape * @return the newly created {@code NumericEntityEscaper} instance */ public static NumericEntityEscaper outsideOf(final int codepointLow, final int codepointHigh) { return new NumericEntityEscaper(codepointLow, codepointHigh, false); }
/** * <p>Constructs a <code>UnicodeEscaper</code> outside of the specified values (exclusive). </p> * * @param codepointLow below which to escape * @param codepointHigh above which to escape * @return the newly created {@code UnicodeEscaper} instance */ public static UnicodeEscaper outsideOf(final int codepointLow, final int codepointHigh) { return new UnicodeEscaper(codepointLow, codepointHigh, false); }
/** * <p>Unescapes any Java literals found in the {@code String}. * For example, it will turn a sequence of {@code '\'} and * {@code 'n'} into a newline character, unless the {@code '\'} * is preceded by another {@code '\'}.</p> * * @param input the {@code String} to unescape, may be null * @return a new unescaped {@code String}, {@code null} if null string input */ public static final String unescapeJava(final String input) { return UNESCAPE_JAVA.translate(input); }
/** * <p> * Constructs a <code>JavaUnicodeEscaper</code> above the specified value (exclusive). * </p> * * @param codepoint * above which to escape * @return the newly created {@code UnicodeEscaper} instance */ public static JavaUnicodeEscaper above(final int codepoint) { return outsideOf(0, codepoint); }
/** * <p>Constructs a <code>UnicodeEscaper</code> above the specified value (exclusive). </p> * * @param codepoint above which to escape * @return the newly created {@code UnicodeEscaper} instance */ public static UnicodeEscaper above(final int codepoint) { return outsideOf(0, codepoint); }
/** * <p> * Constructs a <code>JavaUnicodeEscaper</code> between the specified values (inclusive). * </p> * * @param codepointLow * above which to escape * @param codepointHigh * below which to escape * @return the newly created {@code UnicodeEscaper} instance */ public static JavaUnicodeEscaper between(final int codepointLow, final int codepointHigh) { return new JavaUnicodeEscaper(codepointLow, codepointHigh, true); }
/** * Converts the given codepoint to a hex string of the form {@code "\\uXXXX"} * * @param codepoint * a Unicode code point * @return the hex string for the given codepoint * * @since 3.2 */ protected String toUtf16Escape(final int codepoint) { return "\\u" + hex(codepoint); } }
/** * Converts the given codepoint to a hex string of the form {@code "\\uXXXX\\uXXXX"} * * @param codepoint * a Unicode code point * @return the hex string for the given codepoint */ @Override protected String toUtf16Escape(final int codepoint) { final char[] surrogatePair = Character.toChars(codepoint); return "\\u" + hex(surrogatePair[0]) + "\\u" + hex(surrogatePair[1]); }
/** * <p>Escapes the characters in a {@code String} using HTML entities.</p> * <p>Supports only the HTML 3.0 entities. </p> * * @param input the {@code String} to escape, may be null * @return a new escaped {@code String}, {@code null} if null string input * * @since 3.0 */ public static final String escapeHtml3(final String input) { return ESCAPE_HTML3.translate(input); }
/** * <p>Constructs a <code>NumericEntityEscaper</code> between the specified values (inclusive). </p> * * @param codepointLow above which to escape * @param codepointHigh below which to escape * @return the newly created {@code NumericEntityEscaper} instance */ public static NumericEntityEscaper between(final int codepointLow, final int codepointHigh) { return new NumericEntityEscaper(codepointLow, codepointHigh, true); }
/** * <p> * Constructs a <code>JavaUnicodeEscaper</code> below the specified value (exclusive). * </p> * * @param codepoint * below which to escape * @return the newly created {@code UnicodeEscaper} instance */ public static JavaUnicodeEscaper below(final int codepoint) { return outsideOf(codepoint, Integer.MAX_VALUE); }
/** * <p>Constructs a <code>NumericEntityEscaper</code> above the specified value (exclusive). </p> * * @param codepoint above which to escape * @return the newly created {@code NumericEntityEscaper} instance */ public static NumericEntityEscaper above(final int codepoint) { return outsideOf(0, codepoint); }
/** * <p>Constructs a <code>UnicodeEscaper</code> between the specified values (inclusive). </p> * * @param codepointLow above which to escape * @param codepointHigh below which to escape * @return the newly created {@code UnicodeEscaper} instance */ public static UnicodeEscaper between(final int codepointLow, final int codepointHigh) { return new UnicodeEscaper(codepointLow, codepointHigh, true); }
/** * <p>Constructs a <code>UnicodeEscaper</code> below the specified value (exclusive). </p> * * @param codepoint below which to escape * @return the newly created {@code UnicodeEscaper} instance */ public static UnicodeEscaper below(final int codepoint) { return outsideOf(codepoint, Integer.MAX_VALUE); }
/** * <p> * Constructs a <code>JavaUnicodeEscaper</code> outside of the specified values (exclusive). * </p> * * @param codepointLow * below which to escape * @param codepointHigh * above which to escape * @return the newly created {@code UnicodeEscaper} instance */ public static JavaUnicodeEscaper outsideOf(final int codepointLow, final int codepointHigh) { return new JavaUnicodeEscaper(codepointLow, codepointHigh, false); }
/** * <p>Unescapes a string containing entity escapes to a string * containing the actual Unicode characters corresponding to the * escapes. Supports only HTML 3.0 entities.</p> * * @param input the {@code String} to unescape, may be null * @return a new unescaped {@code String}, {@code null} if null string input * * @since 3.0 */ public static final String unescapeHtml3(final String input) { return UNESCAPE_HTML3.translate(input); }
/** * <p>Unescapes any Json literals found in the {@code String}.</p> * * <p>For example, it will turn a sequence of {@code '\'} and {@code 'n'} * into a newline character, unless the {@code '\'} is preceded by another * {@code '\'}.</p> * * @see #unescapeJava(String) * @param input the {@code String} to unescape, may be null * @return A new unescaped {@code String}, {@code null} if null string input * * @since 3.2 */ public static final String unescapeJson(final String input) { return UNESCAPE_JSON.translate(input); }
/** * The first translator to consume codepoints from the input is the 'winner'. * Execution stops with the number of consumed codepoints being returned. * {@inheritDoc} */ @Override public int translate(final CharSequence input, final int index, final Writer out) throws IOException { for (final CharSequenceTranslator translator : translators) { final int consumed = translator.translate(input, index, out); if(consumed != 0) { return consumed; } } return 0; }
/** * <p>Unescapes any EcmaScript literals found in the {@code String}.</p> * * <p>For example, it will turn a sequence of {@code '\'} and {@code 'n'} * into a newline character, unless the {@code '\'} is preceded by another * {@code '\'}.</p> * * @see #unescapeJava(String) * @param input the {@code String} to unescape, may be null * @return A new unescaped {@code String}, {@code null} if null string input * * @since 3.0 */ public static final String unescapeEcmaScript(final String input) { return UNESCAPE_ECMASCRIPT.translate(input); }