Package com.ibm.icu.text
Class UCharacterIterator
- java.lang.Object
-
- com.ibm.icu.text.UCharacterIterator
-
- All Implemented Interfaces:
UForwardCharacterIterator,Cloneable
public abstract class UCharacterIterator extends Object implements Cloneable, UForwardCharacterIterator
Abstract class that defines an API for iteration on text objects.This is an interface for forward and backward iteration and random access into a text object. Forward iteration is done with post-increment and backward iteration is done with pre-decrement semantics, while thejava.text.CharacterIteratorinterface methods provided forward iteration with "pre-increment" and backward iteration with pre-decrement semantics. This API is more efficient for forward iteration over code points. The other major difference is that this API can do both code unit and code point iteration,java.text.CharacterIteratorcan only iterate over code units and is limited to BMP (0 - 0xFFFF)- Author:
- Ram
- Status:
- Stable ICU 2.4.
-
-
Field Summary
-
Fields inherited from interface com.ibm.icu.text.UForwardCharacterIterator
DONE
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedUCharacterIterator()Protected default constructor for the subclasses
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description UCharacterIteratorclone()Creates a copy of this iterator, independent from other iterators.abstract intcurrent()Returns the code unit at the current index.intcurrentCodePoint()Returns the codepoint at the current index.CharacterIteratorgetCharacterIterator()Returns ajava.text.CharacterIteratorobject for the underlying text of this iterator.abstract intgetIndex()Gets the current index in text.static UCharacterIteratorgetInstance(char[] source)Returns aUCharacterIteratorobject given a source character array.static UCharacterIteratorgetInstance(char[] source, int start, int limit)Returns aUCharacterIteratorobject given a source character array.static UCharacterIteratorgetInstance(Replaceable source)Returns aUCharacterIteratorobject given aReplaceableobject.static UCharacterIteratorgetInstance(String source)Returns aUCharacterIteratorobject given a source string.static UCharacterIteratorgetInstance(StringBuffer source)Returns aUCharacterIteratorobject given a source StringBuffer.static UCharacterIteratorgetInstance(CharacterIterator source)Returns aUCharacterIteratorobject given a CharacterIterator.abstract intgetLength()Returns the length of the textStringgetText()Convenience method for returning the underlying text storage as as stringintgetText(char[] fillIn)Convenience override forgetText(char[], int)that provides an offset of 0.abstract intgetText(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.intmoveCodePointIndex(int delta)Moves the current position by the number of code points specified, either forward or backward depending on the sign of delta (positive or negative respectively).intmoveIndex(int delta)Moves the current position by the number of code units specified, either forward or backward depending on the sign of delta (positive or negative respectively).abstract intnext()Returns the UTF16 code unit at index, and increments to the next code unit (post-increment semantics).intnextCodePoint()Returns the code point at index, and increments to the next code point (post-increment semantics).abstract intprevious()Decrement to the position of the previous code unit in the text, and return it (pre-decrement semantics).intpreviousCodePoint()Retreat to the start of the previous code point in the text, and return it (pre-decrement semantics).abstract voidsetIndex(int index)Sets the index to the specified index in the text.voidsetToLimit()Sets the current index to the limit.voidsetToStart()Sets the current index to the start.
-
-
-
Method Detail
-
getInstance
public static final UCharacterIterator getInstance(Replaceable source)
Returns aUCharacterIteratorobject given aReplaceableobject.- Parameters:
source- a valid source as aReplaceableobject- Returns:
- UCharacterIterator object
- Throws:
IllegalArgumentException- if the argument is null- Status:
- Stable ICU 2.4.
-
getInstance
public static final UCharacterIterator getInstance(String source)
Returns aUCharacterIteratorobject given a source string.- Parameters:
source- a string- Returns:
- UCharacterIterator object
- Throws:
IllegalArgumentException- if the argument is null- Status:
- Stable ICU 2.4.
-
getInstance
public static final UCharacterIterator getInstance(char[] source)
Returns aUCharacterIteratorobject given a source character array.- Parameters:
source- an array of UTF-16 code units- Returns:
- UCharacterIterator object
- Throws:
IllegalArgumentException- if the argument is null- Status:
- Stable ICU 2.4.
-
getInstance
public static final UCharacterIterator getInstance(char[] source, int start, int limit)
Returns aUCharacterIteratorobject given a source character array.- Parameters:
source- an array of UTF-16 code units- Returns:
- UCharacterIterator object
- Throws:
IllegalArgumentException- if the argument is null- Status:
- Stable ICU 2.4.
-
getInstance
public static final UCharacterIterator getInstance(StringBuffer source)
Returns aUCharacterIteratorobject given a source StringBuffer.- Parameters:
source- an string buffer of UTF-16 code units- Returns:
- UCharacterIterator object
- Throws:
IllegalArgumentException- if the argument is null- Status:
- Stable ICU 2.4.
-
getInstance
public static final UCharacterIterator getInstance(CharacterIterator source)
Returns aUCharacterIteratorobject given a CharacterIterator.- Parameters:
source- a valid CharacterIterator object.- Returns:
- UCharacterIterator object
- Throws:
IllegalArgumentException- if the argument is null- Status:
- Stable ICU 2.4.
-
getCharacterIterator
public CharacterIterator getCharacterIterator()
Returns ajava.text.CharacterIteratorobject for the underlying text of this iterator. The returned iterator is independent of this iterator.- Returns:
- java.text.CharacterIterator object
- Status:
- Stable ICU 2.4.
-
current
public abstract int current()
Returns the code unit at the current index. If index is out of range, returns DONE. Index is not changed.- Returns:
- current code unit
- Status:
- Stable ICU 2.4.
-
currentCodePoint
public int currentCodePoint()
Returns the codepoint at the current index. If the current index is invalid, DONE is returned. If the current index points to a lead surrogate, and there is a following trail surrogate, then the code point is returned. Otherwise, the code unit at index is returned. Index is not changed.- Returns:
- current codepoint
- Status:
- Stable ICU 2.4.
-
getLength
public abstract int getLength()
Returns the length of the text- Returns:
- length of the text
- Status:
- Stable ICU 2.4.
-
getIndex
public abstract int getIndex()
Gets the current index in text.- Returns:
- current index in text.
- Status:
- Stable ICU 2.4.
-
next
public abstract int next()
Returns the UTF16 code unit at index, and increments to the next code unit (post-increment semantics). If index is out of range, DONE is returned, and the iterator is reset to the limit of the text.- Specified by:
nextin interfaceUForwardCharacterIterator- Returns:
- the next UTF16 code unit, or DONE if the index is at the limit of the text.
- Status:
- Stable ICU 2.4.
-
nextCodePoint
public int nextCodePoint()
Returns the code point at index, and increments to the next code point (post-increment semantics). If index does not point to a valid surrogate pair, the behavior is the same asnext(). Otherwise the iterator is incremented past the surrogate pair, and the code point represented by the pair is returned.- Specified by:
nextCodePointin interfaceUForwardCharacterIterator- Returns:
- the next codepoint in text, or DONE if the index is at the limit of the text.
- Status:
- Stable ICU 2.4.
-
previous
public abstract int previous()
Decrement to the position of the previous code unit in the text, and return it (pre-decrement semantics). If the resulting index is less than 0, the index is reset to 0 and DONE is returned.- Returns:
- the previous code unit in the text, or DONE if the new index is before the start of the text.
- Status:
- Stable ICU 2.4.
-
previousCodePoint
public int previousCodePoint()
Retreat to the start of the previous code point in the text, and return it (pre-decrement semantics). If the index is not preceded by a valid surrogate pair, the behavior is the same asprevious(). Otherwise the iterator is decremented to the start of the surrogate pair, and the code point represented by the pair is returned.- Returns:
- the previous code point in the text, or DONE if the new index is before the start of the text.
- Status:
- Stable ICU 2.4.
-
setIndex
public abstract void setIndex(int index)
Sets the index to the specified index in the text.- Parameters:
index- the index within the text.- Throws:
IndexOutOfBoundsException- is thrown if an invalid index is supplied- Status:
- Stable ICU 2.4.
-
setToLimit
public void setToLimit()
Sets the current index to the limit.- Status:
- Stable ICU 2.4.
-
setToStart
public void setToStart()
Sets the current index to the start.- Status:
- Stable ICU 2.4.
-
getText
public abstract 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()]; } }- 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.- Status:
- Stable ICU 2.4.
-
getText
public final int getText(char[] fillIn)
Convenience override forgetText(char[], int)that provides an offset of 0.- Parameters:
fillIn- an array of chars to fill with the underlying UTF-16 code units.- Returns:
- the number of code units added to fillIn, as a convenience
- Throws:
IndexOutOfBoundsException- exception if there is not enough room in the array.- Status:
- Stable ICU 2.4.
-
getText
public String getText()
Convenience method for returning the underlying text storage as as string- Returns:
- the underlying text storage in the iterator as a string
- Status:
- Stable ICU 2.4.
-
moveIndex
public int moveIndex(int delta)
Moves the current position by the number of code units specified, either forward or backward depending on the sign of delta (positive or negative respectively). If the resulting index would be less than zero, the index is set to zero, and if the resulting index would be greater than limit, the index is set to limit.- Parameters:
delta- the number of code units to move the current index.- Returns:
- the new index.
- Throws:
IndexOutOfBoundsException- is thrown if an invalid index is supplied- Status:
- Stable ICU 2.4.
-
moveCodePointIndex
public int moveCodePointIndex(int delta)
Moves the current position by the number of code points specified, either forward or backward depending on the sign of delta (positive or negative respectively). If the current index is at a trail surrogate then the first adjustment is by code unit, and the remaining adjustments are by code points. If the resulting index would be less than zero, the index is set to zero, and if the resulting index would be greater than limit, the index is set to limit.- Parameters:
delta- the number of code units to move the current index.- Returns:
- the new index
- Throws:
IndexOutOfBoundsException- is thrown if an invalid delta is supplied- Status:
- Stable ICU 2.4.
-
clone
public UCharacterIterator clone() throws CloneNotSupportedException
Creates a copy of this iterator, independent from other iterators. If it is not possible to clone the iterator, returns null.- Overrides:
clonein classObject- Returns:
- copy of this iterator
- Throws:
CloneNotSupportedException- Status:
- Stable ICU 2.4.
-
-