public abstract class UCharacterIterator extends Object implements Cloneable, UForwardCharacterIterator
java.text.CharacterIterator
interface 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.CharacterIterator
can only iterate over
code units and is limited to BMP (0 - 0xFFFF)DONE
Modifier | Constructor and Description |
---|---|
protected |
UCharacterIterator()
Protected default constructor for the subclasses
|
Modifier and Type | Method and Description |
---|---|
Object |
clone()
Creates a copy of this iterator, independent from other iterators.
|
abstract int |
current()
Returns the code unit at the current index.
|
int |
currentCodePoint()
Returns the codepoint at the current index.
|
CharacterIterator |
getCharacterIterator()
Returns a
java.text.CharacterIterator object for
the underlying text of this iterator. |
abstract int |
getIndex()
Gets the current index in text.
|
static UCharacterIterator |
getInstance(char[] source)
Returns a
UCharacterIterator object given a
source character array. |
static UCharacterIterator |
getInstance(char[] source,
int start,
int limit)
Returns a
UCharacterIterator object given a
source character array. |
static UCharacterIterator |
getInstance(CharacterIterator source)
Returns a
UCharacterIterator object given a
CharacterIterator. |
static UCharacterIterator |
getInstance(Replaceable source)
Returns a
UCharacterIterator object given a
Replaceable object. |
static UCharacterIterator |
getInstance(String source)
Returns a
UCharacterIterator object given a
source string. |
static UCharacterIterator |
getInstance(StringBuffer source)
Returns a
UCharacterIterator object given a
source StringBuffer. |
abstract 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)
Convenience override for
getText(char[], int) that provides
an offset of 0. |
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.
|
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).
|
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).
|
abstract int |
next()
Returns the UTF16 code unit at index, and increments to the next
code unit (post-increment semantics).
|
int |
nextCodePoint()
Returns the code point at index, and increments to the next code
point (post-increment semantics).
|
abstract int |
previous()
Decrement to the position of the previous code unit in the
text, and return it (pre-decrement semantics).
|
int |
previousCodePoint()
Retreat to the start of the previous code point in the text,
and return it (pre-decrement semantics).
|
abstract void |
setIndex(int index)
Sets the index to the specified index in the text.
|
void |
setToLimit()
Sets the current index to the limit.
|
void |
setToStart()
Sets the current index to the start.
|
protected UCharacterIterator()
public static final UCharacterIterator getInstance(Replaceable source)
UCharacterIterator
object given a
Replaceable
object.source
- a valid source as a Replaceable
objectIllegalArgumentException
- if the argument is nullpublic static final UCharacterIterator getInstance(String source)
UCharacterIterator
object given a
source string.source
- a stringIllegalArgumentException
- if the argument is nullpublic static final UCharacterIterator getInstance(char[] source)
UCharacterIterator
object given a
source character array.source
- an array of UTF-16 code unitsIllegalArgumentException
- if the argument is nullpublic static final UCharacterIterator getInstance(char[] source, int start, int limit)
UCharacterIterator
object given a
source character array.source
- an array of UTF-16 code unitsIllegalArgumentException
- if the argument is nullpublic static final UCharacterIterator getInstance(StringBuffer source)
UCharacterIterator
object given a
source StringBuffer.source
- an string buffer of UTF-16 code unitsIllegalArgumentException
- if the argument is nullpublic static final UCharacterIterator getInstance(CharacterIterator source)
UCharacterIterator
object given a
CharacterIterator.source
- a valid CharacterIterator object.IllegalArgumentException
- if the argument is nullpublic CharacterIterator getCharacterIterator()
java.text.CharacterIterator
object for
the underlying text of this iterator. The returned iterator is
independent of this iterator.public abstract int current()
public int currentCodePoint()
public abstract int getLength()
public abstract int getIndex()
public abstract int next()
next
in interface UForwardCharacterIterator
public int nextCodePoint()
next()
. Otherwise the iterator is incremented past
the surrogate pair, and the code point represented by the pair
is returned.nextCodePoint
in interface UForwardCharacterIterator
public abstract int previous()
public int previousCodePoint()
previous()
. Otherwise the iterator is
decremented to the start of the surrogate pair, and the code
point represented by the pair is returned.public abstract void setIndex(int index)
index
- the index within the text.IndexOutOfBoundsException
- is thrown if an invalid index is
suppliedpublic void setToLimit()
public void setToStart()
public abstract 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()]; } }
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.IndexOutOfBoundsException
- exception if there is not enough
room after offset in the array, or if offset < 0.public final int getText(char[] fillIn)
getText(char[], int)
that provides
an offset of 0.fillIn
- an array of chars to fill with the underlying UTF-16 code
units.IndexOutOfBoundsException
- exception if there is not enough
room in the array.public String getText()
public int moveIndex(int delta)
delta
- the number of code units to move the current
index.IndexOutOfBoundsException
- is thrown if an invalid index is
suppliedpublic int moveCodePointIndex(int delta)
delta
- the number of code units to move the current index.IndexOutOfBoundsException
- is thrown if an invalid delta is
suppliedpublic Object clone() throws CloneNotSupportedException
clone
in class Object
CloneNotSupportedException
Copyright (c) 2016 IBM Corporation and others.