Created
March 1, 2012 18:30
-
-
Save jaley/1951985 to your computer and use it in GitHub Desktop.
Remove text surrounded by curly braces.
This file contains hidden or 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
(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