Google Groups

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

Dave Sann Dec 23, 2011 5:43 PM
Posted in group: Clojure
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]
    string #"\\x(..)" 
    (fn [m] (str (char (Integer/parseInt (second m) 16))))))

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