Skip to content

Instantly share code, notes, and snippets.

@swannodette
Forked from jaley/curly.clj
Created March 1, 2012 19:41
Show Gist options
  • Save swannodette/1952549 to your computer and use it in GitHub Desktop.
Save swannodette/1952549 to your computer and use it in GitHub Desktop.
Remove text surrounded by curly braces.
(defn remove-curlied
[^String text]
(let [sb (StringBuilder.)
end (int (count text))]
(loop [state (int 0)
pos (int 0)]
(cond
(= pos end) (.toString sb)
(= (int (.charAt text pos)) (int \{)) (recur (inc state) (inc pos))
(= (int (.charAt text pos)) (int \})) (recur (dec state) (inc pos))
(zero? state) (do
(.append sb (int (.charAt text pos)))
(recur state (inc pos)))
:else (recur state (inc pos))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment