Class TruffleString
java.lang.Object
com.oracle.truffle.api.strings.AbstractTruffleString
com.oracle.truffle.api.strings.TruffleString
Represents a primitive String type, which can be reused across languages. Language implementers
are encouraged to use Truffle Strings as their language's string type for easier interoperability
and better performance. Truffle strings can be encoded in a number of
encodings.
A TruffleString object can cache multiple representations (in multiple encodings) of the
same string in the string object itself. A single TruffleString instance can also
represent the same string in multiple encodings, if the string's content would be equal in all
such encodings (e.g. a string containing only ASCII characters can be viewed as being encoded in
almost any encoding, since the encoded bytes would be equal). To facilitate this, all methods
have an expectedEncoding parameter to indicate which encoding a given string should be
viewed in.
TruffleString instances can be created via one of the following nodes, or via
TruffleStringBuilder.
TruffleString.FromByteArrayNodeTruffleString.FromCharArrayUTF16NodeTruffleString.FromJavaStringNodeTruffleString.FromIntArrayUTF32NodeTruffleString.FromNativePointerNodeTruffleString.FromCodePointNodeTruffleString.FromLongNode
TruffleStringIterator. There is a version of TruffleString that
is also mutable. See MutableTruffleString for details.
Please see the tutorial for further usage instructions.
- Since:
- 22.1
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classNode to get the givenAbstractTruffleStringas a managedTruffleString, meaning that the resulting string's backing memory is not a native pointer.static classstatic classNode to get the givenAbstractTruffleStringas aTruffleString.static classNode to find the index of the first occurrence of any byte from a given array.static classTruffleString.IndexOfCodePointNode, but with byte indices.static classNode to find the byte index of the first occurrence of a codepoint present in a given codepoint set.static classTruffleString.IndexOfStringNode, but with byte indices.static classNode to convert a given byte index to a codepoint index.static classNode to get the number of bytes occupied by the codepoint starting at a given byte index.static classNode to find the index of the first occurrence of anycharfrom a given array.static classNode to read a codepoint at a given byte index.static classNode to read a codepoint at a given codepoint index.static classNode to read a codepoint at a given codepoint index from a UTF-32 string.static classNode to convert a given codepoint index to a byte index.static classNode to get the number of codepoints in a string.static final classA set of codepoints in a given encoding.static enumProvides information about a string's content.static classNode to check if a string's code range is equal to the givenTruffleString.CodeRange.static enumRepresents a string's compaction level, i.e.static classNode to compare two strings byte-by-byte.static classNode to compare two UTF-16 strings.static classNode to compare two UTF-32 strings.static classNode to concatenate two strings.static classNode to copy a region of a string into a byte array.static classNode to copy a region of a string into native memory.static classNode to create aTruffleStringIterator.static classNode to create aTruffleStringIterator.static enumThe list of encodings supported byTruffleString.static classNode to check two strings for equality.static enumError handling instructions for operations that return integer values, such as indices or code points.static classNode to forcibly assign any encoding to a string.static classNode to create a newTruffleStringfrom a byte array.static classNode to create a new UTF-16TruffleStringfrom a char array.static classNode to create a newTruffleStringfrom a single codepoint.static classNode to create a new UTF-32TruffleStringfrom an int-array.static classNode to create a newTruffleStringfrom a Java string.static classNode to create a newTruffleStringfrom alongvalue.static classNode to create a newTruffleStringfrom an interop object representing a native pointer.static classNode to get a string's "byte-based"TruffleString.CodeRange.static classNode to get a string's possibly impreciseTruffleString.CodeRange.static classNode to get a string's preciseTruffleString.CodeRange.static classNode to get a string's internal byte array.static classNode to get anativestring's pointer object.static classNode to get a string'sTruffleString.CompactionLevel.static classNode to get a string's hash code.static final classstatic classNode to find the index of the first occurrence of a given code point.static classNode to find the index of the first occurrence of a given string.static classNode to find the index of the first occurrence of anyintfrom a given array.static classNode to check if a string is encoded correctly.static classTruffleString.LastIndexOfCodePointNode, but with byte indices.static classTruffleString.LastIndexOfStringNode, but with byte indices.static classNode to find the codepoint index of the last occurrence of a given code point.static classNode to find the index of the last occurrence of a given string.static classNode to force materialization of any lazy internal data.static classExtended version ofTruffleString.MaterializeNodethat also materializes substrings/string views created via e.g.static final classThis exception may be thrown byTruffleString.ParseIntNode,TruffleString.ParseLongNodeorTruffleString.ParseDoubleNodeto indicate that the given string cannot be parsed as an integer, long or double value.static classNode to parse a given string as a double value.static classNode to parse a given string as an int value.static classNode to parse a given string as a long value.static classNode to read a single byte from a string.static classNode to read a single char from a UTF-16 string.static classNode to check for a region match, byte-by-byte.static classNode to check codepoint equality of two string regions.static classNode to repeat a given stringNtimes.static classTruffleString.SubstringNode, but with byte indices.static classNode to create a substring of a given string.static classNode to get a given string in a specific encoding.static classNode to get aStringrepresentation of aTruffleString.static classNode to replace all invalid bytes in a given string, such that the resulting string isvalid.static final classExtended parameter type for the operationsTruffleString.ByteIndexOfStringNode,TruffleString.LastByteIndexOfStringNodeandTruffleString.RegionEqualByteIndexNode. -
Method Summary
Modifier and TypeMethodDescriptionasNativeUncached(NativeAllocator allocator, TruffleString.Encoding expectedEncoding, boolean useCompaction, boolean cacheResult) Shorthand for calling the uncached version ofTruffleString.AsNativeNode.static TruffleStringfromByteArrayUncached(byte[] value, int byteOffset, int byteLength, TruffleString.Encoding encoding, boolean copy) Shorthand for calling the uncached version ofTruffleString.FromByteArrayNode.static TruffleStringfromByteArrayUncached(byte[] value, TruffleString.Encoding encoding) Shorthand for calling the uncached version ofTruffleString.FromByteArrayNode.static TruffleStringfromByteArrayUncached(byte[] value, TruffleString.Encoding encoding, boolean copy) Shorthand for calling the uncached version ofTruffleString.FromByteArrayNode.static TruffleStringfromCharArrayUTF16Uncached(char[] value) Shorthand for calling the uncached version ofTruffleString.FromCharArrayUTF16Node.static TruffleStringfromCharArrayUTF16Uncached(char[] value, int charOffset, int charLength) Shorthand for calling the uncached version ofTruffleString.FromCharArrayUTF16Node.static TruffleStringfromCodePointUncached(int codepoint, TruffleString.Encoding encoding) Shorthand for calling the uncached version ofTruffleString.FromCodePointNode.static TruffleStringfromCodePointUncached(int codepoint, TruffleString.Encoding encoding, boolean allowUTF16Surrogates) Shorthand for calling the uncached version ofTruffleString.FromCodePointNode.static TruffleStringfromConstant(String s, TruffleString.Encoding encoding) Shorthand for calling the uncached version ofTruffleString.FromJavaStringNode.static TruffleStringfromIntArrayUTF32Uncached(int[] value) Shorthand for calling the uncached version ofTruffleString.FromIntArrayUTF32Node.static TruffleStringfromIntArrayUTF32Uncached(int[] value, int intOffset, int intLength) Shorthand for calling the uncached version ofTruffleString.FromIntArrayUTF32Node.static TruffleStringfromJavaStringUncached(String s, int charOffset, int length, TruffleString.Encoding encoding, boolean copy) Shorthand for calling the uncached version ofTruffleString.FromJavaStringNode.static TruffleStringfromJavaStringUncached(String s, TruffleString.Encoding encoding) Shorthand for calling the uncached version ofTruffleString.FromJavaStringNode.static TruffleStringfromLongUncached(long value, TruffleString.Encoding encoding, boolean lazy) Shorthand for calling the uncached version ofTruffleString.FromLongNode.static TruffleStringfromNativePointerUncached(Object pointerObject, int byteOffset, int byteLength, TruffleString.Encoding encoding, boolean copy) Shorthand for calling the uncached version ofTruffleString.FromNativePointerNode.Methods inherited from class AbstractTruffleString
asManagedMutableTruffleStringUncached, asManagedTruffleStringUncached, asManagedTruffleStringUncached, asMutableTruffleStringUncached, asTruffleStringUncached, byteIndexOfAnyByteUncached, byteIndexOfCodePointUncached, byteIndexOfStringUncached, byteIndexOfStringUncached, byteIndexToCodePointIndexUncached, byteLength, byteLengthOfCodePointUncached, byteLengthOfCodePointUncached, charIndexOfAnyCharUTF16Uncached, codePointAtByteIndexUncached, codePointAtByteIndexUncached, codePointAtIndexUncached, codePointAtIndexUncached, codePointIndexToByteIndexUncached, codePointLengthUncached, codeRangeEqualsUncached, compareBytesUncached, compareCharsUTF16Uncached, compareIntsUTF32Uncached, concatUncached, copyToByteArrayNodeUncached, copyToByteArrayUncached, copyToByteArrayUncached, copyToNativeMemoryNodeUncached, copyToNativeMemoryUncached, createBackwardCodePointIteratorUncached, createCodePointIteratorUncached, equals, equalsUncached, forceEncodingUncached, getByteCodeRangeUncached, getCodeRangeImpreciseUncached, getCodeRangeUncached, getInternalByteArrayUncached, getInternalNativePointerUncached, getStringCompactionLevelUncached, hashCode, hashCodeUncached, indexOfCodePointUncached, indexOfStringUncached, intIndexOfAnyIntUTF32Uncached, isCompatibleTo, isCompatibleToUncached, isEmpty, isImmutable, isManaged, isMutable, isNative, isValidUncached, lastByteIndexOfCodePointUncached, lastByteIndexOfStringUncached, lastByteIndexOfStringUncached, lastIndexOfCodePointUncached, lastIndexOfStringUncached, materializeSubstringUncached, materializeUncached, materializeUncached, parseDoubleUncached, parseIntUncached, parseIntUncached, parseLongUncached, parseLongUncached, readByteUncached, readCharUTF16Uncached, regionEqualByteIndexUncached, regionEqualByteIndexUncached, regionEqualsUncached, repeatUncached, substringByteIndexUncached, substringUncached, switchEncodingUncached, switchEncodingUncached, toJavaStringUncached, toString, toStringDebug, toValidStringUncached
-
Method Details
-
fromCodePointUncached
Shorthand for calling the uncached version ofTruffleString.FromCodePointNode.- Since:
- 22.1
-
fromCodePointUncached
public static TruffleString fromCodePointUncached(int codepoint, TruffleString.Encoding encoding, boolean allowUTF16Surrogates) Shorthand for calling the uncached version ofTruffleString.FromCodePointNode.- Since:
- 22.2
-
fromLongUncached
public static TruffleString fromLongUncached(long value, TruffleString.Encoding encoding, boolean lazy) Shorthand for calling the uncached version ofTruffleString.FromLongNode.- Since:
- 22.1
-
fromByteArrayUncached
Shorthand for calling the uncached version ofTruffleString.FromByteArrayNode.- Since:
- 22.1
-
fromByteArrayUncached
public static TruffleString fromByteArrayUncached(byte[] value, TruffleString.Encoding encoding, boolean copy) Shorthand for calling the uncached version ofTruffleString.FromByteArrayNode.- Since:
- 22.1
-
fromByteArrayUncached
public static TruffleString fromByteArrayUncached(byte[] value, int byteOffset, int byteLength, TruffleString.Encoding encoding, boolean copy) Shorthand for calling the uncached version ofTruffleString.FromByteArrayNode.- Since:
- 22.1
-
fromCharArrayUTF16Uncached
Shorthand for calling the uncached version ofTruffleString.FromCharArrayUTF16Node.- Since:
- 22.1
-
fromCharArrayUTF16Uncached
public static TruffleString fromCharArrayUTF16Uncached(char[] value, int charOffset, int charLength) Shorthand for calling the uncached version ofTruffleString.FromCharArrayUTF16Node.- Since:
- 22.1
-
fromJavaStringUncached
Shorthand for calling the uncached version ofTruffleString.FromJavaStringNode.For constant strings, it is recommended to use
fromConstant(String, Encoding)instead.- Since:
- 22.1
-
fromJavaStringUncached
public static TruffleString fromJavaStringUncached(String s, int charOffset, int length, TruffleString.Encoding encoding, boolean copy) Shorthand for calling the uncached version ofTruffleString.FromJavaStringNode.For constant strings, it is recommended to use
fromConstant(String, Encoding)instead.- Since:
- 22.1
-
fromConstant
Shorthand for calling the uncached version ofTruffleString.FromJavaStringNode. This variant also forces the calculation of the string's preciseTruffleString.CodeRangeand hash code.- Since:
- 23.0
-
fromIntArrayUTF32Uncached
Shorthand for calling the uncached version ofTruffleString.FromIntArrayUTF32Node.- Since:
- 22.1
-
fromIntArrayUTF32Uncached
Shorthand for calling the uncached version ofTruffleString.FromIntArrayUTF32Node.- Since:
- 22.1
-
fromNativePointerUncached
public static TruffleString fromNativePointerUncached(Object pointerObject, int byteOffset, int byteLength, TruffleString.Encoding encoding, boolean copy) Shorthand for calling the uncached version ofTruffleString.FromNativePointerNode.- Since:
- 22.1
-
asNativeUncached
public TruffleString asNativeUncached(NativeAllocator allocator, TruffleString.Encoding expectedEncoding, boolean useCompaction, boolean cacheResult) Shorthand for calling the uncached version ofTruffleString.AsNativeNode.- Since:
- 23.0
-