Taxonomy Categories:
Member Functions:
Interface Category:
API.
Inherits From:
None.
Inherited By:
None.
Purpose:
Iterates over the character and/or character-based styles in a text object. If you are interested in only the character information, see class TCharacterIterator 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.
Currently TTextIterator only supports character-based styles (see description of TCharacterStyleKind). Use TText::StylesAt to iterate through any other types of styles that may be applied to the text.
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.
bool IsValid ()
Interface Category:
API.
Purpose:
Determines if the iterator is currently at a valid text position. Immediately after construction, the iterator is invalid until First, Last, or SetIteratorAt is called. A valid iterator becomes invalid when the current text position is the first one and you decrement the text position. Similarly, a valid iterator becomes invalid when the current text position is the last one and you increment the text position.
Calling Context:
Call IsValid after calling First, Last, Next, Previous, or Current to determine if the returned text 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 text position is valid.
Parameters:
Return Value:
Returns true if the current text 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 text. 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: TTextIterator::SetIteratorAt
void SetIteratorAt (TTextIndex index)
Interface Category:
API.
Purpose:
Sets the current text 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 text position. Also, call this member function to reposition the iterator when sequential iteration is not desired.
Parameters:
- TTextIndex index -The new text position for the iterator.
Return Value:
None.
Exceptions:
Throws no exceptions, passes all exceptions through.
Concurrency:
Not multithread safe.
Other Considerations:
None.
Member Function: TTextIterator::ResyncAt
void ResyncAt (TTextIndex index, bool updateCaches =true)
Interface Category:
API.
Purpose:
Sets the current text 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:
- TTextIndex index -The new text position for the iterator.
- bool updateCaches =true -Whether to resynchronize with the associated text object or not. The default is to always force things to be in sync. However, you can override this default by passing false for this parameter. In that case, this function works exactly like SetIteratorAt.
Return Value:
None.
Exceptions:
Throws no exceptions, passes all exceptions through.
Concurrency:
Not multithread safe.
Other Considerations:
None.
Member Function: TTextIterator::GetCurrentIndex
TTextIndex GetCurrentIndex ()
Interface Category:
API.
Purpose:
Gets the current text position of the iterator.
Calling Context:
Call when you want to know the current text position.
Parameters:
Return Value:
The TTextIndex representing the current text 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.
- UniChar First ()
- void First (UniChar & ucode)
- void First (TStyleSet & set)
- void First (UniChar & ucode, TStyleSet & set)
Interface Category:
API.
Purpose:
Sets the iterator to the first text position. Then, gets the first character and/or styles.
Calling Context:
- Call when you want to get the character as the return value.
- Call when you want to pass in a character reference to be filled in.
- Call when you want to pass in a style set reference to be filled in.
- Call when you want to pass in a character reference and a style set reference to be filled in.
Parameters:
- Takes no parameters.
- UniChar & ucode -The output character that is set with the character at the current text position.
- TStyleSet & set -The output style set that is set with the style set at the current text position.
- UniChar & ucode -The output character that is set with the character at the current text position.
- TStyleSet & set -The output style set that is set with the style set at the current text position.
Return Value:
- The first character of the associated text object.
- None.
- None.
- None.
Exceptions:
Throws no exceptions, passes all exceptions through.
Concurrency:
Not multithread safe.
Other Considerations:
The returned information will be invalid if the associated text object is empty. After calling this member function, you must call IsValid to determine if the returned information is valid.
- UniChar Last ()
- void Last (UniChar & ucode)
- void Last (TStyleSet & set)
- void Last (UniChar & ucode, TStyleSet & set)
Interface Category:
API.
Purpose:
Sets the iterator to the last text position. Then, gets the last character and/or styles.
Calling Context:
- Call when you want to get the character as the return value.
- Call when you want to pass in a character reference to be filled in.
- Call when you want to pass in a style set reference to be filled in.
- Call when you want to pass in a character reference and a style set reference to be filled in.
Parameters:
- Takes no parameters.
- UniChar & ucode -The output character that is set with the character at the current text position.
- TStyleSet & set -The output style set that is set with the style set at the current text position.
- UniChar & ucode -The output character that is set with the character at the current text position.
- TStyleSet & set -The output style set that is set with the style set at the current text position.
Return Value:
- The last character of the associated text object.
- None.
- None.
- None.
Exceptions:
Throws no exceptions, passes all exceptions through.
Concurrency:
Not multithread safe.
Other Considerations:
The returned information will be invalid if the associated text object is empty. After calling this member function, you must call IsValid to determine if the returned information is valid.
- UniChar Current ()
- void Current (UniChar & ucode)
- void Current (TStyleSet & set)
- void Current (UniChar & ucode, TStyleSet & set)
Interface Category:
API.
Purpose:
Gets the current character and/or styles.
Calling Context:
- Call when you want to get the character as the return value.
- Call when you want to pass in a character reference to be filled in.
- Call when you want to pass in a style set reference to be filled in.
- Call when you want to pass in a character reference and a style set reference to be filled in.
Parameters:
- Takes no parameters.
- UniChar & ucode -The output character that is set with the character at the current text position.
- TStyleSet & set -The output style set that is set with the style set at the current text position.
- UniChar & ucode -The output character that is set with the character at the current text position.
- TStyleSet & set -The output style set that is set with the style set at the current text position.
Return Value:
- The current character of the associated text object.
- None.
- None.
- None.
Exceptions:
Throws no exceptions, passes all exceptions through.
Concurrency:
Not multithread safe.
Other Considerations:
The returned information will be invalid if the current text 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 information.
Member Function: TTextIterator::CurrentAndIncrement
- UniChar CurrentAndIncrement ()
- void CurrentAndIncrement (UniChar & ucode)
- void CurrentAndIncrement (TStyleSet & set)
- void CurrentAndIncrement (UniChar & ucode, TStyleSet & set)
Interface Category:
API.
Purpose:
Gets the current character and/or styles. Then, increments the iterator to the next text position.
Calling Context:
- Call when you want to get the character as the return value.
- Call when you want to pass in a character reference to be filled in.
- Call when you want to pass in a style set reference to be filled in.
- Call when you want to pass in a character reference and a style set reference to be filled in.
Parameters:
- Takes no parameters.
- UniChar & ucode -The output character that is set with the character at the current text position.
- TStyleSet & set -The output style set that is set with the style set at the current text position.
- UniChar & ucode -The output character that is set with the character at the current text position.
- TStyleSet & set -The output style set that is set with the style set at the current text position.
Return Value:
- The current character of the associated text object.
- None.
- None.
- None.
Exceptions:
Throws no exceptions, passes all exceptions through.
Concurrency:
Not multithread safe.
Other Considerations:
The returned information will be invalid if the current text position is beyond either end of the associated text object. Before calling this member function, you must call IsValid() to determine the validity of the returned information.
Member Function: TTextIterator::CurrentAndDecrement
- UniChar CurrentAndDecrement ()
- void CurrentAndDecrement (UniChar & ucode)
- void CurrentAndDecrement (TStyleSet & set)
- void CurrentAndDecrement (UniChar & ucode, TStyleSet & set)
Interface Category:
API.
Purpose:
Gets the current character and/or styles. Then, decrements the iterator to the previous text position.
Calling Context:
- Call when you want to get the character as the return value.
- Call when you want to pass in a character reference to be filled in.
- Call when you want to pass in a style set reference to be filled in.
- Call when you want to pass in a character reference and a style set reference to be filled in.
Parameters:
- Takes no parameters.
- UniChar & ucode -The output character that is set with the character at the current text position.
- TStyleSet & set -The output style set that is set with the style set at the current text position.
- UniChar & ucode -The output character that is set with the character at the current text position.
- TStyleSet & set -The output style set that is set with the style set at the current text position.
Return Value:
- The current character of the associated text object.
- None.
- None.
- None.
Exceptions:
Throws no exceptions, passes all exceptions through.
Concurrency:
Not multithread safe.
Other Considerations:
The returned information will be invalid if the current text position is beyond either end of the associated text object. Before calling this member function, you must call IsValid to determine the validity of the returned information.
- UniChar Next ()
- void Next (UniChar & ucode)
- void Next (TStyleSet & set)
- void Next (UniChar & ucode, TStyleSet & set)
Interface Category:
API.
Purpose:
Increments the iterator to the next text position. Then, gets the character and/or styles at the new text position.
Calling Context:
- Call when you want to get the character as the return value.
- Call when you want to pass in a character reference to be filled in.
- Call when you want to pass in a style set reference to be filled in.
- Call when you want to pass in a character reference and a style set reference to be filled in.
Parameters:
- Takes no parameters.
- UniChar & ucode -The output character that is set with the character at the current text position.
- TStyleSet & set -The output style set that is set with the style set at the current text position.
- UniChar & ucode -The output character that is set with the character at the current text position.
- TStyleSet & set -The output style set that is set with the style set at the current text position.
Return Value:
- The next character of the associated text object.
- None.
- None.
- None.
Exceptions:
Throws no exceptions, passes all exceptions through.
Concurrency:
Not multithread safe.
Other Considerations:
The returned information will be invalid if the new text position is beyond the end of the associated text object. After calling this member function, you must call IsValid to determine if the returned information is valid.
Member Function: TTextIterator::Previous
- UniChar Previous ()
- void Previous (UniChar & ucode)
- void Previous (TStyleSet & set)
- void Previous (UniChar & ucode, TStyleSet & set)
Interface Category:
API.
Purpose:
Decrements the iterator to the previous text position. Then, gets the character and/or styles at the new text position.
Calling Context:
- Call when you want to get the character as the return value.
- Call when you want to pass in a character reference to be filled in.
- Call when you want to pass in a style set reference to be filled in.
- Call when you want to pass in a character reference and a style set reference to be filled in.
Parameters:
- Takes no parameters.
- UniChar & ucode -The output character that is set with the character at the current text position.
- TStyleSet & set -The output style set that is set with the style set at the current text position.
- UniChar & ucode -The output character that is set with the character at the current text position.
- TStyleSet & set -The output style set that is set with the style set at the current text position.
Return Value:
- The previous character of the associated text object.
- None.
- None.
- None.
Exceptions:
Throws no exceptions, passes all exceptions through.
Concurrency:
Not multithread safe.
Other Considerations:
The returned information will be invalid if the new text position is before the beginning of the associated text object. After calling this member function, you must call IsValid to determine if the returned information is valid.
Member Function: TTextIterator::SetCurrent
void SetCurrent (UniChar newValue)
Interface Category:
API.
Purpose:
Sets the character at the current text position.
Calling Context:
Call when you want to set the character at the current text position to a new character value.
Parameters:
- UniChar newValue -The new value for the current character.
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 text position is a valid one. Before attempting to set the current character, you should call IsValid to verify that the current text position is a valid one.
Member Function: TTextIterator::SetCurrentAndIncrement
void SetCurrentAndIncrement (UniChar newValue)
Interface Category:
API.
Purpose:
Sets the current character and increment the iterator to the next text 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:
- UniChar newValue -The new value for the current character.
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 text position is a valid one. Before attempting to set the current character, you should call IsValid to verify that the current text position is a valid one.
Member Function: TTextIterator::SetCurrentAndDecrement
void SetCurrentAndDecrement (UniChar newValue)
Interface Category:
API.
Purpose:
Sets the current character and decrements the iterator to the previous text 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:
- UniChar newValue -The new value for the current character.
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 text position is a valid one. Before attempting to set the current character, you should call IsValid to verify that the current text position is a valid one.
Member Function: TTextIterator::GetChunkLastIndex
TTextIndex GetChunkLastIndex ()
Interface Category:
API.
Purpose:
Returns the last index of the currently selected range in the text object.
Calling Context:
Call to get the last index of the currently selected range in the text object.
Parameters:
Return Value:
The last index of the currently selected range.
Exceptions:
Throws no exceptions, passes all exceptions through.
Concurrency:
Not multithread safe.
Other Considerations:
The style information for all characters in the currently selected range is identical.
Member Function: TTextIterator::GetChunkFirstIndex
TTextIndex GetChunkFirstIndex ()
Interface Category:
API.
Purpose:
Returns the first index of the currently selected range in the text object.
Calling Context:
Call to get the first index of the currently selected range in the text object.
Parameters:
Return Value:
The first index of the currently selected range.
Exceptions:
Throws no exceptions, passes all exceptions through.
Concurrency:
Not multithread safe.
Other Considerations:
The style information for all characters in the currently selected range are identical.
~ TTextIterator ()
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: TTextIterator::operator=
TTextIterator & operator =(const TTextIterator & that)
Interface Category:
API.
Purpose:
Assignment operator.
Calling Context:
Called when an object is assigned to another compatible object.
Parameters:
- const TTextIterator & that -The source object for the assignment.
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.
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.
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:
- TText * text -The new text that the iterator will be iterating over.
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: TTextIterator::operator-=
TTextIterator & operator -=(TTextCount delta)
Interface Category:
API.
Purpose:
Shifts the text position from its current location by subtracting the specified amount.
Calling Context:
For repositioning the current text position in a relative manner. Use SetIteratorAt or ReSyncAt to reposition the iterator in an absolute manner.
Parameters:
- TTextCount delta -The amount to subtract from the current text position.
Return Value:
A reference to this iterator after shifting the current text position by subtracting the specified amount.
Exceptions:
Throws no exceptions, passes all exceptions through.
Concurrency:
Not multithread safe.
Other Considerations:
None.
Member Function: TTextIterator::operator+=
TTextIterator & operator += (TTextCount delta)
Interface Category:
API.
Purpose:
Shifts the text position from its current location by adding the specified amount.
Calling Context:
For repositioning the current text position in a relative manner. Use SetIteratorAt or ReSyncAt to reposition the iterator in an absolute manner.
Parameters:
- TTextCount delta -The amount to add to the current text position.
Return Value:
A reference to this iterator after shifting the current text position by adding the specified amount.
Exceptions:
Throws no exceptions, passes all exceptions through.
Concurrency:
Not multithread safe.
Other Considerations:
None.
- TTextIterator (TText * text)
- TTextIterator (const TTextIterator & that)
Interface Category:
API.
Purpose:
- Constructs a text iterator for the specified text object.
- Copy constructor.
Calling Context:
- Construct one of these to iterate over characters and styles. Use a TCharacterIterator to iterate over only the characters. Use the TText::StylesAt member function to iterate over just the styles.
- Called to copy an object.
Parameters:
- TText * text -The text object to be iterated over.
- const TTextIterator & that -The object to copy.
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 text iterator. Therefore, a text 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.