(defn escape-html [^String s]
(let [len (count s)]
(loop [^StringBuilder sb nil
i (int 0)]
(if (< i len)
(let [char (.charAt s i)
repl (case char
\& "&"
\< "<"
\> ">"
\" """
\' "'"
nil)]
(if (nil? repl)
(if (nil? sb)
(recur nil (inc i))
(recur (doto sb
(.append char))
(inc i)))
(if (nil? sb)
(recur (doto (StringBuilder.)
(.append s 0 i)
(.append repl))
(inc i))
(recur (doto sb
(.append repl))
(inc i)))))
(if (nil? sb) s (str sb))))))