Match

Here is a method for searching (matching) text in the classical style:

If for instance the InventTable must be searched for records whos item name contains the text MUSTER, this method can be called with the parameters: if (myMatch('*MUSTER*', inventTable.Itemname)) {   // Then do something }

The method return true if a match was found and false otherwise.

static boolean myMatch(str _matchKey, str _text) {   str     matchKey        = _matchKey; str    text            = _text; str    tokKey;                             // Match Key Token  -  Holds actual Character being examined str    tokText;                            // Text Token       -  Holds actual Character being examined str    laTok;                              // Look Ahead Token -  Holds Character one Positition after Token Character int    lenKey;                             // Key Length int    lenText;                            // Text Length int    incKey;                             // Incrementor for Key int    incText;                            // Incrementor For Text int    laKey;                              // Look Ahead Incrementor for Key boolean ret            = true; ;

#define.WC_MANY ('*') #define.WC_ONE ('?')

if (!matchKey) matchKey = #WC_MANY;

lenKey = strlen(matchKey); lenText = strlen(text); incText = 1;

for (incKey = 1; incKey <= lenKey; incKey++) {       tokKey  = substr(matchKey, incKey, 1);

if (incText > lenText) ret = false;

switch (tokKey) {           case #WC_MANY   : if (incKey < lenKey) {                   laKey   = incKey + 1; laTok  = substr(matchKey, laKey, 1); if (strscan(text, laTok, incText, strlen(text))) {                       incText = strscan(text, laTok, incText, strlen(text)); if (!myMatch( substr(matchKey, incKey + 1, strlen(matchKey)), substr(text, incText, strlen(text)) ))                       {                            incKey--; incText++; }                       else {                           return true; }                   }                    else {                       return false; }               }                else {                   return true; }               break; case #WC_ONE   : incText++; break; default        : if (tokKey == substr(text, incText, 1)) {                   incText++; }               else {                   return false; }               break; }   }    if (incText < lenText) ret = false;

return ret; }