aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStuart Sierra <mail@stuartsierra.com>2009-08-18 16:59:49 -0400
committerStuart Sierra <mail@stuartsierra.com>2009-08-18 16:59:49 -0400
commitc20fbee2d68fdcde18c7001f859d32513cf0bde6 (patch)
treeaef2b0e7343d32d01ce3adcbf5da8194a20478cc
parent3b6d95140393bf78930c9f4045ba2feab36f3946 (diff)
str_utils2.clj: fix escape so it actually works, add tests
-rw-r--r--src/clojure/contrib/str_utils2.clj2
-rw-r--r--src/clojure/contrib/test_contrib/str_utils2.clj9
2 files changed, 9 insertions, 2 deletions
diff --git a/src/clojure/contrib/str_utils2.clj b/src/clojure/contrib/str_utils2.clj
index ec2741ce..26dd849f 100644
--- a/src/clojure/contrib/str_utils2.clj
+++ b/src/clojure/contrib/str_utils2.clj
@@ -93,7 +93,7 @@
[#^String s cmap]
(let [buffer (StringBuilder. (.length s))]
(dochars [c s]
- (if-let [r (cmap s)]
+ (if-let [r (cmap c)]
(.append buffer r)
(.append buffer c)))
(.toString buffer)))
diff --git a/src/clojure/contrib/test_contrib/str_utils2.clj b/src/clojure/contrib/test_contrib/str_utils2.clj
index dac0893a..4b466774 100644
--- a/src/clojure/contrib/test_contrib/str_utils2.clj
+++ b/src/clojure/contrib/test_contrib/str_utils2.clj
@@ -41,4 +41,11 @@
(deftest t-codepoints
(is (= (list 102 111 111 65536 98 97 114)
(s/codepoints "foo\uD800\uDC00bar"))
- "Handles Unicode supplementary characters")))
+ "Handles Unicode supplementary characters"))
+
+(deftest t-escape
+ (is (= "&lt;foo&amp;bar&gt;"
+ (s/escape "<foo&bar>" {\& "&amp;" \< "&lt;" \> "&gt;"})))
+ (is (= " \\\"foo\\\" "
+ (s/escape " \"foo\" " {\" "\\\""})))
+ (is (= "faabor" (s/escape "foobar" {\a \o, \o \a}))))