Top Description Fields Constructors Methods
com.ibm.icu.impl

public Class StringSegment

extends Object
implements CharSequence
Class Inheritance
All Implemented Interfaces
java.lang.CharSequence
Imports
com.ibm.icu.lang.UCharacter, com.ibm.icu.text.UnicodeSet

A mutable String wrapper with a variable offset and length and support for case folding. The charAt, length, and subSequence methods all operate relative to the fixed offset into the String. Intended to be useful for parsing.

Caution

Since this class is mutable, it must not be used anywhere that an immutable object is required, like in a cache or as the key of a hash map.

Author
sffc (Shane Carr)

Field Summary

Modifier and TypeField and Description
private int
private boolean
private int
private final String

Constructor Summary

AccessConstructor and Description
public
StringSegment(String str, boolean foldCase)

Method Summary

Modifier and TypeMethod and Description
public void
adjustOffset(int delta)

Equivalent to setOffset(getOffset()+delta).

public void
adjustOffsetByCodePoint()

Adjusts the offset by the width of the current lead code point, either 1 or 2 chars.

public String
asString()

Returns a String that is equivalent to the CharSequence representation.

public char
charAt(int
the index of the char value to be returned
index
)

Implements java.lang.CharSequence.charAt.

Returns the char value at the specified index.
public 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)

public boolean
contentEquals(CharSequence other)

Returns true if this segment contains the same characters as the other CharSequence.

public int
getCaseSensitivePrefixLength(CharSequence other)

Like getCommonPrefixLength, but never performs case folding, even if case folding was enabled in the constructor.

public int
getCodePoint()

Returns the first code point in the string segment.

public int
getCommonPrefixLength(CharSequence other)

Returns the length of the prefix shared by this StringSegment and the given CharSequence.

public int
private int
getPrefixLengthInternal(CharSequence other, boolean foldCase)

public int
length()

Implements java.lang.CharSequence.length.

Returns the length of this character sequence.
public void
public void
setLength(int length)

public void
setOffset(int start)

public boolean
startsWith(int otherCp)

Returns true if the first code point of this StringSegment equals the given code point.

public boolean
startsWith(UnicodeSet uniset)

Returns true if the first code point of this StringSegment is in the given UnicodeSet.

public boolean
startsWith(CharSequence other)

Returns true if there is at least one code point of overlap between this StringSegment and the given CharSequence.

public CharSequence
subSequence(int
the start index, inclusive
start
,
int
the end index, exclusive
end
)

Implements java.lang.CharSequence.subSequence.

Returns a CharSequence that is a subsequence of this sequence.
public String
toString()

Overrides java.lang.Object.toString.

Implements java.lang.CharSequence.toString.

Returns a string representation useful for debugging.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

endback to summary
private int end
foldCaseback to summary
private boolean foldCase
startback to summary
private int start
strback to summary
private final String str

Constructor Detail

StringSegmentback to summary
public StringSegment(String str, boolean foldCase)

Method Detail

adjustOffsetback to summary
public void adjustOffset(int delta)

Equivalent to setOffset(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.

adjustOffsetByCodePointback to summary
public void adjustOffsetByCodePoint()

Adjusts the offset by the width of the current lead code point, either 1 or 2 chars.

asStringback to summary
public String asString()

Returns a String that is equivalent to the CharSequence representation.

charAtback to summary
public char charAt(int index)

Implements java.lang.CharSequence.charAt.

Doc from java.lang.CharSequence.charAt.

Returns the char value at the specified index. An index ranges from zero to length() - 1. The first char value of the sequence is at index zero, the next at index one, and so on, as for array indexing.

If the char value specified by the index is a surrogate, the surrogate value is returned.

Parameters
index:int

the index of the char value to be returned

Returns:char

the specified char value

Annotations
@Override
codePointAtback to summary
public int codePointAt(int index)

Returns the code point at the given index relative to the current offset.

codePointsEqualback to summary
private static final boolean codePointsEqual(int cp1, int cp2, boolean foldCase)
contentEqualsback to summary
public boolean contentEquals(CharSequence other)

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.

getCaseSensitivePrefixLengthback to summary
public int getCaseSensitivePrefixLength(CharSequence other)

Like getCommonPrefixLength, but never performs case folding, even if case folding was enabled in the constructor.

getCodePointback to summary
public int getCodePoint()

Returns the first code point in the string segment.

Important Note

Most of the time, you should use startsWith, which handles case folding logic, instead of this method.

getCommonPrefixLengthback to summary
public int getCommonPrefixLength(CharSequence other)

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 Note

The given CharSequence must not be empty! It is the caller's responsibility to check.

getOffsetback to summary
public int getOffset()
getPrefixLengthInternalback to summary
private int getPrefixLengthInternal(CharSequence other, boolean foldCase)
lengthback to summary
public int length()

Implements java.lang.CharSequence.length.

Doc from java.lang.CharSequence.length.

Returns the length of this character sequence. The length is the number of 16-bit chars in the sequence.

Returns:int

the number of chars in this sequence

Annotations
@Override
resetLengthback to summary
public void resetLength()
setLengthback to summary
public void setLength(int length)
setOffsetback to summary
public void setOffset(int start)
startsWithback to summary
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.

startsWithback to summary
public boolean startsWith(UnicodeSet uniset)

Returns true if the first code point of this StringSegment is in the given UnicodeSet.

startsWithback to summary
public boolean startsWith(CharSequence other)

Returns true if there is at least one code point of overlap between this StringSegment and the given CharSequence. Null-safe.

subSequenceback to summary
public CharSequence subSequence(int start, int end)

Implements java.lang.CharSequence.subSequence.

Doc from java.lang.CharSequence.subSequence.

Returns a CharSequence that is a subsequence of this sequence. The subsequence starts with the char value at the specified index and ends with the char value at index end - 1. The length (in chars) of the returned sequence is end - start, so if start == end then an empty sequence is returned.

Parameters
start:int

the start index, inclusive

end:int

the end index, exclusive

Returns:CharSequence

the specified subsequence

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Implements java.lang.CharSequence.toString.

Returns a string representation useful for debugging.

Returns:String

Doc from java.lang.CharSequence.toString.

a string consisting of exactly this sequence of characters

Annotations
@Override