Providing alternate text matches for scanning

TParameterFormatter includes a mechanism that lets you specify alternate text strings for matching during the scan operation. Use this mechanism to match text strings other than the text specified in the template.

TAlternateTextMatch provides a way for you to create a set of text strings that you can attach to a particular segment of the text template. The TParameterFormatter::Scan function uses this list as a set of alternate matches. When the scanning operation reaches the segment of the template with the attached TAlternateTextMatch, it calls the TAlternateTextMatch::Match function to iterate through the list of alternate strings.

You can also provide case-insensitive alternate matching by specifying a text-ordering object when you construct the TAlternateTextMatch.


TAlternateTextMatch derives from the abstract class TTextMatch. To provide a different mechanism for alternate text matching, you can derive your own class from TTextMatch. You must override the TTextMatch::Match function, providing your own matching algorithm. This function returns a Boolean indicating whether there is a match and the number of characters matched.

Example: Using TAlternateTextMatch

To use TAlternateTextMatch:

  1. Instantiate TAlternateTextMatch.
  2. Create text instances containing the alternate text matches and add them to the list with the TAlternateTextMatch::AddAlternateText function.
  3. Attach the TAlternateTextMatch instance to a specific range of the text template using the TParameterFormatter::SetTextMatch function.
This example demonstrates how to provide the alternate match she for the pronoun he.

      TParameterFormatter myFormatter;
      TPositionalNumberFormatter myNumberFormatter;
      TFormattableParameterList parameters;
      TScanResult result;
      TAlternateTextMatch alternateMatch;
      TFormattableNumber num;
      
      // Create the text template.
      TStandardText textTemplate( "He has XX books.");
      myFormatter.SetTemplate(textTemplate);
      
      // Establish the parameters and attach formatters.
      myFormatter.SetParameterType(0,TStandardText("TFormattableNumber"));
      myFormatter.SetParameterFormat(TTextRange(TTextOffset(7),TTextOffset(9)),
                                      0, myNumberFormatter);
      
      // Add the alternate text match.
      alternateMatch.AddAlternateText(TStandardText("She"));
      myFormatter.SetTextMatch(TTextRange(TTextOffset(0),TTextOffset(2)),
                                   alternateMatch);
      
      // Perform the scanning operation.
      TStandardText scanText("She has 499 books.");
      myFormatter.Scan(scanText,TTextRange::GetMaximumRange();
                          parameters, result);
      
      // Verify the scanned-in value.
      parameters.GetParameter(0,num);

[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