Class StringSegment
- All Implemented Interfaces:
CharSequence
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidadjustOffset(int delta) Equivalent tosetOffset(getOffset()+delta).voidAdjusts 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.charcharAt(int index) intcodePointAt(int index) Returns the code point at the given index relative to the current offset.booleancontentEquals(CharSequence other) Returns true if this segment contains the same characters as the other CharSequence.intLikegetCommonPrefixLength(CharSequence), but never performs case folding, even if case folding was enabled in the constructor.intReturns the first code point in the string segment.intReturns the length of the prefix shared by this StringSegment and the given CharSequence.intintlength()voidvoidsetLength(int length) voidsetOffset(int start) booleanstartsWith(int otherCp) Returns true if the first code point of this StringSegment equals the given code point.booleanstartsWith(CharSequence other) Returns true if there is at least one code point of overlap between this StringSegment and the given CharSequence.booleanstartsWith(UnicodeSet uniset) Returns true if the first code point of this StringSegment is in the given UnicodeSet.subSequence(int start, int end) toString()Returns a string representation useful for debugging.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface CharSequence
chars, codePoints, getChars, isEmpty
-
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:
lengthin interfaceCharSequence
-
charAt
public char charAt(int index) - Specified by:
charAtin interfaceCharSequence
-
subSequence
- Specified by:
subSequencein 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(CharSequence), but never performs case folding, even if case folding was enabled in the constructor. -
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(CharSequence). -
toString
Returns a string representation useful for debugging.- Specified by:
toStringin interfaceCharSequence- Overrides:
toStringin classObject
-
asString
Returns a String that is equivalent to the CharSequence representation.
-