Class IonTextUtils


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

      Constructors 
      Constructor Description
      IonTextUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean isAllWhitespace​(java.lang.CharSequence charSequence)
      Ion whitespace is defined as one of the characters space, tab, newline, and carriage-return.
      static boolean isDigit​(int codePoint, int radix)  
      static boolean isIdentifierPart​(int codePoint)  
      static boolean isIdentifierStart​(int codePoint)  
      static boolean isNumericStop​(int codePoint)
      Determines whether a given code point is one of the valid Ion numeric terminators.
      static boolean isOperatorPart​(int codePoint)  
      static boolean isWhitespace​(int codePoint)
      Ion whitespace is defined as one of the characters space, tab, newline, and carriage-return.
      static java.lang.String printBlob​(byte[] value)  
      static void printBlob​(java.lang.Appendable out, byte[] value)  
      static java.lang.String printClob​(byte[] value)  
      static void printClob​(java.lang.Appendable out, byte[] value)  
      static java.lang.String printCodePointAsString​(int codePoint)
      Builds a String denoting an ASCII-encoded Ion string, with double-quotes surrounding a single Unicode code point.
      static void printDecimal​(java.lang.Appendable out, java.math.BigDecimal decimal)  
      static java.lang.String printDecimal​(java.math.BigDecimal decimal)  
      static java.lang.String printFloat​(double value)  
      static void printFloat​(java.lang.Appendable out, double value)  
      static void printFloat​(java.lang.Appendable out, java.lang.Double value)  
      static java.lang.String printFloat​(java.lang.Double value)  
      static void printJsonCodePoint​(java.lang.Appendable out, int codePoint)
      Prints a single Unicode code point for use in an ASCII-safe JSON string.
      static void printJsonString​(java.lang.Appendable out, java.lang.CharSequence text)
      Prints characters as an ASCII-encoded JSON string, including surrounding double-quotes.
      static void printLongString​(java.lang.Appendable out, java.lang.CharSequence text)
      Prints characters as an ASCII-encoded Ion "long string", including surrounding triple-quotes.
      static java.lang.String printLongString​(java.lang.CharSequence text)
      Builds a String denoting an ASCII-encoded Ion "long string", including surrounding triple-quotes.
      static void printQuotedSymbol​(java.lang.Appendable out, java.lang.CharSequence text)
      Prints text as a single-quoted Ion symbol.
      static java.lang.String printQuotedSymbol​(java.lang.CharSequence text)
      Builds a String containing a single-quoted Ion symbol.
      static void printString​(java.lang.Appendable out, java.lang.CharSequence text)
      Prints characters as an ASCII-encoded Ion string, including surrounding double-quotes.
      static java.lang.String printString​(java.lang.CharSequence text)
      Builds a String denoting an ASCII-encoded Ion string, including surrounding double-quotes.
      static void printStringCodePoint​(java.lang.Appendable out, int codePoint)
      Prints a single Unicode code point for use in an ASCII-safe Ion string.
      static java.lang.String printSymbol​(SymbolToken token)  
      static void printSymbol​(java.lang.Appendable out, java.lang.CharSequence text)
      Prints the text as an Ion symbol, including surrounding single-quotes if they are necessary.
      static java.lang.String printSymbol​(java.lang.CharSequence text)
      Prints the text as an Ion symbol, including surrounding single-quotes if they are necessary.
      static void printSymbolCodePoint​(java.lang.Appendable out, int codePoint)
      Prints a single Unicode code point for use in an ASCII-safe Ion symbol.
      static IonTextUtils.SymbolVariant symbolVariant​(java.lang.CharSequence symbol)
      Determines whether the text of a symbol represents an identifier, an operator, or a symbol that always requires (single) quotes.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • IonTextUtils

        public IonTextUtils()
    • Method Detail

      • 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:
        RFC 4627
      • isAllWhitespace

        public static boolean isAllWhitespace​(java.lang.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:
        isWhitespace(int), RFC 4627
      • 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​(java.lang.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:
        java.lang.NullPointerException - if symbol is null.
      • printStringCodePoint

        public static void printStringCodePoint​(java.lang.Appendable out,
                                                int codePoint)
                                         throws java.io.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:
        java.io.IOException
      • printSymbolCodePoint

        public static void printSymbolCodePoint​(java.lang.Appendable out,
                                                int codePoint)
                                         throws java.io.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:
        java.io.IOException
      • printJsonCodePoint

        public static void printJsonCodePoint​(java.lang.Appendable out,
                                              int codePoint)
                                       throws java.io.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:
        java.io.IOException
      • printString

        public static void printString​(java.lang.Appendable out,
                                       java.lang.CharSequence text)
                                throws java.io.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:
        java.io.IOException - if the Appendable throws an exception.
        java.lang.IllegalArgumentException - if the text contains invalid UTF-16 surrogates.
      • printJsonString

        public static void printJsonString​(java.lang.Appendable out,
                                           java.lang.CharSequence text)
                                    throws java.io.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:
        java.io.IOException - if the Appendable throws an exception.
        java.lang.IllegalArgumentException - if the text contains invalid UTF-16 surrogates.
      • printString

        public static java.lang.String printString​(java.lang.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:
        java.lang.IllegalArgumentException - if the text contains invalid UTF-16 surrogates.
      • printLongString

        public static java.lang.String printLongString​(java.lang.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:
        java.lang.IllegalArgumentException - if the text contains invalid UTF-16 surrogates.
      • printLongString

        public static void printLongString​(java.lang.Appendable out,
                                           java.lang.CharSequence text)
                                    throws java.io.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:
        java.io.IOException - if the Appendable throws an exception.
        java.lang.IllegalArgumentException - if the text contains invalid UTF-16 surrogates.
      • printCodePointAsString

        public static java.lang.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​(java.lang.Appendable out,
                                       java.lang.CharSequence text)
                                throws java.io.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:
        java.io.IOException - if the Appendable throws an exception.
        See Also:
        printSymbol(CharSequence)
      • printSymbol

        public static java.lang.String printSymbol​(java.lang.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(Appendable, CharSequence)
      • printSymbol

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

        public static void printQuotedSymbol​(java.lang.Appendable out,
                                             java.lang.CharSequence text)
                                      throws java.io.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:
        java.io.IOException - if the Appendable throws an exception.
        java.lang.IllegalArgumentException - if the text contains invalid UTF-16 surrogates.
      • printQuotedSymbol

        public static java.lang.String printQuotedSymbol​(java.lang.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:
        java.lang.IllegalArgumentException - if the text contains invalid UTF-16 surrogates.
      • printDecimal

        public static void printDecimal​(java.lang.Appendable out,
                                        java.math.BigDecimal decimal)
                                 throws java.io.IOException
        Throws:
        java.io.IOException
      • printDecimal

        public static java.lang.String printDecimal​(java.math.BigDecimal decimal)
      • printFloat

        public static void printFloat​(java.lang.Appendable out,
                                      double value)
                               throws java.io.IOException
        Throws:
        java.io.IOException
      • printFloat

        public static java.lang.String printFloat​(double value)
      • printFloat

        public static void printFloat​(java.lang.Appendable out,
                                      java.lang.Double value)
                               throws java.io.IOException
        Throws:
        java.io.IOException
      • printFloat

        public static java.lang.String printFloat​(java.lang.Double value)
      • printBlob

        public static void printBlob​(java.lang.Appendable out,
                                     byte[] value)
                              throws java.io.IOException
        Throws:
        java.io.IOException
      • printBlob

        public static java.lang.String printBlob​(byte[] value)
      • printClob

        public static void printClob​(java.lang.Appendable out,
                                     byte[] value)
                              throws java.io.IOException
        Throws:
        java.io.IOException
      • printClob

        public static java.lang.String printClob​(byte[] value)