public final class StringUCharacterIterator extends UCharacterIterator
DONE| Constructor and Description |
|---|
StringUCharacterIterator()
Public default constructor
|
StringUCharacterIterator(String str)
Public constructor
|
| Modifier and Type | Method and Description |
|---|---|
Object |
clone()
Creates a copy of this iterator, does not clone the underlying
Stringobject |
int |
current()
Returns the current UTF16 character.
|
int |
getIndex()
Gets the current currentIndex in text.
|
int |
getLength()
Returns the length of the text
|
String |
getText()
Convenience method for returning the underlying text storage as as
string
|
int |
getText(char[] fillIn,
int offset)
Fills the buffer with the underlying text storage of the iterator
If the buffer capacity is not enough a exception is thrown.
|
int |
next()
Returns next UTF16 character and increments the iterator's currentIndex
by 1.
|
int |
previous()
Returns previous UTF16 character and decrements the iterator's
currentIndex by 1.
|
void |
setIndex(int currentIndex)
Sets the currentIndex to the specified currentIndex in the text and
returns that single UTF16 character at currentIndex.
|
void |
setText(String text)
Reset this iterator to point to a new string.
|
currentCodePoint, getCharacterIterator, getInstance, getInstance, getInstance, getInstance, getInstance, getInstance, getText, moveCodePointIndex, moveIndex, nextCodePoint, previousCodePoint, setToLimit, setToStartpublic StringUCharacterIterator(String str)
str - text which the iterator will be based onpublic StringUCharacterIterator()
public Object clone()
Stringobjectclone in class UCharacterIteratorpublic int current()
current in class UCharacterIteratorpublic int getLength()
getLength in class UCharacterIteratorpublic int getIndex()
getIndex in class UCharacterIteratorpublic int next()
next in interface UForwardCharacterIteratornext in class UCharacterIteratorpublic int previous()
previous in class UCharacterIteratorpublic void setIndex(int currentIndex)
throws IndexOutOfBoundsException
Sets the currentIndex to the specified currentIndex in the text and returns that single UTF16 character at currentIndex. This assumes the text is stored as 16-bit code units.
setIndex in class UCharacterIteratorcurrentIndex - the currentIndex within the text.IndexOutOfBoundsException - is thrown if an invalid currentIndex
is supplied. i.e. currentIndex is out of bounds.public int getText(char[] fillIn,
int offset)
getLength()Usage:
UChacterIterator iter = new UCharacterIterator.getInstance(text);
char[] buf = new char[iter.getLength()];
iter.getText(buf);
OR
char[] buf= new char[1];
int len = 0;
for(;;){
try{
len = iter.getText(buf);
break;
}catch(IndexOutOfBoundsException e){
buf = new char[iter.getLength()];
}
}
getText in class UCharacterIteratorfillIn - an array of chars to fill with the underlying UTF-16 code
units.offset - the position within the array to start putting the data.IndexOutOfBoundsException - exception if there is not enough
room after offset in the array, or if offset < 0.public String getText()
getText in class UCharacterIteratorpublic void setText(String text)
text - The String to be iterated over