[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 04/06: peek-char-and-len/iconv uses both returns from fi
From: |
Andy Wingo |
Subject: |
[Guile-commits] 04/06: peek-char-and-len/iconv uses both returns from fill-input |
Date: |
Tue, 10 May 2016 13:41:18 +0000 (UTC) |
wingo pushed a commit to branch wip-port-refactor
in repository guile.
commit 3ccfa213c10af1db748597123ee982b4e4069275
Author: Andy Wingo <address@hidden>
Date: Tue May 10 15:37:42 2016 +0200
peek-char-and-len/iconv uses both returns from fill-input
* module/ice-9/ports.scm (peek-char-and-len/iconv): Use buffered value
from fill-input.
---
module/ice-9/ports.scm | 37 +++++++++++++++++++------------------
1 file changed, 19 insertions(+), 18 deletions(-)
diff --git a/module/ice-9/ports.scm b/module/ice-9/ports.scm
index e672b2c..742e702 100644
--- a/module/ice-9/ports.scm
+++ b/module/ice-9/ports.scm
@@ -419,24 +419,25 @@ interpret its input and output."
(define (peek-char-and-len/iconv port first-byte)
(let lp ((prev-input-size 0))
- (let* ((input-size (1+ prev-input-size))
- (buf (fill-input port input-size))
- (cur (port-buffer-cur buf)))
- (cond
- ((< (- (port-buffer-end buf) cur) input-size)
- ;; Buffer failed to fill; EOF, possibly premature.
- (cond
- ((zero? prev-input-size)
- (values the-eof-object 0))
- ((eq? (port-conversion-strategy port) 'substitute)
- (values #\? prev-input-size))
- (else
- (decoding-error "peek-char" port))))
- ((port-decode-char port (port-buffer-bytevector buf) cur input-size)
- => (lambda (char)
- (values char input-size)))
- (else
- (lp input-size))))))
+ (let ((input-size (1+ prev-input-size)))
+ (call-with-values (lambda () (fill-input port input-size))
+ (lambda (buf buffered)
+ (cond
+ ((< buffered input-size)
+ ;; Buffer failed to fill; EOF, possibly premature.
+ (cond
+ ((zero? prev-input-size)
+ (values the-eof-object 0))
+ ((eq? (port-conversion-strategy port) 'substitute)
+ (values #\? prev-input-size))
+ (else
+ (decoding-error "peek-char" port))))
+ ((port-decode-char port (port-buffer-bytevector buf)
+ (port-buffer-cur buf) input-size)
+ => (lambda (char)
+ (values char input-size)))
+ (else
+ (lp input-size))))))))
(define (peek-char-and-len port)
(let ((first-byte (peek-byte port)))
- [Guile-commits] branch wip-port-refactor updated (837a7e0 -> d28d1a5), Andy Wingo, 2016/05/10
- [Guile-commits] 03/06: Fix bad-utf8-len bug., Andy Wingo, 2016/05/10
- [Guile-commits] 01/06: Fix port-clear-stream-start-for-bom-read logic., Andy Wingo, 2016/05/10
- [Guile-commits] 04/06: peek-char-and-len/iconv uses both returns from fill-input,
Andy Wingo <=
- [Guile-commits] 02/06: clear-stream-start-for-bom-read refactor, Andy Wingo, 2016/05/10
- [Guile-commits] 05/06: %peek-char port argument optional., Andy Wingo, 2016/05/10
- [Guile-commits] 06/06: Implement read-char in Scheme., Andy Wingo, 2016/05/10