TextSpresso Manual Menu

Word Table Filter

Overview

Word Table Editor

Creating The Pattern

Creating The Table

Case Masks

Overview

This chapter explains how to design new filters based on the Word Table filter type. The Word Table filter is designed to find and replace large sets, or tables, of similar elements very quickly. The classic example of this type of task would be converting between special characters and escape code sequences, such as Mac ASCII To MIME or HTML To Mac ASCII.

You could create a filter for such a task by creating a MultiFilter which contained a Replace Text filter for every element that needed to be replaced. However, this would result in a relatively slow filter because the entire body of text would be searched for every instance to be replaced. A large set could result in a hundred or more passes over the text. Another MultiFilter might call upon several such filters (i.e. Net To Text calling convertors for both HTML and MIME escape characters), resulting in several hundred passes over the text.

Word Tables work around this by using a two step process. First the Word Table filter finds every likely instance of text to be replaced in a single pass by doing a pattern search. Once it has the locations of all of the likely instances, it matches each instance against a table. Every instance of text which is found in the table is replaced with the appropriate replace text. Instances not found in the table are ignored.

By using this process Word Table filters reduce the searching portion of the filter to a single pass. Even though TextSpresso's search routines are very fast, a single pass is always better than a few hundred.

This chapter assumes that you already know how to create new filters and open filter editors, and that you know how to use the elements common to all filter editors. If not, please read Editing Filters before proceeding.

The Word Table Editor

The Word Table editor appears when you select New Filter... from the Filters menu and select the type Word Table. The editor contains a Find field, a Replace field, a Pattern button, and a Case Mask button. Below these items is a scroll list which contains the actual table of find/replace pairs. This table is manipulated using the three buttons next to it, Add, Store, and Delete.

Creating The Pattern

The first step in creating a Word Table filter is to design and enter the pattern the filter will use to find all of the instances of text to be replaced. Remember that the pattern must encompass all of the possible variations of the text. This means that the text items you are looking to filter must have something in common, something that can be used to identify and delineate each instance.

For example, MIME escape codes always start with an equal sign '=' and are followed by two characters which can be any of the digits 0-9 or the letters A, B, C, D, E, or F. This is perfect for the Word Table filter because a simple pattern can be written to find this sequence of characters. The pattern simply looks for an equal sign, followed by 2 characters in the range 0-9, A-F.

Another good example would be HTML escape codes. They always start with '&' and end with ';'.

To edit the pattern used by the Word Table click on the Pattern button. This button will bring up a Replace Pattern Editor which is just like the editor you would see if you were writing a Replace Pattern filter. You use this editor to write the pattern you want to use. Instructions on this editor type and on writing TextSpresso pattern filters can be found in the chapter Replace Pattern Filter. If you haven't already, read that chapter to learn how to write the pattern you need for your Word Table filter. Then move on to the next step.

Creating The Table

After you've created the pattern to be used to find the text which needs to be replaced, you create the table of find/replace pairs used to determine how to replace the text. You create a table entry for every specific instance you want replaced. The Word Table filter will take every instance found by the pattern you specified in the first step and look it up in the table. If it's found, the filter will replace the text with the specified replace text. If it's not, the filter will leave that instance alone.

Adding A New Entry - To add a new find/replace pair to the table:

  1. Type the text to be found in the Find field.
  2. Type the text which will replace the found text in the Replace field.
  3. Click the Add button.

Editing An Entry - To edit an existing find/replace pair:

  1. Double-click the entry you wish to edit in the scroll list.
  2. Edit the Find and Replace fields as needed.
  3. With the entry to be edited selected in the scroll list, click the Store button.

Deleting An Entry - To delete an existing find/replace pair:

  1. Select the entry or entries you wish to delete in the scroll list.
  2. Click the Delete button.

Case Masks

The Word Table filter supports the use of a case mask during its table look ups. Because table look ups are performed with a literal, not a pattern, search routine, the case of the characters is significant. For example, '=ff' is different from '=FF'.

A case mask is a table which maps normal ASCII characters to replacement, or mask, characters. Case masks are used in the Character Table filter to actually map and replace characters at very high speed. In the Word Table filter the characters are not actually changed as they are in the Character Table filter. But the filter 'sees' the mapped characters rather than the normal characters during the table look up. This is useful for implementing case insensitive look ups so that you don't have to make multiple entries for the same element to be replaced (i.e. =ff, =Ff, =fF, =FF).

To edit and save a new case mask for a Word Table filter, click the Case Mask button in the editor. A new dialog will appear which lists all of the 256 characters in the 8-bit Mac ASCII character set. On the left side of the list is the normal character and its ASCII code. On the right side is the replacement character and its ASCII code.

Now select the character you wish to map and type the replacement character. The right side of the list item will change to reflect the replacement character. Repeat for every character you wish to mask, and then click Save to save the new mask, or Cancel to discard the new mask and retain the old one.

You can also type the ASCII code for the replacement character while holding down the control key. Or you can select a character from the Character popup menu.

Finally, there are a number of existing case masks under the Tables popup menu. Simply select one from the menu and click Save to use it. For Word Tables you will most often simply want to use a Lowercase mask. Select Lowercase from the Table popup menu and save the mask.