Hey Folks,
I use cURL a lot and sometimes Wget for various tasks, and occasionally I forget whether my handlers take quoted strings for input or not. So I decided that rather than force input to be quoted or unquoted I'd write a little routine to make them ambivalent.
------------------------------------------------------------------------------ # For a single url. ------------------------------------------------------------------------------ tell _url if (character 1 = character -1) and (character 1 is in {"\"", "'"}) then # Continue else set _url to "\"" & _url & "\"" end if end tell
------------------------------------------------------------------------------ # For an Applescript list of urls. ------------------------------------------------------------------------------ if class of linkList = list and linkList ≠ {} then repeat with _url in linkList tell _url if (character 1 = character -1) and (character 1 is in {"\"", "'"}) then # Continue else set contents of _url to "\"" & _url & "\"" end if end tell end repeat end if ------------------------------------------------------------------------------
On my system I prefer to use the Satimage.osax's regex which is fast as all get-out and quite convenient.
set linkList to change "(^[\"']*|[\"']*$)" into "\"" in linkList with regexp
This will operate on a string or a list of strings and requires no separate test for quoting.
I always try to have a vanilla or shell backup for portability though, so I wonder if anyone has a better way?
-- Best Regards, Chris
|