guile-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Guile-commits] 05/05: Scheme peek-char can handle iconv encodings


From: Andy Wingo
Subject: [Guile-commits] 05/05: Scheme peek-char can handle iconv encodings
Date: Tue, 10 May 2016 10:51:24 +0000 (UTC)

wingo pushed a commit to branch wip-port-refactor
in repository guile.

commit 837a7e0810f27c2c00991015836fc45925d76fd7
Author: Andy Wingo <address@hidden>
Date:   Tue May 10 12:48:10 2016 +0200

    Scheme peek-char can handle iconv encodings
    
    * module/ice-9/ports.scm (peek-char-and-len/iconv): Fully implement.
---
 module/ice-9/ports.scm |   21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/module/ice-9/ports.scm b/module/ice-9/ports.scm
index a222e83..6078b6a 100644
--- a/module/ice-9/ports.scm
+++ b/module/ice-9/ports.scm
@@ -417,22 +417,21 @@ interpret its input and output."
   (values (integer->char first-byte) 1))
 
 (define (peek-char-and-len/iconv port first-byte)
-  (define (bad-input len)
-    (if (eq? (port-conversion-strategy port) 'substitute)
-        (values #\? len)
-        (decoding-error "peek-char" port)))
   (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) prev-input-size)
-        (if (zero? prev-input-size)
-            (values the-eof-object 0)
-            (bad-input prev-input-size)))
-       ;; fixme: takes port arg???
-       ((iconv1 port (port-buffer-bytevector buf) cur input-size
-                (port-conversion-strategy port))
+       ((< (- (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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]