mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-09 13:30:26 +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))
|
||||
|
||||
(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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue