Iterating through Characters in an IText Object

The Unicode Text Framework provides a full set of classes for iterating over characters in an IText object. Use ITextIterator or IConstTextIterator to iterate forwards, or IReverseTextIterator or IConstReverseTextIterator to iterate backwards through the characters in an IText object. You can also use IFastTextIterator when you want faster performance and don't need as many safety checking mechanisms to guarantee the validity of the iterator.

To use a text iterator:

  1. Call IText::begin (or other IText iterator functions as appropriate) to instantiate the iterator.
  2. Use the iterator operators ++ and -- to iterate forwards and backwards through the characters.

For example, this code shows how to use an iterator to strip whitespace characters from the beginning of a text object called someText:

ITextIterator iter;

// IUnicode::isASpace(*iter) checks whether the character 
currently pointed

// to by the iterator is a space character (a space, tab, and so 
on)

for (iter = someText.begin(); iter < someText.end() && 

		!IUnicode::isASpace(*iter); ++iter);

	someText.erase(someText.begin(), iter);