public class Twine8 extends UnicodeString
Twine8
is Unicode string whose codepoints are all in the range 0-255 (that is, Latin-1).
These are held in an array of bytes, one byte per character. The length of the string is limited
to 2^31-1 codepoints.Modifier and Type | Field and Description |
---|---|
protected byte[] |
bytes |
protected int |
cachedHash |
Constructor and Description |
---|
Twine8(byte[] bytes)
Constructor
|
Twine8(char[] chars,
int start,
int len)
Create a Twine8 from an array of characters that are known to be single byte chars
|
Twine8(java.lang.String str)
Create a Twine8 from a string whose characters are known to be single byte chars
|
Modifier and Type | Method and Description |
---|---|
int |
codePointAt(long index)
Get the code point at a given position in the string
|
IntIterator |
codePoints()
Get an iterator over the Unicode codepoints in the value.
|
int |
compareTo(UnicodeString other)
Compare this string to another using codepoint comparison
|
java.lang.String |
details() |
boolean |
equals(java.lang.Object o)
Test whether this StringValue is equal to another under the rules of the codepoint collation.
|
byte[] |
getByteArray()
Get an array of bytes holding the characters of the string in their Latin-1 encoding
|
int |
getWidth()
Get the number of bits needed to hold all the characters in this string
|
int |
hashCode()
Compute a hashCode.
|
long |
indexOf(int codePoint,
long from)
Get the first position, at or beyond start, where a given codepoint appears
in this string.
|
long |
indexOf(UnicodeString other,
long from)
Get the first position, at or beyond start, where another string appears as a substring
of this string, comparing codepoints.
|
long |
indexWhere(java.util.function.IntPredicate predicate,
long from)
Get the position of the first occurrence of the specified codepoint,
starting the search at a given position in the string
|
boolean |
isEmpty()
Determine whether the string is a zero-length string.
|
long |
length()
Get the length of this string, in codepoints
|
int |
length32()
Get the length of the string, provided it is less than 2^31 characters
|
UnicodeString |
substring(long start,
long end)
Get a substring of this string (following the rules of
String.substring(int) , but measuring
Unicode codepoints rather than 16-bit code units) |
java.lang.String |
toString()
Display as a string.
|
asAtomic, checkSubstringBounds, concat, economize, estimatedLength, hasSubstring, indexOf, prefix, requireInt, substring, tidy, verifyCharacters
public Twine8(byte[] bytes)
bytes
- the byte array containing the characters in the range 0-255. The caller must ensure that
this array is immutable.public Twine8(char[] chars, int start, int len)
chars
- character array, all characters in range must be LE 255start
- offset of first character to be usedlen
- number of characters to be usedpublic Twine8(java.lang.String str)
str
- the value, all characters in range must be LE 255public byte[] getByteArray()
public long length()
length
in class UnicodeString
public int length32()
UnicodeString
length32
in class UnicodeString
int
public UnicodeString substring(long start, long end)
String.substring(int)
, but measuring
Unicode codepoints rather than 16-bit code units)substring
in class UnicodeString
start
- the offset of the first character to be included in the result, counting Unicode codepointsend
- the offset of the first character to be excluded from the result, counting Unicode codepointspublic int codePointAt(long index) throws java.lang.IndexOutOfBoundsException
UnicodeString
codePointAt
in class UnicodeString
index
- the given position (0-based)java.lang.IndexOutOfBoundsException
- if the index is out of rangepublic long indexOf(int codePoint, long from)
indexOf
in class UnicodeString
codePoint
- the sought codepointfrom
- the position (0-based) where searching is to start (counting in codepoints)public long indexOf(UnicodeString other, long from)
indexOf
in class UnicodeString
other
- the other (sought) stringfrom
- the position (0-based) where searching is to start (counting in codepoints)public boolean isEmpty()
isEmpty
in class UnicodeString
public int getWidth()
UnicodeString
getWidth
in class UnicodeString
public IntIterator codePoints()
codePoints
in class UnicodeString
public int hashCode()
UnicodeString
use compatible hash codes and the
hashing algorithm is therefore identical to that for java.lang.String
. This means
that for strings containing Astral characters, the hash code needs to be computed by decomposing
an Astral character into a surrogate pair.hashCode
in class UnicodeString
public boolean equals(java.lang.Object o)
equals
in class UnicodeString
o
- the value to be compared with this valuepublic int compareTo(UnicodeString other)
UnicodeString
compareTo
in interface java.lang.Comparable<UnicodeString>
compareTo
in class UnicodeString
other
- the other stringpublic java.lang.String toString()
toString
in class java.lang.Object
public long indexWhere(java.util.function.IntPredicate predicate, long from)
indexWhere
in class UnicodeString
predicate
- condition that the codepoint must satisfyfrom
- the position from which the search should start (0-based)java.lang.UnsupportedOperationException
- if the UnicodeString
has not been prepared
for codePoint accesspublic java.lang.String details()
Copyright (c) 2004-2022 Saxonica Limited. All rights reserved.