Class: TCharacterIterator

Declaration: TextIterator.h

Taxonomy Categories:

Member Functions:


Interface Category:

API.

Inherits From:

None.

Inherited By:

None.

Purpose:

Iterates over just the character information in a text object. If you are interested in style information too, see class TTextIterator instead. During each iteration, clients are required to call IsValid before using the returned character information. Only use the returned information when IsValid returns true. Immediately after construction, clients must call either First, Last, or SetIteratorAt in order to initialize the iterator to a valid state.

Instantiation:

Allocate on the heap or the stack.

Deriving Classes:

This class is not designed for deriving.

Concurrency:

Not multithread safe.

Resource Use:

No special requirements.

Member Function: TCharacterIterator::IsValid

bool IsValid ()

Interface Category:

API.

Purpose:

Determines if the iterator is currently at a valid character position. Immediately after construction, the iterator is invalid until First, Last, or SetIteratorAt is called. A valid iterator becomes invalid when the current character is the first one and you decrement the character position. Similarly, a valid iterator becomes invalid when the current character position is the last one and you increment the character position.

Calling Context:

Call IsValid after calling First, Last, Next, Previous, or Current to determine if the returned character information is valid. Only call the functions that set the current character or get the current character and increment/decrement after first making certain the current character position is valid.

Parameters:

Return Value:

Returns true if the current character position is valid.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

An optimization technique is used internally that may be of interest to external clients with similar requirements for the fastest performance possible when iterating over large numbers of characters. Although calling IsValid is the only guaranteed way to verify the returned data from each iteration, calling this function for every iteration is not the fastest way to safely iterate over characters. When the iterator is in an invalid state, TUnicodeSpecial::kNull is the returned character value. However, you can't assume that because a TUnicodeSpecial::kNull was returned that the iterator is invalid. Rather, this character will occur rarely if at all within normal text objects. So, you can check for the TUnicodeSpecial::kNull and only call IsValid on the rare occasions that this character is returned. For most text objects, this will save many calls to IsValid.

Member Function: TCharacterIterator::SetIteratorAt

void SetIteratorAt (TTextIndex index)

Interface Category:

API.

Purpose:

Sets the current character position at the specified index.

Calling Context:

Call immediately after constructing an iterator to initialize it to a position other than the first or last character position. Also, call this member function to reposition the iterator when sequential iteration is not desired.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TCharacterIterator::ResyncAt

void ResyncAt (TTextIndex index, bool updateCaches =true)

Interface Category:

API.

Purpose:

Sets the current character position at the specified index and resynchronizes with the associated text object.

Calling Context:

Call this member function instead of SetIteratorAt when the associated text object was modified in some way other than the character setting member functions provided by the iterator.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TCharacterIterator::GetCurrentIndex

TTextIndex GetCurrentIndex ()

Interface Category:

API.

Purpose:

Gets the current character position of the iterator.

Calling Context:

Call when you want to know the current character position.

Parameters:

Return Value:

The TTextIndex representing the current character position.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

The returned index is only guaranteed to be valid if IsValid is called and returns true immediately before or after calling this function. Otherwise, it is possible the index returned is less than zero or greater than the last valid index for the associated text object.

Member Function: TCharacterIterator::First

  1. UniChar First ()
  2. void First (UniChar & ucode)

Interface Category:

API.

Purpose:

Sets the iterator to the first character position and returns the first character.

Calling Context:

  1. Call when you want to get the character as the return value.
  2. Call when you want to pass in your own character reference to be filled in.

Parameters:

Return Value:

  1. The first character of the associated text object.
  2. None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

The returned character will be invalid if the associated text object is empty. After calling this member function, you must call IsValid to determine if the returned character is a valid one.

Member Function: TCharacterIterator::Last

  1. UniChar Last ()
  2. void Last (UniChar & ucode)

Interface Category:

API.

Purpose:

Sets the iterator to the last character position and returns the last character.

Calling Context:

  1. Call when you want to get the character as the return value.
  2. Call when you want to pass in your own character reference to be filled in.

Parameters:

Return Value:

  1. The last character of the associated text object.
  2. None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

The returned character will be invalid if the associated text object is empty. After calling this member function, you must call IsValid to determine if the returned character is a valid one.

Member Function: TCharacterIterator::Current

  1. UniChar Current ()
  2. void Current (UniChar & ucode)

Interface Category:

API.

Purpose:

Gets the character at the current character position of the iterator.

Calling Context:

  1. Call when you want to get the character as the return value.
  2. Call when you want to pass in your own character reference to be filled in.

Parameters:

Return Value:

  1. The current character of the associated text object.
  2. None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

The returned character will be invalid if the current character position is beyond either end of the associated text object. Before or after calling this member function, you must call IsValid to determine the validity of the returned character.

Member Function: TCharacterIterator::CurrentAndIncrement

  1. UniChar CurrentAndIncrement ()
  2. void CurrentAndIncrement (UniChar & ucode)

Interface Category:

API.

Purpose:

Gets the character at the current character position and increments the iterator to the next character position.

Calling Context:

  1. Call when you want to get the character as the return value.
  2. Call when you want to pass in your own character reference to be filled in.

Parameters:

Return Value:

  1. The current character of the associated text object.
  2. None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

The returned character will be invalid if the current character position is beyond either end of the associated text object. Before calling this member function, you must call IsValid to determine if the returned character will be a valid one.

Member Function: TCharacterIterator::CurrentAndDecrement

  1. UniChar CurrentAndDecrement ()
  2. void CurrentAndDecrement (UniChar & ucode)

Interface Category:

API.

Purpose:

Gets the character at the current character position and decrement the iterator to the previous character position.

Calling Context:

  1. Call when you want to get the character as the return value.
  2. Call when you want to pass in your own character reference to be filled in.

Parameters:

Return Value:

  1. The current character of the associated text object.
  2. None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

The returned character will be invalid if the current character position is beyond either end of the associated text object. Before calling this member function, you must call IsValid to determine if the returned character will be a valid one.

Member Function: TCharacterIterator::Next

  1. UniChar Next ()
  2. void Next (UniChar & ucode)

Interface Category:

API.

Purpose:

Increments the iterator to the next character position and return the character at the new character position.

Calling Context:

  1. Call when you want to get the character as the return value.
  2. Call when you want to pass in your own character reference to be filled in.

Parameters:

Return Value:

  1. The next character of the associated text object.
  2. None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

The returned character will be invalid if the new character position is beyond the end of the associated text object. After calling this member function, you must call IsValid to determine if the returned character is a valid one.

Member Function: TCharacterIterator::Previous

  1. UniChar Previous ()
  2. void Previous (UniChar & ucode)

Interface Category:

API.

Purpose:

Decrements the iterator to the previous character position and return the character at the new character position.

Calling Context:

  1. Call when you want to get the character as the return value.
  2. Call when you want to pass in your own character reference to be filled in.

Parameters:

Return Value:

  1. The previous character of the associated text object.
  2. None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

The returned character will be invalid if the previous character position is before the beginning of the associated text object. After calling this member function, you must call IsValid to determine if the returned character is a valid one.

Member Function: TCharacterIterator::SetCurrent

void SetCurrent (UniChar newValue)

Interface Category:

API.

Purpose:

Set the character at the current character position.

Calling Context:

Call when you want to set the character at the current character position to a new character value.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

It doesn't make sense to set the current character unless the current character position is a valid one. Before attempting to set the current character, you should call IsValid to verify that the current character position is a valid one.

Member Function: TCharacterIterator::SetCurrentAndIncrement

void SetCurrentAndIncrement (UniChar newValue)

Interface Category:

API.

Purpose:

Set the current character and increments the iterator to the next character position.

Calling Context:

When you want to set multiple characters while sequentially iterating forward through the text, call this member function within a looping construct.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

It doesn't make sense to set the current character unless the current character position is a valid one. Before attempting to set the current character, you should call IsValid to verify that the current character position is a valid one.

Member Function: TCharacterIterator::SetCurrentAndDecrement

void SetCurrentAndDecrement (UniChar newValue)

Interface Category:

API.

Purpose:

Sets the current character and decrements the iterator to the previous character position.

Calling Context:

When you want to set multiple characters while sequentially iterating backward through the text, call this member function within a looping construct.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

It doesn't make sense to set the current character unless the current character position is a valid one. Before attempting to set the current character, you should call IsValid to verify that the current character position is a valid one.

Member Function: TCharacterIterator::~TCharacterIterator

~ TCharacterIterator ()

Interface Category:

API.

Purpose:

Destructor.

Calling Context:

Called to destroy an object.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TCharacterIterator::operator=

TCharacterIterator & operator =(const TCharacterIterator & that)

Interface Category:

API.

Purpose:

Assignment operator.

Calling Context:

Called when an object is assigned to another compatible object.

Parameters:

Return Value:

A non-const reference to the left-hand side object.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TCharacterIterator::GetText

const TText * GetText () const

Interface Category:

API.

Purpose:

Obtains a pointer to the text that the iterator is iterating over.

Calling Context:

Called to get a pointer to the text that the iterator is iterating over.

Parameters:

Return Value:

Returns a const pointer to the text that the iterator is iterating over.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TCharacterIterator::SetText

void SetText (TText * text)

Interface Category:

API.

Purpose:

Changes the text that the iterator is iterating over. This member function resets the iterator after changing the text, so you do not need to call ResyncAt after calling this member function. If you have a member function whose argument list contains a TText that the member function needs to iterator over, a performance optimization is to cache the iterator and call SetText on the iterator each time the member function is called. It is faster to call this member function than to create the iterator each time.

Calling Context:

Called to change the text that the iterator is iterating over.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

The iterator assumes that the object passed into this member function will remain valid while it is being iterated over.

Member Function: TCharacterIterator::operator-=

TCharacterIterator & operator -=(TTextCount delta)

Interface Category:

API.

Purpose:

Shifts the character position from its current location by subtracting the specified amount.

Calling Context:

For repositioning the current character position in a relative manner. Use SetIteratorAt or ReSyncAt to reposition the iterator in an absolute manner.

Parameters:

Return Value:

A reference to this iterator after shifting the current character position by subtracting the specified amount.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TCharacterIterator::operator+=

TCharacterIterator & operator += (TTextCount delta)

Interface Category:

API.

Purpose:

Shifts the character position from its current location by adding the specified amount.

Calling Context:

For repositioning the current character position in a relative manner. Use SetIteratorAt or ReSyncAt to reposition the iterator in an absolute manner.

Parameters:

Return Value:

A reference to this iterator after shifting the current character position by adding the specified amount.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

None.

Member Function: TCharacterIterator::TCharacterIterator

  1. TCharacterIterator (TText * text)
  2. TCharacterIterator (const TCharacterIterator & that)

Interface Category:

API.

Purpose:

  1. Constructs a character iterator for the specified text object.
  2. Copy constructor.

Calling Context:

  1. Construct one of these to iterate over just the characters. Use a TTextIterator to iterate over both the characters and styles at the same time. Use the TText::StylesAt member function to iterate over just the styles.
  2. Called to copy an object.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Not multithread safe.

Other Considerations:

Immediately after construction, clients must call either First, Last, or SetIteratorAt in order to initialize the iterator to a valid state. A reference to the input text object is used throughout the life of a character iterator. Therefore, a character iterator is only valid as long as the associated text object is in existence. Similarly, the ReSyncAt member functions must be called to synchronize the iterator with the associated text object when the text object is changed in any way besides the character setting functions provided.
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.