Class StringSegment
- All Implemented Interfaces:
CharSequence
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
adjustOffset
(int delta) Equivalent tosetOffset(getOffset()+delta)
.void
Adjusts the offset by the width of the current lead code point, either 1 or 2 chars.asString()
Returns a String that is equivalent to the CharSequence representation.char
charAt
(int index) int
codePointAt
(int index) Returns the code point at the given index relative to the current offset.private static final boolean
codePointsEqual
(int cp1, int cp2, boolean foldCase) boolean
contentEquals
(CharSequence other) Returns true if this segment contains the same characters as the other CharSequence.int
LikegetCommonPrefixLength(java.lang.CharSequence)
, but never performs case folding, even if case folding was enabled in the constructor.int
Returns the first code point in the string segment.int
Returns the length of the prefix shared by this StringSegment and the given CharSequence.int
private int
getPrefixLengthInternal
(CharSequence other, boolean foldCase) int
length()
void
void
setLength
(int length) void
setOffset
(int start) boolean
startsWith
(int otherCp) Returns true if the first code point of this StringSegment equals the given code point.boolean
startsWith
(UnicodeSet uniset) Returns true if the first code point of this StringSegment is in the given UnicodeSet.boolean
startsWith
(CharSequence other) Returns true if there is at least one code point of overlap between this StringSegment and the given CharSequence.subSequence
(int start, int end) toString()
Returns a string representation useful for debugging.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.CharSequence
chars, codePoints, isEmpty
-
Field Details
-
str
-
start
private int start -
end
private int end -
foldCase
private boolean foldCase
-
-
Constructor Details
-
StringSegment
-
-
Method Details
-
getOffset
public int getOffset() -
setOffset
public void setOffset(int start) -
adjustOffset
public void adjustOffset(int delta) Equivalent tosetOffset(getOffset()+delta)
.Number parsing note: This method is usually called by a Matcher to register that a char was consumed. If the char is strong (it usually is, except for things like whitespace), follow this with a call to ParsedNumber#setCharsConsumed(). For more information on strong chars, see that method.
-
adjustOffsetByCodePoint
public void adjustOffsetByCodePoint()Adjusts the offset by the width of the current lead code point, either 1 or 2 chars. -
setLength
public void setLength(int length) -
resetLength
public void resetLength() -
length
public int length()- Specified by:
length
in interfaceCharSequence
-
charAt
public char charAt(int index) - Specified by:
charAt
in interfaceCharSequence
-
subSequence
- Specified by:
subSequence
in interfaceCharSequence
-
getCodePoint
public int getCodePoint()Returns the first code point in the string segment.Important: Most of the time, you should use
startsWith(int)
, which handles case folding logic, instead of this method. -
codePointAt
public int codePointAt(int index) Returns the code point at the given index relative to the current offset. -
startsWith
public boolean startsWith(int otherCp) Returns true if the first code point of this StringSegment equals the given code point.This method will perform case folding if case folding is enabled for the parser.
-
startsWith
Returns true if the first code point of this StringSegment is in the given UnicodeSet. -
startsWith
Returns true if there is at least one code point of overlap between this StringSegment and the given CharSequence. Null-safe. -
getCommonPrefixLength
Returns the length of the prefix shared by this StringSegment and the given CharSequence. For example, if this string segment is "aab", and the char sequence is "aac", this method returns 2, since the first 2 characters are the same.This method only returns offsets along code point boundaries.
This method will perform case folding if case folding was enabled in the constructor.
IMPORTANT: The given CharSequence must not be empty! It is the caller's responsibility to check.
-
getCaseSensitivePrefixLength
LikegetCommonPrefixLength(java.lang.CharSequence)
, but never performs case folding, even if case folding was enabled in the constructor. -
getPrefixLengthInternal
-
codePointsEqual
private static final boolean codePointsEqual(int cp1, int cp2, boolean foldCase) -
contentEquals
Returns true if this segment contains the same characters as the other CharSequence.This method does not perform case folding; if you want case-insensitive equality, use
getCommonPrefixLength(java.lang.CharSequence)
. -
toString
Returns a string representation useful for debugging.- Specified by:
toString
in interfaceCharSequence
- Overrides:
toString
in classObject
-
asString
Returns a String that is equivalent to the CharSequence representation.
-