From: Trastabuga
Subject: read-from-string and double-quote
Date: 
Message-ID: <0fd6affa-9853-49dd-a545-fad97b0863e5@34g2000hsf.googlegroups.com>
I get a string as a result of some JavaScript manipulation and it
happen to have a double-quote character in it which breaks the
evaluating of the string to CL list. (I am using SBCL on Ubuntu)

Let's say if I evaluate following form
> (read-from-string "(\"size\" \"32inches\")")
("size" "32inches")

Now if I replace inches for \" it's going to break:
> (read-from-string "(\"size\" \"32\"\")")
end of file on #<SB-IMPL::STRING-INPUT-STREAM {15D64AC1}>
   [Condition of type END-OF-FILE]

Restarts:
 0: [ABORT] Return to SLIME's top level.
 1: [ABORT] Exit debugger, returning to top level.

Is there any way I can keep the \" character in the string and still
evaluate the string to list?

Thank you,
Andrew

From: Pascal J. Bourguignon
Subject: Re: read-from-string and double-quote
Date: 
Message-ID: <87lk1c99jy.fsf@hubble.informatimago.com>
Trastabuga <·········@gmail.com> writes:

> I get a string as a result of some JavaScript manipulation and it
> happen to have a double-quote character in it which breaks the
> evaluating of the string to CL list. (I am using SBCL on Ubuntu)
>
> Let's say if I evaluate following form
>> (read-from-string "(\"size\" \"32inches\")")
> ("size" "32inches")
>
> Now if I replace inches for \" it's going to break:
>> (read-from-string "(\"size\" \"32\"\")")
> end of file on #<SB-IMPL::STRING-INPUT-STREAM {15D64AC1}>
>    [Condition of type END-OF-FILE]
>
> Restarts:
>  0: [ABORT] Return to SLIME's top level.
>  1: [ABORT] Exit debugger, returning to top level.
>
> Is there any way I can keep the \" character in the string and still
> evaluate the string to list?

Of course.  Remember that you can use \ to escape characters in
strings.  Perhaps it's too obvious, there's already 11 backslash in
your post.


C/USER[14]> (read-from-string "\" a string with a quote: \\\" and a backslash: \\\\\"")
" a string with a quote: \" and a backslash: \\" ;
48
C/USER[15]> (princ *)
 a string with a quote: " and a backslash: \
" a string with a quote: \" and a backslash: \\"


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

"By filing this bug report you have challenged the honor of my
family. Prepare to die!"
From: Trastabuga
Subject: Re: read-from-string and double-quote
Date: 
Message-ID: <9f21f547-6602-4745-9960-28b0f7baea9e@26g2000hsk.googlegroups.com>
On Jun 10, 7:04 pm, ····@informatimago.com (Pascal J. Bourguignon)
wrote:
> Trastabuga <·········@gmail.com> writes:
> > I get a string as a result of some JavaScript manipulation and it
> > happen to have a double-quote character in it which breaks the
> > evaluating of the string to CL list. (I am using SBCL on Ubuntu)
>
> > Let's say if I evaluate following form
> >> (read-from-string "(\"size\" \"32inches\")")
> > ("size" "32inches")
>
> > Now if I replace inches for \" it's going to break:
> >> (read-from-string "(\"size\" \"32\"\")")
> > end of file on #<SB-IMPL::STRING-INPUT-STREAM {15D64AC1}>
> >    [Condition of type END-OF-FILE]
>
> > Restarts:
> >  0: [ABORT] Return to SLIME's top level.
> >  1: [ABORT] Exit debugger, returning to top level.
>
> > Is there any way I can keep the \" character in the string and still
> > evaluate the string to list?
>
> Of course.  Remember that you can use \ to escape characters in
> strings.  Perhaps it's too obvious, there's already 11 backslash in
> your post.
>
> C/USER[14]> (read-from-string "\" a string with a quote: \\\" and a backslash: \\\\\"")
> " a string with a quote: \" and a backslash: \\" ;
> 48
> C/USER[15]> (princ *)
>  a string with a quote: " and a backslash: \
> " a string with a quote: \" and a backslash: \\"
>
> --
> __Pascal Bourguignon__                    http://www.informatimago.com/
>
> "By filing this bug report you have challenged the honor of my
> family. Prepare to die!"

It helps! I keep forgetting putting multiple backslashes to escape
something in CL :)