mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-09 21:40:33 +02:00
Scheme peek-char can handle iconv encodings
* module/ice-9/ports.scm (peek-char-and-len/iconv): Fully implement.
This commit is contained in:
parent
8ee189980d
commit
837a7e0810
1 changed files with 10 additions and 11 deletions
|
@ -417,22 +417,21 @@ interpret its input and output."
|
||||||
(values (integer->char first-byte) 1))
|
(values (integer->char first-byte) 1))
|
||||||
|
|
||||||
(define (peek-char-and-len/iconv port first-byte)
|
(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 lp ((prev-input-size 0))
|
||||||
(let* ((input-size (1+ prev-input-size))
|
(let* ((input-size (1+ prev-input-size))
|
||||||
(buf (fill-input port input-size))
|
(buf (fill-input port input-size))
|
||||||
(cur (port-buffer-cur buf)))
|
(cur (port-buffer-cur buf)))
|
||||||
(cond
|
(cond
|
||||||
((<= (- (port-buffer-end buf) cur) prev-input-size)
|
((< (- (port-buffer-end buf) cur) input-size)
|
||||||
(if (zero? prev-input-size)
|
;; Buffer failed to fill; EOF, possibly premature.
|
||||||
(values the-eof-object 0)
|
(cond
|
||||||
(bad-input prev-input-size)))
|
((zero? prev-input-size)
|
||||||
;; fixme: takes port arg???
|
(values the-eof-object 0))
|
||||||
((iconv1 port (port-buffer-bytevector buf) cur input-size
|
((eq? (port-conversion-strategy port) 'substitute)
|
||||||
(port-conversion-strategy port))
|
(values #\? prev-input-size))
|
||||||
|
(else
|
||||||
|
(decoding-error "peek-char" port))))
|
||||||
|
((port-decode-char port (port-buffer-bytevector buf) cur input-size)
|
||||||
=> (lambda (char)
|
=> (lambda (char)
|
||||||
(values char input-size)))
|
(values char input-size)))
|
||||||
(else
|
(else
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue