~ chicken-core (chicken-5) c78cdcd9347a1e501ccc8882cd8c1cadeb76f0c3
commit c78cdcd9347a1e501ccc8882cd8c1cadeb76f0c3 Author: Evan Hanson <evhan@foldling.org> AuthorDate: Mon Jan 18 23:31:53 2016 +1300 Commit: Evan Hanson <evhan@foldling.org> CommitDate: Tue Mar 8 22:52:33 2016 +1300 Make `read-string` return #!eof on empty input diff --git a/extras.scm b/extras.scm index a766d209..3b337981 100644 --- a/extras.scm +++ b/extras.scm @@ -165,7 +165,9 @@ (define ##sys#read-string/port (lambda (n p) (##sys#check-input-port p #t 'read-string) - (cond (n (##sys#check-fixnum n 'read-string) + (cond ((eof-object? (##sys#peek-char-0 p)) + (if (eq? n 0) "" #!eof)) + (n (##sys#check-fixnum n 'read-string) (let* ((str (##sys#make-string n)) (n2 (##sys#read-string! n str p 0)) ) (if (eq? n n2) @@ -175,7 +177,8 @@ (let ([out (open-output-string)] (buf (make-string read-string-buffer-size))) (let loop () - (let ((n (##sys#read-string! read-string-buffer-size + (let ((c (peek-char p)) + (n (##sys#read-string! read-string-buffer-size buf p 0))) (cond ((eq? n 0) (get-output-string out)) diff --git a/manual/Unit extras b/manual/Unit extras index 7c16be42..e66ea6ac 100644 --- a/manual/Unit extras +++ b/manual/Unit extras @@ -179,12 +179,14 @@ a string naming a file. Returns a list of strings, each string representing a li Read or write {{NUM}} characters from/to {{PORT}}, which defaults to the value of {{(current-input-port)}} or {{(current-output-port)}}, respectively. -If {{NUM}} is {{#f}} or not given, then all data -up to the end-of-file is read, or, in the case of {{write-string}} the whole -string is written. If no more input is available, {{read-string}} returns the -empty string. {{read-string!}} reads destructively into the given {{STRING}} argument, -but never more characters than would fit into {{STRING}}. If {{START}} is given, then -the read characters are stored starting at that position. + +If {{NUM}} is {{#f}} or not given, then all data up to the end-of-file is +read, or, in the case of {{write-string}} the whole string is written. If no +more input is available, {{read-string}} returns {{#!eof}}. + +{{read-string!}} reads destructively into the given {{STRING}} argument, but +never more characters than would fit into {{STRING}}. If {{START}} is given, +then the read characters are stored starting at that position. {{read-string!}} returns the actual number of characters read.Trap