java::text::CharacterIterator Class Reference

Inheritance diagram for java::text::CharacterIterator:

Inheritance graph
java::text::AttributedCharacterIteratorjava::lang::Interfacejava::lang::Object
[legend]
Collaboration diagram for java::text::CharacterIterator:

Collaboration graph
java::lang::Interfacejava::lang::Object
[legend]

List of all members.


Detailed Description

This interface defines a protocol for bidirectional iteration over text.

The iterator iterates over a bounded sequence of characters. Characters are indexed with values beginning with the value returned by getBeginIndex() and continuing through the value returned by getEndIndex()-1.

Iterators maintain a current character index, whose valid range is from getBeginIndex() to getEndIndex(); the value getEndIndex() is included to allow handling of zero-length text ranges and for historical reasons. The current index can be retrieved by calling getIndex() and set directly by calling setIndex(), first(), and last().

The methods previous() and next() are used for iteration. They return DONE if they would move outside the range from getBeginIndex() to getEndIndex() -1, signaling that the iterator has reached the end of the sequence. DONE is also returned by other methods to indicate that the current index is outside this range.

Examples:

Traverse the text from start to finish

 public void traverseForward(CharacterIterator iter) {
     for(char c = iter.first(); c != CharacterIterator.DONE; c = iter.next()) {
         processChar(c);
     }
 }
 

Traverse the text backwards, from end to start

 public void traverseBackward(CharacterIterator iter) {
     for(char c = iter.last(); c != CharacterIterator.DONE; c = iter.previous()) {
         processChar(c);
     }
 }
 

Traverse both forward and backward from a given position in the text. Calls to notBoundary() in this example represents some additional stopping criteria.

 public void traverseOut(CharacterIterator iter, int pos) {
     for (char c = iter.setIndex(pos);
              c != CharacterIterator.DONE && notBoundary(c);
              c = iter.next()) {
     }
     int end = iter.getIndex();
     for (char c = iter.setIndex(pos);
             c != CharacterIterator.DONE && notBoundary(c);
             c = iter.previous()) {
     }
     int start = iter.getIndex();
     processSection(start, end);
 }
 

See also:
StringCharacterIterator

AttributedCharacterIterator


Public Member Functions

virtual jchar first ()=0
 Sets the position to getBeginIndex() and returns the character at that position.
virtual jchar last ()=0
 Sets the position to getEndIndex()-1 (getEndIndex() if the text is empty) and returns the character at that position.
virtual jchar current () const =0
 Gets the character at the current position (as returned by getIndex()).
virtual jchar next ()=0
 Increments the iterator's index by one and returns the character at the new index.
virtual jchar previous ()=0
 Decrements the iterator's index by one and returns the character at the new index.
virtual jchar setIndex (int position)=0
 Sets the position to the specified position in the text and returns that character.
virtual jint getBeginIndex () const =0
 Returns the start index of the text.
virtual jint getEndIndex () const =0
 Returns the end index of the text.
virtual jint getIndex () const =0
 Returns the current index.

Static Public Attributes

static const jchar DONE
 Constant that is returned when the iterator has reached either the end or the beginning of the text.

Member Function Documentation

virtual jchar java::text::CharacterIterator::first (  )  [pure virtual]

Sets the position to getBeginIndex() and returns the character at that position.

Returns:
the first character in the text, or DONE if the text is empty
See also:
getBeginIndex()

virtual jchar java::text::CharacterIterator::last (  )  [pure virtual]

Sets the position to getEndIndex()-1 (getEndIndex() if the text is empty) and returns the character at that position.

Returns:
the last character in the text, or DONE if the text is empty
See also:
getEndIndex()

virtual jchar java::text::CharacterIterator::current (  )  const [pure virtual]

Gets the character at the current position (as returned by getIndex()).

Returns:
the character at the current position or DONE if the current position is off the end of the text.
See also:
getIndex()

virtual jchar java::text::CharacterIterator::next (  )  [pure virtual]

Increments the iterator's index by one and returns the character at the new index.

If the resulting index is greater or equal to getEndIndex(), the current index is reset to getEndIndex() and a value of DONE is returned.

Returns:
the character at the new position or DONE if the new position is off the end of the text range.

virtual jchar java::text::CharacterIterator::previous (  )  [pure virtual]

Decrements the iterator's index by one and returns the character at the new index.

If the current index is getBeginIndex(), the index remains at getBeginIndex() and a value of DONE is returned.

Returns:
the character at the new position or DONE if the current position is equal to getBeginIndex().

virtual jchar java::text::CharacterIterator::setIndex ( int  position  )  [pure virtual]

Sets the position to the specified position in the text and returns that character.

Parameters:
position the position within the text. Valid values range from getBeginIndex() to getEndIndex(). An IllegalArgumentException is thrown if an invalid value is supplied.
Returns:
the character at the specified position or DONE if the specified position is equal to getEndIndex()

virtual jint java::text::CharacterIterator::getBeginIndex (  )  const [pure virtual]

Returns the start index of the text.

Returns:
the index at which the text begins.

virtual jint java::text::CharacterIterator::getEndIndex (  )  const [pure virtual]

Returns the end index of the text.

This index is the index of the first character following the end of the text.

Returns:
the index after the last character in the text

virtual jint java::text::CharacterIterator::getIndex (  )  const [pure virtual]

Returns the current index.

Returns:
the current index.


Member Data Documentation

const jchar java::text::CharacterIterator::DONE [static]

Constant that is returned when the iterator has reached either the end or the beginning of the text.

The value is '\uFFFF', the "not a character" value which should not occur in any valid Unicode string.


The documentation for this class was generated from the following file:
Generated on Fri May 16 11:56:45 2008 for CrossPlatformJavaLikeC++API by  doxygen 1.5.3