Package com.ibm.icu.impl
Class StringUCharacterIterator
- java.lang.Object
-
- com.ibm.icu.text.UCharacterIterator
-
- com.ibm.icu.impl.StringUCharacterIterator
-
- All Implemented Interfaces:
UForwardCharacterIterator,Cloneable
public final class StringUCharacterIterator extends UCharacterIterator
Used by Collation. UCharacterIterator on Strings. Can't use ReplaceableUCharacterIterator because it is not easy to do a fast setText.
-
-
Field Summary
-
Fields inherited from interface com.ibm.icu.text.UForwardCharacterIterator
DONE
-
-
Constructor Summary
Constructors Constructor Description StringUCharacterIterator()Public default constructorStringUCharacterIterator(String str)Public constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Objectclone()Creates a copy of this iterator, does not clone the underlyingStringobjectintcurrent()Returns the current UTF16 character.intgetIndex()Gets the current currentIndex in text.intgetLength()Returns the length of the textStringgetText()Convenience method for returning the underlying text storage as as stringintgetText(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.intnext()Returns next UTF16 character and increments the iterator's currentIndex by 1.intprevious()Returns previous UTF16 character and decrements the iterator's currentIndex by 1.voidsetIndex(int currentIndex)Sets the currentIndex to the specified currentIndex in the text and returns that single UTF16 character at currentIndex.voidsetText(String text)Reset this iterator to point to a new string.-
Methods inherited from class com.ibm.icu.text.UCharacterIterator
currentCodePoint, getCharacterIterator, getInstance, getInstance, getInstance, getInstance, getInstance, getInstance, getText, moveCodePointIndex, moveIndex, nextCodePoint, previousCodePoint, setToLimit, setToStart
-
-
-
-
Constructor Detail
-
StringUCharacterIterator
public StringUCharacterIterator(String str)
Public constructor- Parameters:
str- text which the iterator will be based on
-
StringUCharacterIterator
public StringUCharacterIterator()
Public default constructor
-
-
Method Detail
-
clone
public Object clone()
Creates a copy of this iterator, does not clone the underlyingStringobject- Overrides:
clonein classUCharacterIterator- Returns:
- copy of this iterator
-
current
public int current()
Returns the current UTF16 character.- Specified by:
currentin classUCharacterIterator- Returns:
- current UTF16 character
-
getLength
public int getLength()
Returns the length of the text- Specified by:
getLengthin classUCharacterIterator- Returns:
- length of the text
-
getIndex
public int getIndex()
Gets the current currentIndex in text.- Specified by:
getIndexin classUCharacterIterator- Returns:
- current currentIndex in text.
-
next
public int next()
Returns next UTF16 character and increments the iterator's currentIndex by 1. If the resulting currentIndex is greater or equal to the text length, the currentIndex is reset to the text length and a value of DONE is returned.- Specified by:
nextin interfaceUForwardCharacterIterator- Specified by:
nextin classUCharacterIterator- Returns:
- next UTF16 character in text or DONE if the new currentIndex is off the end of the text range.
-
previous
public int previous()
Returns previous UTF16 character and decrements the iterator's currentIndex by 1. If the resulting currentIndex is less than 0, the currentIndex is reset to 0 and a value of DONE is returned.- Specified by:
previousin classUCharacterIterator- Returns:
- next UTF16 character in text or DONE if the new currentIndex is off the start of the text range.
-
setIndex
public void setIndex(int currentIndex) throws IndexOutOfBoundsExceptionSets 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.
- Specified by:
setIndexin classUCharacterIterator- Parameters:
currentIndex- the currentIndex within the text.- Throws:
IndexOutOfBoundsException- is thrown if an invalid currentIndex is supplied. i.e. currentIndex is out of bounds.
-
getText
public 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. The capacity of the fill in buffer should at least be equal to length of text in the iterator obtained by callinggetLength()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()]; } }- Specified by:
getTextin classUCharacterIterator- Parameters:
fillIn- an array of chars to fill with the underlying UTF-16 code units.offset- the position within the array to start putting the data.- Returns:
- the number of code units added to fillIn, as a convenience
- Throws:
IndexOutOfBoundsException- exception if there is not enough room after offset in the array, or if offset < 0.
-
getText
public String getText()
Convenience method for returning the underlying text storage as as string- Overrides:
getTextin classUCharacterIterator- Returns:
- the underlying text storage in the iterator as a string
-
setText
public void setText(String text)
Reset this iterator to point to a new string. This method is used by other classes that want to avoid allocating new ReplaceableCharacterIterator objects every time their setText method is called.- Parameters:
text- The String to be iterated over
-
-