Should read-string support \x.. escaped characters?

476 views
Skip to first unread message

Dave Sann

unread,
Dec 23, 2011, 8:43:00 PM12/23/11
to clo...@googlegroups.com
When sending data as strings from clojurescript to clojure there will be issues if the source data contains certain unicode characters. (I think in range 128-255 - extended latin characters mostly).

This is because the goog string conversion used by pr-str encodes these characters as \x.. not \u00..

read-string will throw an exception if it encounters these characters.

Should read-string support these character escapes?



by way of work around, I am using:

(require '[clojure.string :as s])

(defn unescape [string]
  (s/replace 
    string #"\\x(..)" 
    (fn [m] (str (char (Integer/parseInt (second m) 16))))))

(defn my-read-string [s]
  (read-string (unescape s)))


Cheers

Dave

Softaddicts

unread,
Dec 24, 2011, 10:23:51 AM12/24/11
to clo...@googlegroups.com
My mother language being French, I would be naturally inclined to say yes.
However I do have a real concern, I am currently evaluating a dashboard option to be
added to our hospital integration product and our pilot site uses French.

I am counting on ClojureScript in the browser to make this thing
quite dynamic. Hospital personnel will carry tablets with them to enter data and
several huge screens will be installed so people can find where patients are located
at any moment.

Luc

> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clo...@googlegroups.com
> Note that posts from new members are moderated - please be patient with your first post.
> To unsubscribe from this group, send email to
> clojure+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
--
Softaddicts<lprefo...@softaddicts.ca> sent by ibisMail!

Stuart Sierra

unread,
Jan 1, 2012, 12:46:51 PM1/1/12
to clo...@googlegroups.com
One of the goals of having a reader/printer in ClojureScript is to enable transparent data exchange between Clojure and ClojureScript.

I don't know right away what the correct approach here should be: either pr-str in ClojureScript should print character escapes in the form expected by the Clojure reader, or the Clojure reader should support the additional character escape form.

I've created a new wiki page to document the issue: http://dev.clojure.org/pages/viewpage.action?pageId=4063586

-Stuart Sierra
clojure.com

Brandon Bloom

unread,
Apr 24, 2012, 2:20:11 PM4/24/12
to clo...@googlegroups.com
Surprisingly, this differs from JSON, which only supports \u...

Dave Sann

unread,
Jul 13, 2012, 11:37:19 PM7/13/12
to clo...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages