Nonlanguage-sensitive searching

The TExactTextPatternIterator class finds text patterns by directly comparing the Unicode character codes. This iterator does not support any language-sensitive or case-insensitive matching or look for characters that might have other equivalent Unicode sequences; it does a character-by-character bitwise comparison.

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 );
          }
      }
If you have an instance of TBitwiseTextOrder, you can also create a TExactTextPatternIterator by calling the inherited member function TTextOrder::CreateTextPatternIterator. For example, in the sample function above you could have constructed the iterator as follows:

      TBitwiseTextOrder bitwiseOrder;
      TTextPatternIterator *iterator = 
          bitwiseOrder.CreateTextPatternIterator( &searchText, textToFind,
                                              TTextRange::GetMaximumRange() );

[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker