~ chicken-core (chicken-5) 64659c6a7f436bd278c769020955556f58991d46
commit 64659c6a7f436bd278c769020955556f58991d46
Author: Evan Hanson <evhan@foldling.org>
AuthorDate: Mon May 27 16:18:53 2013 +1200
Commit: Moritz Heidkamp <moritz@twoticketsplease.de>
CommitDate: Thu May 30 19:00:06 2013 +0200
handle CR & CRLF-terminated lines when collapsing intraline whitespace
Signed-off-by: Peter Bex <peter.bex@xs4all.nl>
Signed-off-by: Moritz Heidkamp <moritz@twoticketsplease.de>
diff --git a/library.scm b/library.scm
index 7b967c63..77278157 100644
--- a/library.scm
+++ b/library.scm
@@ -2523,12 +2523,19 @@ EOF
(loop (##sys#read-char-0 port) (r-cons-codepoint n lst)) )))
((#\\ #\' #\" #\|)
(loop (##sys#read-char-0 port) (cons c lst)))
- ((#\newline #\space #\tab)
+ ((#\newline #\return #\space #\tab)
;; Read "escaped" <intraline ws>* <nl> <intraline ws>*
(let eat-ws ((c c) (nl? #f))
(case c
((#\space #\tab)
(eat-ws (##sys#read-char-0 port) nl?))
+ ((#\return)
+ (if nl?
+ (loop c lst)
+ (let ((nc (##sys#read-char-0 port)))
+ (if (eq? nc #\newline) ; collapse \r\n
+ (eat-ws (##sys#read-char-0 port) #t)
+ (eat-ws nc #t)))))
((#\newline)
(if nl?
(loop c lst)
diff --git a/tests/r7rs-tests.scm b/tests/r7rs-tests.scm
index 84a95d13..f47eacd5 100644
--- a/tests/r7rs-tests.scm
+++ b/tests/r7rs-tests.scm
@@ -119,11 +119,17 @@
;; *ONE* line ending following a backslash escape, along with any
;; preceding or trailing intraline whitespace is collapsed and ignored.
(test #\E escaped-char (string-append (string #\newline) " END"))
+;; This also works with CR instead of LF...
+(test #\E escaped-char (string-append (string #\return) " END"))
+;; And CRLF, too
+(test #\E escaped-char (string-append (string #\return) (string #\newline) " END"))
(test #\E escaped-char (string-append " " (string #\newline) "END"))
(test #\E escaped-char (string-append " " (string #\newline) "END"))
(test #\E escaped-char (string-append " " (string #\newline) " END"))
;; But not more than one!
(test #\newline escaped-char (string-append " " (string #\newline) " " (string #\newline) " END"))
+;; CR and LF both counted
+(test #\newline escaped-char (string-append " " (string #\return) " " (string #\newline) " END"))
;; Tabs count as intraline whitespace too
(test #\E escaped-char (string-append (string #\tab) (string #\newline) (string #\tab) " END"))
;; Edge case
Trap