Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Header Files   Compound Members   File Members  

CharacterIterator Class Reference

Abstract class defining a protcol for accessing characters in a text-storage object. More...

#include <chariter.h>

Class diagram for CharacterIterator:

UCharCharacterIterator StringCharacterIterator

List of all members.


Public Members

virtual ~CharacterIterator ()
Destructor. More...

virtual bool_t operator== (const CharacterIterator& that) const = 0
Returns true when both iterators refer to the same character in the same character-storage object. More...

bool_t operator!= (const CharacterIterator& that) const
Returns true when the iterators refer to different text-storage objects, or to different characters in the same text-storage object. More...

virtual CharacterIterator* clone (void) const = 0
Returns a pointer to a new CharacterIterator of the same concrete class as this one, and referring to the same character in the same text-storage object as this one. More...

virtual int32_t hashCode (void) const = 0
Generates a hash code for this iterator. More...

virtual UChar first (void) = 0
Sets the iterator to refer to the first character in its iteration range, and returns that character,. More...

virtual UChar last (void) = 0
Sets the iterator to refer to the last character in its iteration range, and returns that character. More...

virtual UChar setIndex (UTextOffset position) = 0
Sets the iterator to refer to the "position"-th character in the text-storage object the iterator refers to, and returns that character. More...

virtual UChar current (void) const = 0
Returns the character the iterator currently refers to. More...

virtual UChar next (void) = 0
Advances to the next character in the iteration range (toward last()), and returns that character. More...

virtual UChar previous (void) = 0
Advances to the previous character in the iteration rance (toward first()), and returns that character. More...

virtual UTextOffset startIndex (void) const = 0
Returns the numeric index in the underlying text-storage object of the character returned by first(). More...

virtual UTextOffset endIndex (void) const = 0
Returns the numeric index in the underlying text-storage object of the position immediately BEYOND the character returned by last(). More...

virtual UTextOffset getIndex (void) const = 0
Returns the numeric index in the underlying text-storage object of the character the iterator currently refers to (i.e., the character returned by current()). More...

virtual void getText (UnicodeString& result) = 0
Copies the text under iteration into the UnicodeString referred to by "result". More...

virtual UClassID getDynamicClassID (void) const = 0
Returns a UClassID for this CharacterIterator ("poor man's RTTI").

Despite the fact that this function is public, DO NOT CONSIDER IT PART OF CHARACTERITERATOR'S API! More...


Static Public Members

const UChar DONE
Value returned by most of CharacterIterator's functions when the iterator has reached the limits of its iteration.


Protected Members

 CharacterIterator ()
 CharacterIterator (const CharacterIterator&)
CharacterIterator& operator= (const CharacterIterator&)

Detailed Description

Abstract class defining a protcol for accessing characters in a text-storage object.

Examples:

Function processing characters, in this example simple output

    .   void processChar( UChar c )
    .   {
    .       cout &lt;&lt; " " &lt;&lt; c;
    .   }
    
Traverse the text from start to finish
 
    .   void traverseForward(CharacterIterator& iter)
    .   {
    .       for(UChar c = iter.first(); c != CharacterIterator.DONE; c = iter.next()) {
    .           processChar(c);
    .       }
    .   }
    
Traverse the text backwards, from end to start
    .   void traverseBackward(CharacterIterator& iter)
    .   {
    .       for(UChar 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.
    .   void traverseOut(CharacterIterator& iter, UTextOffset pos)
    .   {
    .       UChar c;
    .       for (c = iter.setIndex(pos);
    .       c != CharacterIterator.DONE && (Unicode::isLetter(c) || Unicode::isDigit(c));
    .           c = iter.next()) {}
    .       UTextOffset end = iter.getIndex();
    .       for (c = iter.setIndex(pos);
    .           c != CharacterIterator.DONE && (Unicode::isLetter(c) || Unicode::isDigit(c));
    .           c = iter.previous()) {}
    .       UTextOffset start = iter.getIndex() + 1;
    .   
    .       cout &lt;&lt; "start: " &lt;&lt; start &lt;&lt; " end: " &lt;&lt; end &lt;&lt; endl;
    .       for (c = iter.setIndex(start); iter.getIndex() &lt; end; c = iter.next() ) {
    .           processChar(c);
    .       }
    .    }
    
Creating a StringCharacterIteratorand calling the test functions
    .    void CharacterIterator_Example( void )
    .    {
    .        cout &lt;&lt; endl &lt;&lt; "===== CharacterIterator_Example: =====" &lt;&lt; endl;
    .        UnicodeString text("Ein kleiner Satz.");
    .        StringCharacterIterator iterator(text);
    .        cout &lt;&lt; "----- traverseForward: -----------" &lt;&lt; endl;
    .        traverseForward( iterator );
    .        cout &lt;&lt; endl &lt;&lt; endl &lt;&lt; "----- traverseBackward: ----------" &lt;&lt; endl;
    .        traverseBackward( iterator );
    .        cout &lt;&lt; endl &lt;&lt; endl &lt;&lt; "----- traverseOut: ---------------" &lt;&lt; endl;
    .        traverseOut( iterator, 7 );
    .        cout &lt;&lt; endl &lt;&lt; endl &lt;&lt; "-----" &lt;&lt; endl;
    .    }
    

Member Function Documentation

virtual CharacterIterator::~CharacterIterator () [virtual]

Destructor.

Stable:

virtual bool_t CharacterIterator::operator== (const CharacterIterator & that) const [pure virtual]

Returns true when both iterators refer to the same character in the same character-storage object.

Stable:

Reimplemented in StringCharacterIterator, and UCharCharacterIterator.

bool_t CharacterIterator::operator!= (const CharacterIterator & that) const [inline]

Returns true when the iterators refer to different text-storage objects, or to different characters in the same text-storage object.

Stable:

virtual CharacterIterator * CharacterIterator::clone (void) const [pure virtual]

Returns a pointer to a new CharacterIterator of the same concrete class as this one, and referring to the same character in the same text-storage object as this one.

The caller is responsible for deleting the new clone.

Stable:

Reimplemented in StringCharacterIterator, and UCharCharacterIterator.

virtual int32_t CharacterIterator::hashCode (void) const [pure virtual]

Generates a hash code for this iterator.

Stable:

Reimplemented in StringCharacterIterator, and UCharCharacterIterator.

virtual UChar CharacterIterator::first (void) [pure virtual]

Sets the iterator to refer to the first character in its iteration range, and returns that character,.

Draft:

Reimplemented in StringCharacterIterator, and UCharCharacterIterator.

virtual UChar CharacterIterator::last (void) [pure virtual]

Sets the iterator to refer to the last character in its iteration range, and returns that character.

Draft:

Reimplemented in StringCharacterIterator, and UCharCharacterIterator.

virtual UChar CharacterIterator::setIndex (UTextOffset pos) [pure virtual]

Sets the iterator to refer to the "position"-th character in the text-storage object the iterator refers to, and returns that character.

Draft:

Reimplemented in StringCharacterIterator, and UCharCharacterIterator.

virtual UChar CharacterIterator::current (void) const [pure virtual]

Returns the character the iterator currently refers to.

Draft:

Reimplemented in StringCharacterIterator, and UCharCharacterIterator.

virtual UChar CharacterIterator::next (void) [pure virtual]

Advances to the next character in the iteration range (toward last()), and returns that character.

If there are no more characters to return, returns DONE.

Draft:

Reimplemented in StringCharacterIterator, and UCharCharacterIterator.

virtual UChar CharacterIterator::previous (void) [pure virtual]

Advances to the previous character in the iteration rance (toward first()), and returns that character.

If there are no more characters to return, returns DONE.

Draft:

Reimplemented in StringCharacterIterator, and UCharCharacterIterator.

virtual UTextOffset CharacterIterator::startIndex (void) const [pure virtual]

Returns the numeric index in the underlying text-storage object of the character returned by first().

Since it's possible to create an iterator that iterates across only part of a text-storage object, this number isn't necessarily 0.

Stable:

Reimplemented in StringCharacterIterator, and UCharCharacterIterator.

virtual UTextOffset CharacterIterator::endIndex (void) const [pure virtual]

Returns the numeric index in the underlying text-storage object of the position immediately BEYOND the character returned by last().

Stable:

Reimplemented in StringCharacterIterator, and UCharCharacterIterator.

virtual UTextOffset CharacterIterator::getIndex (void) const [pure virtual]

Returns the numeric index in the underlying text-storage object of the character the iterator currently refers to (i.e., the character returned by current()).

Stable:

Reimplemented in StringCharacterIterator, and UCharCharacterIterator.

virtual void CharacterIterator::getText (UnicodeString & result) [pure virtual]

Copies the text under iteration into the UnicodeString referred to by "result".

Parameters:
result   Receives a copy of the text under iteration.
Stable:

Reimplemented in StringCharacterIterator, and UCharCharacterIterator.

virtual UClassID CharacterIterator::getDynamicClassID (void) const [pure virtual]

Returns a UClassID for this CharacterIterator ("poor man's RTTI").

Despite the fact that this function is public, DO NOT CONSIDER IT PART OF CHARACTERITERATOR'S API!

Stable:

Reimplemented in StringCharacterIterator, and UCharCharacterIterator.

CharacterIterator::CharacterIterator () [inline, protected]

CharacterIterator::CharacterIterator (const CharacterIterator &) [inline, protected]

CharacterIterator & CharacterIterator::operator= (const CharacterIterator &) [inline, protected]


Member Data Documentation

const UChar CharacterIterator::DONE [static]

Value returned by most of CharacterIterator's functions when the iterator has reached the limits of its iteration.


The documentation for this class was generated from the following file:
Generated at Thu Feb 10 15:30:28 2000 for icu by doxygen 1.0.0 written by Dimitri van Heesch, © 1997-1999