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
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!"
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 :)