Hi Bob, nice function.
Just for my interest, what is the function of the leading "break" in the
switch control structure? It doesn't seem to bother, but any advantage?
Tiemo


-----Ursprüngliche Nachricht-----
Von: use-livecode [mailto:use-livecode-boun...@lists.runrev.com] Im Auftrag
von Bob Sneidar via use-livecode
Gesendet: Mittwoch, 22. März 2017 23:21
An: How to use LiveCode <use-livecode@lists.runrev.com>
Cc: Bob Sneidar <bobsnei...@iotecdigital.com>
Betreff: Re: New Iteration of cleanASCII

cleanASCII(pString, pModeList, pCustomChars)

Belay my last. I refactored the whole thing to be much more robust. Pass a
string, a modelist and a custom list. This will act as a simple regex
character filter for any string you pass it. (Great for filtering out
hidden/non-printing characters!) If you only pass it a string and no
arguements, it will return uppercase, lowercase, numbers and spaces. 

The modelist can be any items in
"tabs,newlines,returns,spaces,numbers,lowercase,uppercase,symbols,custom".
If the modelist contains "custom" then pass any other characters you want to
include in pCustomList. 

Modifications welcome, but remember this is just a character by character
filter and NOT a full blown regex replacement. That would put me in the
funny farm for sure. 

Bob S


function cleanASCII pString, pModeList, pCustomChars
   if pModeList is empty then
      put " 0-9a-zA-Z" into tAllowedChars
   end if
   
   repeat for each item pMode in pModeList
      switch
            break
         case "tabs" is in pMode
            put "\t" after tAllowedChars
            break
         case "newlines" is in pMode
            put "\n" after tAllowedChars
            break
         case "returns" is in pMode
            put "\r" after tAllowedChars
            break
         case "spaces" is in pMode
            put " " after tAllowedChars
            break
         case "numbers" is in pMode
            put "0-9" after tAllowedChars
            break
         case "lowercase" is in pMode
            put "a-z" after tAllowedChars
            break
         case "uppercase" is in pMode
            put "A-Z" after tAllowedChars
            break
         case "symbols" is in pMode
            put "!#$%&'()*+,./:;<=>?@[\\_`{|}~^-" after tAllowedChars
            break
         case pMode is "custom"
            put pCustomChars after tAllowedChars
            break
      end switch
   end repeat
   
   put "[" & tAllowedChars & "]" into tMatchText
   
   repeat for each character theChar in pString
      if matchtext(theChar, tMatchText) is true then
         put theChar after cleanString
      end if
   end repeat
   
   return cleanString
end cleanASCII

Bob S



_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Reply via email to