How an Advanced Search is Made

There are some subtle differences between some of the search possibilities and to make best use of these an understanding of the search process will help.

To understand the search process it is important to remember that a file in memory is stored as a long string of Bytes, each Byte representing a character. The search expression consists of a number of separate elements strung together, with spaces as desired to make the expression readable. Spaces outside of search element are ignored. The diagram shows six elements, e1 to e6. search_how/png

During a search, StrongED maintains three pointers. Pointer Ts (Text Start) points to the Start of the Text string currently being inspected for a match, and is tied to the first element in the Search expression. Tm (Text Match) points to the byte currently being inspected for a Match against the Search expression.

Em (Element Match?) points to the search element currently doing the inspecting.

At the start of a search, Tm points to the same place as Ts. Em points to e1. If no match is found, all are moved on together one byte in the text and so on until the text matches e1. Now e2 is matched against the next byte(s) of the text - in this case starting at the letter e. If these bytes match, Tm moves on to the end of the matched section and Em moves to e3.

Thus the matching continues in chunks until one if two things happens:

  1. No match is found. But this may be because this expression is part of an OR - so the pointer Em must Look Ahead (Ea) to see if there is any such element which need to override the "no-match". If indeed there is no match, then Ta is moved on one byte and Tm and Em are returned to their starts, coupled to Ts.
  2. If a match is found, then Em moves on to the next element which is matched against the next chunk of text.
If all the elements of the search expression match, then a complete match is found.

There is also an element ~ which causes search to look ahead without moving the Text Match (Tm) pointer - as shown by Ta (Text ahead) - until the element qualified by the ~ fails to match it (in other words, the ~ qualifier causes any bytes that match the qualified element to be ignored).

The text byte that caused the failure (i.e. is not ignored) is then matched against the following element.

Other relevant pages

Top of page


Page Information

http://css.torrens.org/valid-html401-bluehttp://css.torrens.org/valid-css Document URI: http://stronged.torrens.org/man/search/how.html
Page first published: Tuesday the 23rd of January, 2018
Last modified:Wed, 30 May 2018 09:33:45 BST
© 2018 - 2018 Richard Torrens.