Last active
December 19, 2015 10:28
-
-
Save jeremyheiler/5940103 to your computer and use it in GitHub Desktop.
Read a line that ends with a CRLF.
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
(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