This iterator provides a faster pattern matching mechanism for any environment that does not require language-sensitive criteria, such as an editor for writing programs.
The following example function shows how to search the contents of the text object searchText
for the pattern in the text object textToFind
, and how to highlight each occurrence with a red color style. This example uses TExactTextPatternIterator and therefore does not provide language-sensitive matching. The TExactTextPatternIterator constructor takes a third argument, a TTextRange, that defaults to the value returned by TTextRange::GetMaximumRange.
void HighlightAll( const TText& searchText, const TText& textToFind ) { TTextRange foundRange; TExactTextPatternIterator iterator( &searchText, textToFind ); for (TTextOffset foundOffset = iterator.First( foundRange ); foundOffset != TTextPatternIterator::kNotFoundOffset; foundOffset = iterator.Next( foundRange ) ) { searchText.AddStyles( TTextColorStyle::GetRed(), foundRange ); } }
TBitwiseTextOrder bitwiseOrder; TTextPatternIterator *iterator = bitwiseOrder.CreateTextPatternIterator( &searchText, textToFind, TTextRange::GetMaximumRange() );