From 71afd5d56a71fd475e7fa65638d0eac32c877be5 Mon Sep 17 00:00:00 2001 From: Alex Shinn Date: Mon, 16 Jul 2012 23:40:58 +0900 Subject: [PATCH] Acknowledging that I may never be free of the \r evil... --- lib/chibi/io/io.scm | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/lib/chibi/io/io.scm b/lib/chibi/io/io.scm index 6db5aa65..13c616f6 100644 --- a/lib/chibi/io/io.scm +++ b/lib/chibi/io/io.scm @@ -58,9 +58,15 @@ (and (not (equal? res "")) res))) (else (write-char ch out) - (if (eqv? ch #\newline) - (get-output-string out) - (lp)))))))))) + (cond + ((eqv? ch #\newline) + (get-output-string out)) + ((eqv? ch #\return) + (if (eqv? #\newline (peek-char in)) + (read-char in)) + (get-output-string out)) + (else + (lp))))))))))) (define (read-line . o) (let ((in (if (pair? o) (car o) (current-input-port))) @@ -70,11 +76,15 @@ (if (not res) eof (let ((len (string-length res))) - (if (and (> len 0) (eqv? #\newline (string-ref res (- len 1)))) - (if (and (> len 1) (eqv? #\return (string-ref res (- len 2)))) - (substring res 0 (- len 2)) - (substring res 0 (- len 1))) - res)))))) + (cond + ((and (> len 0) (eqv? #\newline (string-ref res (- len 1)))) + (if (and (> len 1) (eqv? #\return (string-ref res (- len 2)))) + (substring res 0 (- len 2)) + (substring res 0 (- len 1)))) + ((and (> len 0) (eqv? #\return (string-ref res (- len 1)))) + (substring res 0 (- len 1))) + (else + res))))))) ;;> @subsubsubsection{(read-string n [in])}