Permalink
Browse files

CLJS-400: stop using goog.string.quote when printing strings

  • Loading branch information...
1 parent 82c5ca7 commit 3b32345966a65f66e49563a3a40a2877d0435c5d @cemerick cemerick committed with David Nolen Oct 19, 2012
Showing with 18 additions and 2 deletions.
  1. +17 −2 src/cljs/cljs/core.cljs
  2. +1 −0 test/cljs/cljs/core_test.cljs
View
@@ -6350,6 +6350,21 @@ reduces them without incurring seq initialization"
[fmt & args]
(print (apply format fmt args)))
+(def ^:private char-escapes {"\"" "\\\""
+ "\\" "\\\\"
+ "\b" "\\b"
+ "\f" "\\f"
+ "\n" "\\n"
+ "\r" "\\r"
+ "\t" "\\t"})
+
+(defn ^:private quote-string
+ [s]
+ (str \"
+ (.replace s (js/RegExp "[\\\\\"\b\f\n\r\t]" "g")
+ (fn [match] (get char-escapes match)))
+ \"))
+
(extend-protocol ^:deprecation-nowarn IPrintable
boolean
(-pr-seq [bool opts] (list (str bool)))
@@ -6374,7 +6389,7 @@ reduces them without incurring seq initialization"
(str nspc "/"))
(name obj)))
:else (list (if (:readably opts)
- (goog.string.quote obj)
+ (quote-string obj)
obj))))
function
@@ -6510,7 +6525,7 @@ reduces them without incurring seq initialization"
(write-all writer (str nspc) "/"))
(-write writer (name obj)))
:else (if (:readably opts)
- (-write writer (goog.string.quote obj))
+ (-write writer (quote-string obj))
(-write writer obj))))
function
@@ -1650,6 +1650,7 @@
(assert (= (pr-str true) "true"))
(assert (= (pr-str false) "false"))
(assert (= (pr-str "string") "\"string\""))
+ (assert (= (pr-str ["üñîçó∂£" :ทดสอบ/你好 'こんにちは]) "[\"üñîçó∂£\" :ทดสอบ/你好 こんにちは]"))
(assert (= (pr-str "escape chars \t \r \n \\ \" \b \f") "\"escape chars \\t \\r \\n \\\\ \\\" \\b \\f\""))
;;; pr-str records

0 comments on commit 3b32345

Please sign in to comment.