Skip to content

Instantly share code, notes, and snippets.

@sw1nn
Created March 2, 2012 13:48
Show Gist options
  • Save sw1nn/1958497 to your computer and use it in GitHub Desktop.
Save sw1nn/1958497 to your computer and use it in GitHub Desktop.
;; 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