Class IonTextUtils

java.lang.Object
com.amazon.ion.util.IonTextUtils

public class IonTextUtils extends Object
Utility methods for working with Ion's text-oriented data types.
  • Constructor Details

    • IonTextUtils

      public IonTextUtils()
  • Method Details

    • isWhitespace

      public static boolean isWhitespace(int codePoint)
      Ion whitespace is defined as one of the characters space, tab, newline, and carriage-return. This matches the definition of whitespace used by JSON.
      Parameters:
      codePoint - the character to test.
      Returns:
      true if c is one of the four legal Ion whitespace characters.
      See Also:
    • isAllWhitespace

      public static boolean isAllWhitespace(CharSequence charSequence)
      Ion whitespace is defined as one of the characters space, tab, newline, and carriage-return. This matches the definition of whitespace used by JSON.
      Parameters:
      charSequence - the CharSequence to test.
      Returns:
      true if charSequence consists entirely of the four legal Ion whitespace characters.
      See Also:
    • isNumericStop

      public static boolean isNumericStop(int codePoint)
      Determines whether a given code point is one of the valid Ion numeric terminators.

      The slash character '/' is not itself a valid terminator, but if the next character is '/' or '*' then the number is followed by a comment. Since this method cannot perform the look-ahead necessary to make that determination, it returns false for the slash.

      Parameters:
      codePoint - the Unicode scalar to test.
      Returns:
      true when the scalar can legally follow an Ion number. Returns false for the slash character '/'.
    • isDigit

      public static boolean isDigit(int codePoint, int radix)
    • isIdentifierStart

      public static boolean isIdentifierStart(int codePoint)
    • isIdentifierPart

      public static boolean isIdentifierPart(int codePoint)
    • isOperatorPart

      public static boolean isOperatorPart(int codePoint)
    • symbolVariant

      public static IonTextUtils.SymbolVariant symbolVariant(CharSequence symbol)
      Determines whether the text of a symbol represents an identifier, an operator, or a symbol that always requires (single) quotes.
      Parameters:
      symbol - must be a non-empty string.
      Returns:
      the variant of the symbol.
      Throws:
      NullPointerException - if symbol is null.
    • printStringCodePoint

      public static void printStringCodePoint(Appendable out, int codePoint) throws IOException
      Prints a single Unicode code point for use in an ASCII-safe Ion string.
      Parameters:
      out - the stream to receive the data.
      codePoint - a Unicode code point.
      Throws:
      IOException
    • printSymbolCodePoint

      public static void printSymbolCodePoint(Appendable out, int codePoint) throws IOException
      Prints a single Unicode code point for use in an ASCII-safe Ion symbol.
      Parameters:
      out - the stream to receive the data.
      codePoint - a Unicode code point.
      Throws:
      IOException
    • printJsonCodePoint

      public static void printJsonCodePoint(Appendable out, int codePoint) throws IOException
      Prints a single Unicode code point for use in an ASCII-safe JSON string.
      Parameters:
      out - the stream to receive the data.
      codePoint - a Unicode code point.
      Throws:
      IOException
    • printString

      public static void printString(Appendable out, CharSequence text) throws IOException
      Prints characters as an ASCII-encoded Ion string, including surrounding double-quotes. If the text is null, this prints null.string.
      Parameters:
      out - the stream to receive the data.
      text - the text to print; may be null.
      Throws:
      IOException - if the Appendable throws an exception.
      IllegalArgumentException - if the text contains invalid UTF-16 surrogates.
    • printJsonString

      public static void printJsonString(Appendable out, CharSequence text) throws IOException
      Prints characters as an ASCII-encoded JSON string, including surrounding double-quotes. If the text is null, this prints null.
      Parameters:
      out - the stream to receive the JSON data.
      text - the text to print; may be null.
      Throws:
      IOException - if the Appendable throws an exception.
      IllegalArgumentException - if the text contains invalid UTF-16 surrogates.
    • printString

      public static String printString(CharSequence text)
      Builds a String denoting an ASCII-encoded Ion string, including surrounding double-quotes. If the text is null, this returns "null.string".
      Parameters:
      text - the text to print; may be null.
      Throws:
      IllegalArgumentException - if the text contains invalid UTF-16 surrogates.
    • printLongString

      public static String printLongString(CharSequence text)
      Builds a String denoting an ASCII-encoded Ion "long string", including surrounding triple-quotes. If the text is null, this returns "null.string".
      Parameters:
      text - the text to print; may be null.
      Throws:
      IllegalArgumentException - if the text contains invalid UTF-16 surrogates.
    • printLongString

      public static void printLongString(Appendable out, CharSequence text) throws IOException
      Prints characters as an ASCII-encoded Ion "long string", including surrounding triple-quotes. If the text is null, this prints null.string.
      Parameters:
      out - the stream to receive the data.
      text - the text to print; may be null.
      Throws:
      IOException - if the Appendable throws an exception.
      IllegalArgumentException - if the text contains invalid UTF-16 surrogates.
    • printCodePointAsString

      public static String printCodePointAsString(int codePoint)
      Builds a String denoting an ASCII-encoded Ion string, with double-quotes surrounding a single Unicode code point.
      Parameters:
      codePoint - a Unicode code point.
    • printSymbol

      public static void printSymbol(Appendable out, CharSequence text) throws IOException
      Prints the text as an Ion symbol, including surrounding single-quotes if they are necessary. Operator symbols such as '+' are quoted. If the text is null, this prints null.symbol.
      Parameters:
      out - the stream to receive the Ion data.
      text - the symbol text; may be null.
      Throws:
      IOException - if the Appendable throws an exception.
      See Also:
    • printSymbol

      public static String printSymbol(CharSequence text)
      Prints the text as an Ion symbol, including surrounding single-quotes if they are necessary. Operator symbols such as '+' are quoted. If the text is null, this returns "null.symbol".
      Parameters:
      text - the symbol text; may be null.
      Returns:
      a string containing the resulting Ion data.
      See Also:
    • printSymbol

      public static String printSymbol(SymbolToken token)
      Parameters:
      token - the symbolToken to be printed.
      Returns:
      a string representing the symboltoken.
    • printQuotedSymbol

      public static void printQuotedSymbol(Appendable out, CharSequence text) throws IOException
      Prints text as a single-quoted Ion symbol. If the text is null, this prints null.symbol.
      Parameters:
      out - the stream to receive the data.
      text - the symbol text; may be null.
      Throws:
      IOException - if the Appendable throws an exception.
      IllegalArgumentException - if the text contains invalid UTF-16 surrogates.
    • printQuotedSymbol

      public static String printQuotedSymbol(CharSequence text)
      Builds a String containing a single-quoted Ion symbol. If the text is null, this returns "null.symbol".
      Parameters:
      text - the symbol text; may be null.
      Throws:
      IllegalArgumentException - if the text contains invalid UTF-16 surrogates.
    • printDecimal

      public static void printDecimal(Appendable out, BigDecimal decimal) throws IOException
      Throws:
      IOException
    • printDecimal

      public static String printDecimal(BigDecimal decimal)
    • printFloat

      public static void printFloat(Appendable out, double value) throws IOException
      Throws:
      IOException
    • printFloat

      public static String printFloat(double value)
    • printFloat

      public static void printFloat(Appendable out, Double value) throws IOException
      Throws:
      IOException
    • printFloat

      public static String printFloat(Double value)
    • printBlob

      public static void printBlob(Appendable out, byte[] value) throws IOException
      Throws:
      IOException
    • printBlob

      public static String printBlob(byte[] value)
    • printClob

      public static void printClob(Appendable out, byte[] value) throws IOException
      Throws:
      IOException
    • printClob

      public static String printClob(byte[] value)