whole( )

FlexibleLearning at aol.com FlexibleLearning at aol.com
Sat Jul 14 06:31:39 EDT 2007


This is getting closer but is still not foolproof...

on mouseUp
answer whole(fld "str",fld "source")
end  mouseUp

function whole stringToFind, sourceText
--| Based on a  script by Sakari Ruoho <sakari.ruoho at academica.com>
--| Tests  for a whole word or phrase in a variable. Returns TRUE or FALSE
--|  Handles single punctuation and hyphenated words.
--| Fails with  unbalanced double punctuation (brackets, quotes etc).
--| Fails if the  string to find is punctuation only
--| Fails with leading  punctuation
--| Does not support multiple-line matching (ignores  ends-of-line)

# set the caseSensitive to true # Optional  setting
set the wholematches to TRUE
if NOT  incPunctuation(stringToFind)
then put stripPunctuation(sourceText)  into sourceText
put 0 into tSkip
repeat while  wordOffset(word 1 of stringToFind, sourceText, tSkip) >  0
add wordOffset(word 1 of stringToFind, sourceText,  tSkip) to tSkip
put TRUE into  tReturn
repeat with x=2 to the number of words in  stringToFind
try
get matchText(word x of  stringToFind, "^" & word (tSkip-1+x) of sourceText & 
"$"  )
catch  errorNum
put FALSE into  tReturn
exit  repeat
end  try
if it is FALSE  then
put stripPunctuation(word  (tSkip-1+x) of sourceText) into  strippedString
try
get matchText(word  x of stringToFind, "^" & strippedString &  "$")
catch  errorNum
put FALSE  into tReturn
exit  repeat
end  try
if it is not TRUE  then
put FALSE into  tReturn
exit  repeat
else
put TRUE into  tReturn
end  if
else
put TRUE into  tReturn
end if
end  repeat
if tReturn is TRUE  then
return  TRUE
exit whole
end  if
end repeat
return FALSE
end whole

function  incPunctuation tString
repeat for each char c in  (";:.,!'?[](){}"&return&QUOTE)
if c is in tString  then return TRUE
end repeat
return FALSE
end  incPunctuation

function stripPunctuation tString
repeat for  each char c in (";:.,!'?[](){}"&return&QUOTE)
replace c with SPACE in tString
end repeat
return  tString
end stripPunctuation
 
 
/H
 
Hugh Senior
FLCo



   



More information about the use-livecode mailing list