Package com.amazon.ion.util
Class IonTextUtils
java.lang.Object
com.amazon.ion.util.IonTextUtils
Utility methods for working with Ion's text-oriented data types.
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanisAllWhitespace(CharSequence charSequence) Ion whitespace is defined as one of the characters space, tab, newline, and carriage-return.static booleanisDigit(int codePoint, int radix) static booleanisIdentifierPart(int codePoint) static booleanisIdentifierStart(int codePoint) static booleanisNumericStop(int codePoint) Determines whether a given code point is one of the valid Ion numeric terminators.static booleanisOperatorPart(int codePoint) static booleanisWhitespace(int codePoint) Ion whitespace is defined as one of the characters space, tab, newline, and carriage-return.static StringprintBlob(byte[] value) static voidprintBlob(Appendable out, byte[] value) static StringprintClob(byte[] value) static voidprintClob(Appendable out, byte[] value) static StringprintCodePointAsString(int codePoint) Builds a String denoting an ASCII-encoded Ion string, with double-quotes surrounding a single Unicode code point.static voidprintDecimal(Appendable out, BigDecimal decimal) static StringprintDecimal(BigDecimal decimal) static StringprintFloat(double value) static voidprintFloat(Appendable out, double value) static voidprintFloat(Appendable out, Double value) static StringprintFloat(Double value) static voidprintJsonCodePoint(Appendable out, int codePoint) Prints a single Unicode code point for use in an ASCII-safe JSON string.static voidprintJsonString(Appendable out, CharSequence text) Prints characters as an ASCII-encoded JSON string, including surrounding double-quotes.static voidprintLongString(Appendable out, CharSequence text) Prints characters as an ASCII-encoded Ion "long string", including surrounding triple-quotes.static StringprintLongString(CharSequence text) Builds a String denoting an ASCII-encoded Ion "long string", including surrounding triple-quotes.static voidprintQuotedSymbol(Appendable out, CharSequence text) Prints text as a single-quoted Ion symbol.static StringBuilds a String containing a single-quoted Ion symbol.static voidprintString(Appendable out, CharSequence text) Prints characters as an ASCII-encoded Ion string, including surrounding double-quotes.static StringprintString(CharSequence text) Builds a String denoting an ASCII-encoded Ion string, including surrounding double-quotes.static voidprintStringCodePoint(Appendable out, int codePoint) Prints a single Unicode code point for use in an ASCII-safe Ion string.static StringprintSymbol(SymbolToken token) static voidprintSymbol(Appendable out, CharSequence text) Prints the text as an Ion symbol, including surrounding single-quotes if they are necessary.static StringprintSymbol(CharSequence text) Prints the text as an Ion symbol, including surrounding single-quotes if they are necessary.static voidprintSymbolCodePoint(Appendable out, int codePoint) Prints a single Unicode code point for use in an ASCII-safe Ion symbol.static IonTextUtils.SymbolVariantsymbolVariant(CharSequence symbol) Determines whether the text of a symbol represents an identifier, an operator, or a symbol that always requires (single) quotes.
-
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:
trueifcis one of the four legal Ion whitespace characters.- See Also:
-
isAllWhitespace
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:
trueifcharSequenceconsists 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 returnsfalsefor 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
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- ifsymbolisnull.
-
printStringCodePoint
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
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
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
Prints characters as an ASCII-encoded Ion string, including surrounding double-quotes. If thetextis null, this printsnull.string.- Parameters:
out- the stream to receive the data.text- the text to print; may benull.- Throws:
IOException- if theAppendablethrows an exception.IllegalArgumentException- if the text contains invalid UTF-16 surrogates.
-
printJsonString
Prints characters as an ASCII-encoded JSON string, including surrounding double-quotes. If thetextis null, this printsnull.- Parameters:
out- the stream to receive the JSON data.text- the text to print; may benull.- Throws:
IOException- if theAppendablethrows an exception.IllegalArgumentException- if the text contains invalid UTF-16 surrogates.
-
printString
Builds a String denoting an ASCII-encoded Ion string, including surrounding double-quotes. If thetextis null, this returns"null.string".- Parameters:
text- the text to print; may benull.- Throws:
IllegalArgumentException- if the text contains invalid UTF-16 surrogates.
-
printLongString
Builds a String denoting an ASCII-encoded Ion "long string", including surrounding triple-quotes. If thetextis null, this returns"null.string".- Parameters:
text- the text to print; may benull.- Throws:
IllegalArgumentException- if the text contains invalid UTF-16 surrogates.
-
printLongString
Prints characters as an ASCII-encoded Ion "long string", including surrounding triple-quotes. If thetextis null, this printsnull.string.- Parameters:
out- the stream to receive the data.text- the text to print; may benull.- Throws:
IOException- if theAppendablethrows an exception.IllegalArgumentException- if the text contains invalid UTF-16 surrogates.
-
printCodePointAsString
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
Prints the text as an Ion symbol, including surrounding single-quotes if they are necessary. Operator symbols such as'+'are quoted. If thetextis null, this printsnull.symbol.- Parameters:
out- the stream to receive the Ion data.text- the symbol text; may benull.- Throws:
IOException- if theAppendablethrows an exception.- See Also:
-
printSymbol
Prints the text as an Ion symbol, including surrounding single-quotes if they are necessary. Operator symbols such as'+'are quoted. If thetextis null, this returns"null.symbol".- Parameters:
text- the symbol text; may benull.- Returns:
- a string containing the resulting Ion data.
- See Also:
-
printSymbol
- Parameters:
token- the symbolToken to be printed.- Returns:
- a string representing the symboltoken.
-
printQuotedSymbol
Prints text as a single-quoted Ion symbol. If thetextis null, this printsnull.symbol.- Parameters:
out- the stream to receive the data.text- the symbol text; may benull.- Throws:
IOException- if theAppendablethrows an exception.IllegalArgumentException- if the text contains invalid UTF-16 surrogates.
-
printQuotedSymbol
Builds a String containing a single-quoted Ion symbol. If thetextis null, this returns"null.symbol".- Parameters:
text- the symbol text; may benull.- Throws:
IllegalArgumentException- if the text contains invalid UTF-16 surrogates.
-
printDecimal
- Throws:
IOException
-
printDecimal
-
printFloat
- Throws:
IOException
-
printFloat
-
printFloat
- Throws:
IOException
-
printFloat
-
printBlob
- Throws:
IOException
-
printBlob
-
printClob
- Throws:
IOException
-
printClob
-