FAQ

[Clojure] Should read-string support \x.. escaped characters?

Dave Sann
Dec 24, 2011 at 1:43 am
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)))

Causes : https://github.com/ibdknox/pinot/issues/16

Cheers

Dave

--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
reply

Search Discussions

4 responses

  • Softaddicts at Dec 24, 2011 at 3:23 pm
    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

    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)))

    Causes : https://github.com/ibdknox/pinot/issues/16

    Cheers

    Dave

    --
    You received this message because you are subscribed to the Google
    Groups "Clojure" group.
    To post to this group, send email to clojure@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+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/clojure?hl=en
    --
    Softaddicts<lprefontaine@softaddicts.ca> sent by ibisMail!

    --
    You received this message because you are subscribed to the Google
    Groups "Clojure" group.
    To post to this group, send email to clojure@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+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/clojure?hl=en
  • Stuart Sierra at Jan 1, 2012 at 5:46 pm
    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

    --
    You received this message because you are subscribed to the Google
    Groups "Clojure" group.
    To post to this group, send email to clojure@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+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/clojure?hl=en
  • Brandon Bloom at Apr 24, 2012 at 6:20 pm
    Surprisingly, this differs from JSON, which only supports \u...
    On Friday, December 23, 2011 5:43:00 PM UTC-8, Dave Sann wrote:

    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)))

    Causes : https://github.com/ibdknox/pinot/issues/16

    Cheers

    Dave
    --
    You received this message because you are subscribed to the Google
    Groups "Clojure" group.
    To post to this group, send email to clojure@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+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/clojure?hl=en
  • Dave Sann at Jul 14, 2012 at 3:37 am
    opened: http://dev.clojure.org/jira/browse/CLJ-1025
    On Wednesday, 25 April 2012 04:20:11 UTC+10, Brandon Bloom wrote:

    Surprisingly, this differs from JSON, which only supports \u...
    On Friday, December 23, 2011 5:43:00 PM UTC-8, Dave Sann wrote:

    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)))

    Causes : https://github.com/ibdknox/pinot/issues/16

    Cheers

    Dave
    --
    You received this message because you are subscribed to the Google
    Groups "Clojure" group.
    To post to this group, send email to clojure@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+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/clojure?hl=en

Related Discussions

Discussion Navigation
viewthread | post