Skip to content

Instantly share code, notes, and snippets.

@schani
Created June 27, 2013 04:01
Show Gist options
  • Select an option

  • Save schani/5873850 to your computer and use it in GitHub Desktop.

Select an option

Save schani/5873850 to your computer and use it in GitHub Desktop.
diff --git a/samples/reverse.cljc b/samples/reverse.cljc
new file mode 100644
index 0000000..063e0df
--- /dev/null
+++ b/samples/reverse.cljc
@@ -0,0 +1,5 @@
+(ns cljc.user)
+(defn -main [& args]
+ (doseq [arg args]
+ (println (reverse arg))
+ (println (cljc.string/reverse arg))))
diff --git a/src/cljc/cljc/core.cljc b/src/cljc/cljc/core.cljc
index 954e3f0..07a5b0b 100644
--- a/src/cljc/cljc/core.cljc
+++ b/src/cljc/cljc/core.cljc
@@ -5939,3 +5939,32 @@ reduces them without incurring seq initialization"
0
:else
1))
+
+(ns cljc.string)
+
+;; Could also be used to implement string-quote.
+(defn escape
+ "Return a new string, using cmap to escape each character ch
+ from s as follows:
+
+ If (cmap ch) is nil, append ch to the new string.
+ If (cmap ch) is non-nil, append (str (cmap ch)) instead."
+ [s cmap]
+ (loop [sb (sb-make "")
+ cs (seq s)]
+ (if cs
+ (let [c (first cs)
+ replacement (or (cmap c) c)]
+ (recur (-append! sb (str replacement))
+ (next cs)))
+ (str sb))))
+
+(defn reverse
+ "Returns s with its characters reversed."
+ [s]
+ (apply str (cljc.core/reverse s)))
+
+(ns cljc.core)
+
+(defn- re-string-quote [s]
+ (cljc.string/escape s {\" "\\\""}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment