>From ffae85a6998808b35392ecdb4d061e4885d39b12 Mon Sep 17 00:00:00 2001
From: Evan Hanson
Date: Mon, 27 May 2013 16:18:53 +1200
Subject: [PATCH] handle CR & CRLF-terminated lines when collapsing intraline
whitespace
Signed-off-by: Peter Bex
---
library.scm | 9 ++++++++-
tests/r7rs-tests.scm | 6 ++++++
2 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/library.scm b/library.scm
index 68165d9..d8264da 100644
--- a/library.scm
+++ b/library.scm
@@ -2521,12 +2521,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" * *
(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 c0f6ebd..89f2e7d 100644
--- a/tests/r7rs-tests.scm
+++ b/tests/r7rs-tests.scm
@@ -111,11 +111,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
--
1.7.12