Re: Escaped characters in variables, XML-RPC, Mac OS X
Re: Escaped characters in variables, XML-RPC, Mac OS X
- Subject: Re: Escaped characters in variables, XML-RPC, Mac OS X
- From: Arthur J Knapp <email@hidden>
- Date: Thu, 01 Nov 2001 11:28:38 -0500
>
Date: Tue, 30 Oct 2001 21:19:27 -0500
>
From: Jeremy Reichman <email@hidden>
>
Subject: Escaped characters in variables, XML-RPC, Mac OS X
>
I'm trying to edit a UserLand Frontier/Manila Web site page through
>
TextEdit on OS X. I can download the current contents of the page on the
>
Manila server as text and place that in TextEdit. When I try to take the
>
updated text and upload it to the server, I've got it in an AppleScript
>
variable. AppleScript thus escapes things like quotes that were in the
>
TextEdit window, and this escaping interferes with the text in such a way
>
that the Manila server app doesn't interpret it correctly. (Escaped quotes,
>
for example, don't get used as Manila shortcuts, and I want them to.)
I'm not really sure that I understand. AppleScript only "escapes" a
character when it needs to display it in a result window or in some
other "code" environment, ie: "\"" is equal to ", and this is exactly
what you should get if you are passing this character to another
application.
>
This is very similar to the escaped character problem in BBEdit,
>
especially when you're doing grep searches there. You have to
>
double-escape backslashes there to make sure they get passed to BBEdit's
>
grep engine properly.
Right, because to represent a backslash, you need to escape it for the
regular expression, \\, and to represent it in AppleScript, you have to
represent this as \\\\.
>
... Might there be another clever solution?
I think this is what you are asking for:
-- These are not thoroughly tested!!!
--
on s_escape(str)
set q to "\""
set b to "\\"
set sentinel to ASCII character 1
set oldDelim to text item delimiters
set text item delimiters to b
set str to str's text items
set text item delimiters to sentinel & b
set str to "" & str
set text item delimiters to q
set str to str's text items
set text item delimiters to sentinel & q
set str to "" & str
set text item delimiters to sentinel
set str to str's text items
set text item delimiters to b
set str to "" & str
set text item delimiters to oldDelim
return str
end s_escape
on s_unescape(str)
set q to "\""
set b to "\\"
set oldDelim to text item delimiters
set text item delimiters to b & b
set str to str's text items
set text item delimiters to b
set str to "" & str
set text item delimiters to b & q
set str to str's text items
set text item delimiters to q
set str to "" & str
set text item delimiters to oldDelim
return str
end s_unescape
set s to "This is a quote: \" This is a backslash: \\"
set s to s_escape(s)
--
--> "This is a quote: \\\" This is a backslash: \\\\"
set s to s_unescape(s)
--
--> "This is a quote: \" This is a backslash: \\"
Arthur J. Knapp
http://www.stellarvisions.com
mailto:email@hidden
Hey, check out:
http://www.zavatone.com/