Created
March 2, 2012 13:48
-
-
Save sw1nn/1958497 to your computer and use it in GitHub Desktop.
mostly optimized version of https://github.com/jaley/curly/blob/92a21267f9772cd5eb93a2306612978b15b0c031/src/curly/core.clj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; mutate a StringBuilder in place. Listen for the sound of a clojure bunny dying somewhere.. | |
;; | |
(defn remove-curlied-optimized2 | |
"Remove {something} from a string or {something else}" | |
[^String text] | |
(let [ tb (StringBuilder. text)] | |
(loop [lo (.lastIndexOf tb "{" ) | |
lc (.indexOf tb "}" lo)] | |
(assert (<= lo lc)) ; sanity check. | |
(if (= -1 lo) | |
(.toString tb) | |
(do | |
(.delete tb lo (inc lc)) | |
(let [nlo (.lastIndexOf tb "{")] | |
(recur nlo (.indexOf tb "}" nlo)))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment