Language-sensitive searching

The TStandardTextPatternIterator class uses an instance of TTableBasedTextOrder to provide language-sensitive searching capabilities. By setting the ordering level of the text ordering object used, you control the sensitivity of the pattern matching. For example, if case differences are tertiary, you can provide case-insensitive matching by setting the text ordering object to ignore tertiary differences.

TStandardTextPatternIterator also matches characters that are equivalent in Unicode. For example, à is equivalent to the sequence a and `.

The following example function shows how to search the contents of the text instance searchText for the string in the text instance pattern. You must pass a text-ordering object to the TStandardTextPatternIterator constructor.

      void
      FindString( TText& searchText, const TText& pattern )
      {
          TTextRange foundRange;
          
          TTableBasedTextOrder *englishOrder = TTableBasedTextOrder( TToken("English") );
          TStandardTextPatternIterator iterator( &searchText, pattern,
              TTextRange( 0, searchText.GetLength() ), &englishOrder );
      
          if (iterator.First(foundRange) != TTextPatternIterator::kNotFoundOffset) 
          {
              // Do something interesting...
          }
          else
          {
              // No pattern found.
          }
      }
To perform pattern matching based on a text-ordering object you have already created, you can also create the iterator by calling the TTableBasedTextOrder::CreateTextPatternIterator member function of your ordering object. For example, in the sample function above you could have constructed the iterator as follows:

      TTableBasedTextOrder englishOrder = TTableBasedTextOrder( TToken("English") );
      TTextPatternIterator *iterator = 
          englishOrder.CreatePatternIterator( &searchText, pattern, 
                                          TTextRange(0, searchText.GetLength()) );

[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