Package net.sf.saxon.str
Class StringView
- java.lang.Object
-
- net.sf.saxon.str.UnicodeString
-
- net.sf.saxon.str.StringView
-
- All Implemented Interfaces:
java.lang.Comparable<UnicodeString>
,AtomicMatchKey
public class StringView extends UnicodeString
An implementation of the UnicodeString interface that wraps an ordinary Java string.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
codePointAt(long index)
Get the code point at a given position in the stringIntIterator
codePoints()
Get an iterator over the code points present in the string.int
compareTo(UnicodeString other)
Compare this string to another using codepoint comparisonUnicodeString
concat(UnicodeString other)
Concatenate with another string, returning a new stringUnicodeString
economize()
boolean
equals(java.lang.Object obj)
long
estimatedLength()
Get the estimated length of the string, suitable for space allocation.int
getWidth()
Get the number of bits needed to hold all the characters in this stringint
hashCode()
Compute a hashCode.long
indexOf(int codePoint, long from)
Get the position of the first occurrence of the specified codepoint, starting the search at a given position in the stringlong
indexWhere(java.util.function.IntPredicate predicate, long from)
Get the position of the first occurrence of a codepoint that matches a supplied predicate, starting the search at a given position in the stringboolean
isEmpty()
Ask whether the string is emptylong
length()
Get the length of the stringstatic UnicodeString
of(java.lang.String base)
UnicodeString
substring(long start, long end)
Get a substring of this codepoint sequence, with a given start and end positionUnicodeString
tidy()
Ensure that the implementation is capable of counting codepoints in the string.static UnicodeString
tidy(java.lang.String base)
java.lang.String
toString()
static UnicodeString
wrap(java.lang.String base)
-
Methods inherited from class net.sf.saxon.str.UnicodeString
asAtomic, checkSubstringBounds, hasSubstring, indexOf, indexOf, length32, prefix, requireInt, requireNonNegativeInt, substring, verifyCharacters
-
-
-
-
Method Detail
-
of
public static UnicodeString of(java.lang.String base)
-
wrap
public static UnicodeString wrap(java.lang.String base)
-
tidy
public static UnicodeString tidy(java.lang.String base)
-
tidy
public UnicodeString tidy()
Description copied from class:UnicodeString
Ensure that the implementation is capable of counting codepoints in the string. This is normally a null operation, but it may cause internal reorganisation.- Overrides:
tidy
in classUnicodeString
- Returns:
- this
UnicodeString
, or another that represents the same sequence of characters.
-
isEmpty
public boolean isEmpty()
Description copied from class:UnicodeString
Ask whether the string is empty- Overrides:
isEmpty
in classUnicodeString
- Returns:
- true if the length of the string is zero
-
estimatedLength
public long estimatedLength()
Description copied from class:UnicodeString
Get the estimated length of the string, suitable for space allocation.- Overrides:
estimatedLength
in classUnicodeString
- Returns:
- for a
UnicodeString
, the actual length of the string in codepoints
-
length
public long length()
Get the length of the string- Specified by:
length
in classUnicodeString
- Returns:
- the number of code points in the string
-
getWidth
public int getWidth()
Get the number of bits needed to hold all the characters in this string- Specified by:
getWidth
in classUnicodeString
- Returns:
- 7 for ascii characters, 8 for latin-1, 16 for BMP, 24 for general Unicode.
-
indexOf
public long indexOf(int codePoint, long from)
Get the position of the first occurrence of the specified codepoint, starting the search at a given position in the string- Specified by:
indexOf
in classUnicodeString
- Parameters:
codePoint
- the sought codepointfrom
- the position from which the search should start (0-based). There is no restriction on the value. Negative values are treated as zero; values greater than or equal to length() return -1.- Returns:
- the position (zero-based) of the first occurrence found, or -1 if not found
-
indexWhere
public long indexWhere(java.util.function.IntPredicate predicate, long from)
Description copied from class:UnicodeString
Get the position of the first occurrence of a codepoint that matches a supplied predicate, starting the search at a given position in the string- Specified by:
indexWhere
in classUnicodeString
- Parameters:
predicate
- condition that the codepoint must satisfyfrom
- the position from which the search should start (0-based). A negative value is treated as zero. A position beyond the end of the string results in a return value of -1 (meaning not found).- Returns:
- the position (0-based) of the first codepoint to match the predicate, or -1 if not found
-
codePointAt
public int codePointAt(long index)
Get the code point at a given position in the string- Specified by:
codePointAt
in classUnicodeString
- Parameters:
index
- the given position (0-based)- Returns:
- the code point at the given position
- Throws:
java.lang.IndexOutOfBoundsException
- if the index is out of range
-
substring
public UnicodeString substring(long start, long end)
Get a substring of this codepoint sequence, with a given start and end position- Specified by:
substring
in classUnicodeString
- Parameters:
start
- the start position (0-based): that is, the position of the first code point to be includedend
- the end position (0-based): specifically, the position of the first code point not to be included- Returns:
- the requested substring
- Throws:
java.lang.UnsupportedOperationException
- if theUnicodeString
has not been prepared for codePoint access
-
codePoints
public IntIterator codePoints()
Description copied from class:UnicodeString
Get an iterator over the code points present in the string.- Specified by:
codePoints
in classUnicodeString
- Returns:
- an iterator that delivers the individual code points
-
concat
public UnicodeString concat(UnicodeString other)
Description copied from class:UnicodeString
Concatenate with another string, returning a new string- Overrides:
concat
in classUnicodeString
- Parameters:
other
- the string to be appended- Returns:
- the result of concatenating this string followed by the other
-
compareTo
public int compareTo(UnicodeString other)
Description copied from class:UnicodeString
Compare this string to another using codepoint comparison- Specified by:
compareTo
in interfacejava.lang.Comparable<UnicodeString>
- Overrides:
compareTo
in classUnicodeString
- Parameters:
other
- the other string- Returns:
- -1 if this string comes first, 0 if they are equal, +1 if the other string comes first
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classUnicodeString
-
hashCode
public int hashCode()
Description copied from class:UnicodeString
Compute a hashCode. All implementations ofUnicodeString
use compatible hash codes and the hashing algorithm is therefore identical to that forjava.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.- Overrides:
hashCode
in classUnicodeString
- Returns:
- the hash code
-
economize
public UnicodeString economize()
- Overrides:
economize
in classUnicodeString
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-