[TIDBIT] googleMatch()

FlexibleLearning at aol.com FlexibleLearning at aol.com
Fri Mar 24 09:56:22 EST 2006


I wrote this to provide a "search as you type" filter field with  
google-style pattern matching:
 
+ means it has to be included
- means it must not be included
quotes means the whole phrase.
 
e.g. DOG +LEAD -CAT "REAL LEATHER"
 
Maybe you will find it useful. Optimization welcome!
 
on rawkeyup
  put me into tPattern
  repeat for each line L in fld "myDataList"
    if googleMatch(tPattern,L) then put L&cr after  tStdOut
  end repeat
  put char 1 to -2 of tStdOut into fld "searchResult"
end rawkeyup
 
function googleMatch tPattern,tTxt
# NOTE: To match a + or -, use  ++ or +-, or -+ or --
repeat for each word W in  tPattern
if W="+" or W="-" then return  TRUE
if (char 1 of W is quoteAND char -1 of W is quote)  then put char 2 to -2 of 
W into W
if ("-" is char 1 of W)  and (char 2 to -1 of W is in tTxt) then return FALSE
if  ("-" is char 1 of W) and (char 2 to -1 of W is NOT in tTxt) then next  
repeat
if ("+" is char 1 of W) and (char 2 to -1 of W is  NOT in tTxt) then return 
FALSE
if ("+" is char 1 of W) and  (char 2 to -1 of W is in tTxt) then next repeat
if W is in  tTxt then next repeat
else return FALSE
end  repeat
return TRUE
end googleMatch
 
/H



More information about the Use-livecode mailing list