Class UnicodeEscaper

Direct Known Subclasses:
JavaUnicodeEscaper

public class UnicodeEscaper extends CodePointTranslator
Translates codepoints to their Unicode escaped value.
Since:
Java 17+
Author:
Kimi Liu
  • Constructor Details

    • UnicodeEscaper

      public UnicodeEscaper()

      Constructs a UnicodeEscaper for all characters.

    • UnicodeEscaper

      protected UnicodeEscaper(int below, int above, boolean between)

      Constructs a UnicodeEscaper for the specified range. This is the underlying method for the other constructors/builders. The below and above boundaries are inclusive when between is true and exclusive when it is false.

      Parameters:
      below - int value representing the lowest codepoint boundary
      above - int value representing the highest codepoint boundary
      between - whether to escape between the boundaries or outside them
  • Method Details

    • below

      public static UnicodeEscaper below(int codepoint)

      Constructs a UnicodeEscaper below the specified value (exclusive).

      Parameters:
      codepoint - below which to escape
      Returns:
      the newly created UnicodeEscaper instance
    • above

      public static UnicodeEscaper above(int codepoint)

      Constructs a UnicodeEscaper above the specified value (exclusive).

      Parameters:
      codepoint - above which to escape
      Returns:
      the newly created UnicodeEscaper instance
    • outsideOf

      public static UnicodeEscaper outsideOf(int codepointLow, int codepointHigh)

      Constructs a UnicodeEscaper outside of the specified values (exclusive).

      Parameters:
      codepointLow - below which to escape
      codepointHigh - above which to escape
      Returns:
      the newly created UnicodeEscaper instance
    • between

      public static UnicodeEscaper between(int codepointLow, int codepointHigh)

      Constructs a UnicodeEscaper between the specified values (inclusive).

      Parameters:
      codepointLow - above which to escape
      codepointHigh - below which to escape
      Returns:
      the newly created UnicodeEscaper instance
    • translate

      public boolean translate(int codepoint, Writer out) throws IOException
      Specified by:
      translate in class CodePointTranslator
      Throws:
      IOException
    • toUtf16Escape

      protected String toUtf16Escape(int codepoint)
      Converts the given codepoint to a hex string of the form "\\uXXXX".
      Parameters:
      codepoint - a Unicode code point
      Returns:
      the hex string for the given codepoint