class U_COMMON_API CharacterIterator

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

Inheritance:


Public Fields

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

Public Methods

virtual ~CharacterIterator()
Destructor
virtual bool_t operator==(const CharacterIterator& that) const
Returns true when both iterators refer to the same character in the same character-storage object
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
virtual CharacterIterator* clone(void) const
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
virtual int32_t hashCode(void) const
Generates a hash code for this iterator
virtual UChar first(void)
Sets the iterator to refer to the first character in its iteration range, and returns that character,
virtual UChar last(void)
Sets the iterator to refer to the last character in its iteration range, and returns that character
virtual UChar setIndex(UTextOffset position)
Sets the iterator to refer to the "position"-th character in the text-storage object the iterator refers to, and returns that character
virtual UChar current(void) const
Returns the character the iterator currently refers to
virtual UChar next(void)
Advances to the next character in the iteration range (toward last()), and returns that character
virtual UChar previous(void)
Advances to the previous character in the iteration rance (toward first()), and returns that character
virtual UTextOffset startIndex(void) const
Returns the numeric index in the underlying text-storage object of the character returned by first()
virtual UTextOffset endIndex(void) const
Returns the numeric index in the underlying text-storage object of the position immediately BEYOND the character returned by last()
virtual UTextOffset getIndex(void) const
Returns the numeric index in the underlying text-storage object of the character the iterator currently refers to (i
virtual void getText(UnicodeString& result)
Copies the text under iteration into the UnicodeString referred to by "result"
virtual UClassID getDynamicClassID(void) const
Returns a UClassID for this CharacterIterator ("poor man's RTTI")

Documentation

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 << " " << 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 << "start: " << start << " end: " << end << endl;
.       for (c = iter.setIndex(start); iter.getIndex() < end; c = iter.next() ) {
.           processChar(c);
.       }
.    }
Creating a StringCharacterIteratorand calling the test functions
.    void CharacterIterator_Example( void )
.    {
.        cout << endl << "===== CharacterIterator_Example: =====" << endl;
.        UnicodeString text("Ein kleiner Satz.");
.        StringCharacterIterator iterator(text);
.        cout << "----- traverseForward: -----------" << endl;
.        traverseForward( iterator );
.        cout << endl << endl << "----- traverseBackward: ----------" << endl;
.        traverseBackward( iterator );
.        cout << endl << endl << "----- traverseOut: ---------------" << endl;
.        traverseOut( iterator, 7 );
.        cout << endl << endl << "-----" << endl;
.    }
static const UChar DONE
Value returned by most of CharacterIterator's functions when the iterator has reached the limits of its iteration.

virtual ~CharacterIterator()
Destructor.

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

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.

virtual CharacterIterator* clone(void) const
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.

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

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

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

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

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

virtual UChar next(void)
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.

virtual UChar previous(void)
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.

virtual UTextOffset startIndex(void) const
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.

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

virtual UTextOffset getIndex(void) const
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()).

virtual void getText(UnicodeString& result)
Copies the text under iteration into the UnicodeString referred to by "result". @param result Receives a copy of the text under iteration.

virtual UClassID getDynamicClassID(void) const
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!


Direct child classes:
UCharCharacterIterator
StringCharacterIterator

alphabetic index hierarchy of classes


this page has been generated automatically by doc++

(c)opyright by Malte Zöckler, Roland Wunderling
contact: doc++@zib.de