clojure.string/escape

functionsince v0.0-927 clojure.string/escapeEdit
(escape s cmap)

Details:

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.


Source docstring:
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.
Source code @ clojurescript:src/main/cljs/clojure/string.cljs
(defn ^string escape
  [s cmap]
  (let [buffer (StringBuffer.)
        length (.-length s)]
    (loop [index 0]
      (if (== length index)
        (. buffer (toString))
        (let [ch (.charAt s index)
              replacement (cmap ch)]
          (if-not (nil? replacement)
            (.append buffer (str replacement))
            (.append buffer ch))
          (recur (inc index)))))))