function | since v0.0-927 | clojure.string/escape | Edit |
(escape s cmap)
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.
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.
(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)))))))