Skip to content

Instantly share code, notes, and snippets.

@jeremyheiler
Last active December 19, 2015 10:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeremyheiler/5940103 to your computer and use it in GitHub Desktop.
Save jeremyheiler/5940103 to your computer and use it in GitHub Desktop.
Read a line that ends with a CRLF.
(defn get-line
[reader]
(loop [last-cr? false line (StringBuilder.)]
(let [i (.read reader)]
(if (neg? i)
(str line)
(let [c (char i)]
(if (and last-cr? (= c \newline))
(.substring line 0 (dec (.length line)))
(recur (= c \return) (.append line c))))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment