[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Re: Unicode/UTF-8 confusion

Tom Stambaugh

3/15/2008 5:55:00 PM

> Somehow I don't get what you are after. The ' doesn't have to be escaped
> at all if " are used to delimit the string. If ' are used as delimiters
> then \' is a correct escaping. What is the problem with that!?

If I delimit the string with double quote, then I have to escape every
double quote in whatever I serialize. I'm moving strict html from the server
to the browser, and therefore the value of every tag attribute is delimited
by double quotes. That means that I'd have to escape every double quote, and
there are MANY more of them.

Thanks,
Tom



1 Answer

Marc Christiansen

3/15/2008 6:31:00 PM

0

Tom Stambaugh <tms@zeetix.com> wrote:
>> Somehow I don't get what you are after. The ' doesn't have to be escaped
>> at all if " are used to delimit the string. If ' are used as delimiters
>> then \' is a correct escaping. What is the problem with that!?
>
> If I delimit the string with double quote, then I have to escape every
> double quote in whatever I serialize. I'm moving strict html from the server
> to the browser, and therefore the value of every tag attribute is delimited
> by double quotes. That means that I'd have to escape every double quote, and
> there are MANY more of them.

I haven't done much programming with Javascript/AJAX, so why is the
following not sufficient? All the double quotes get escaped.

>>> link = u"""<a href="asd" title="Peter's child">Click here</a>"""
>>> simplejson.dumps(link)
'"<a href=\\"asd\\" title=\\"Peter\'s child\\">Click here<\\/a>"'
>>> print simplejson.dumps(link)
"<a href=\"asd\" title=\"Peter's child\">Click here<\/a>"

And ' is a valid delimiter for attributes, so you don't have to use
double quotes for them.

Marc