Package net.sf.saxon.str
Class BMPString
- java.lang.Object
-
- net.sf.saxon.str.UnicodeString
-
- net.sf.saxon.str.BMPString
-
- All Implemented Interfaces:
java.lang.Comparable<UnicodeString>,AtomicMatchKey
public class BMPString extends UnicodeString
An implementation ofUnicodeStringthat wraps a Java string which is known to contain no surrogates. That is, all the characters in the string are in the Basic Multilingual Plane (their codepoints are in the range 0-65535).
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedBMPString(java.lang.String baseString)Protected constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intcodePointAt(long index)Get the code point at a given position in the stringIntIteratorcodePoints()Get an iterator over the code points present in the string.intcompareTo(UnicodeString other)Compare this string to another using codepoint comparisonUnicodeStringconcat(UnicodeString other)Concatenate with another string, returning a new stringbooleanequals(java.lang.Object obj)intgetWidth()Get the number of bits needed to hold all the characters in this stringinthashCode()Compute a hashCode.longindexOf(int codePoint)Get the position of the first occurrence of the specified codepoint, starting the search at the beginninglongindexOf(int codePoint, long from)Get the position of the first occurrence of the specified codepoint, starting the search at a given position in the stringlongindexWhere(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 stringbooleanisEmpty()Ask whether the string is emptylonglength()Get the length of the stringstatic UnicodeStringof(java.lang.String base)Wrap a String, which must contain no surrogatesUnicodeStringsubstring(long start, long end)Get a substring of this string, with a given start and end positionjava.lang.StringtoString()-
Methods inherited from class net.sf.saxon.str.UnicodeString
asAtomic, checkSubstringBounds, economize, estimatedLength, hasSubstring, indexOf, length32, prefix, requireInt, substring, tidy, verifyCharacters
-
-
-
-
Method Detail
-
of
public static UnicodeString of(java.lang.String base)
Wrap a String, which must contain no surrogates- Parameters:
base- the string. The caller warrants that this string contains no surrogates; this condition is checked only if Java assertions are enabled.- Returns:
- the wrapped string.
-
length
public long length()
Description copied from class:UnicodeStringGet the length of the string- Specified by:
lengthin classUnicodeString- Returns:
- the number of code points in the string
-
isEmpty
public boolean isEmpty()
Description copied from class:UnicodeStringAsk whether the string is empty- Overrides:
isEmptyin classUnicodeString- Returns:
- true if the length of the string is zero
-
getWidth
public int getWidth()
Description copied from class:UnicodeStringGet the number of bits needed to hold all the characters in this string- Specified by:
getWidthin classUnicodeString- Returns:
- 7 for ascii characters (not used??), 8 for latin-1, 16 for BMP, 24 for general Unicode.
-
codePoints
public IntIterator codePoints()
Description copied from class:UnicodeStringGet an iterator over the code points present in the string.- Specified by:
codePointsin classUnicodeString- Returns:
- an iterator that delivers the individual code points
-
indexOf
public long indexOf(int codePoint)
Description copied from class:UnicodeStringGet the position of the first occurrence of the specified codepoint, starting the search at the beginning- Overrides:
indexOfin classUnicodeString- Parameters:
codePoint- the sought codePoint- Returns:
- the position (0-based) of the first occurrence found, or -1 if not found, counting codePoints rather than UTF16 chars.
-
indexOf
public long indexOf(int codePoint, long from)Description copied from class:UnicodeStringGet the position of the first occurrence of the specified codepoint, starting the search at a given position in the string- Specified by:
indexOfin classUnicodeString- Parameters:
codePoint- the sought codePointfrom- the position from which the search should start (0-based)- Returns:
- the position (0-based) of the first occurrence found, or -1 if not found
-
indexWhere
public 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- Overrides:
indexWherein classUnicodeString- Parameters:
predicate- condition that the codepoint must satisfyfrom- the position from which the search should start (0-based)- Returns:
- the position (0-based) of the first codepoint to match the predicate, or -1 if not found
- Throws:
java.lang.UnsupportedOperationException- if theUnicodeStringhas not been prepared for codePoint access
-
codePointAt
public int codePointAt(long index)
Description copied from class:UnicodeStringGet the code point at a given position in the string- Specified by:
codePointAtin classUnicodeString- Parameters:
index- the given position (0-based)- Returns:
- the code point at the given position
-
substring
public UnicodeString substring(long start, long end)
Description copied from class:UnicodeStringGet a substring of this string, with a given start and end position- Specified by:
substringin 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
-
concat
public UnicodeString concat(UnicodeString other)
Description copied from class:UnicodeStringConcatenate with another string, returning a new string- Overrides:
concatin 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:UnicodeStringCompare this string to another using codepoint comparison- Specified by:
compareToin interfacejava.lang.Comparable<UnicodeString>- Overrides:
compareToin 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:
equalsin classUnicodeString
-
hashCode
public int hashCode()
Description copied from class:UnicodeStringCompute a hashCode. All implementations ofUnicodeStringuse 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:
hashCodein classUnicodeString- Returns:
- the hash code
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-