mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-30 06:50:31 +02:00
clear-stream-start-for-bom-read refactor
* module/ice-9/ports.scm (clear-stream-start-for-bom-read): Use the "buffered" value that fill-input returns.
This commit is contained in:
parent
502e3a2213
commit
0dd18191bc
1 changed files with 14 additions and 13 deletions
|
@ -212,19 +212,20 @@ interpret its input and output."
|
||||||
(define (clear-stream-start-for-bom-read port io-mode)
|
(define (clear-stream-start-for-bom-read port io-mode)
|
||||||
(define (maybe-consume-bom bom)
|
(define (maybe-consume-bom bom)
|
||||||
(and (eq? (peek-byte port) (bytevector-u8-ref bom 0))
|
(and (eq? (peek-byte port) (bytevector-u8-ref bom 0))
|
||||||
(let* ((buf (fill-input port (bytevector-length bom)))
|
(call-with-values (lambda ()
|
||||||
(bv (port-buffer-bytevector buf))
|
(fill-input port (bytevector-length bom)))
|
||||||
(cur (port-buffer-cur bv)))
|
(lambda (buf buffered)
|
||||||
(and (<= (bytevector-length bv)
|
(and (<= (bytevector-length bom) buffered)
|
||||||
(- (port-buffer-end buf) cur))
|
(let ((bv (port-buffer-bytevector buf))
|
||||||
(let lp ((i 1))
|
(cur (port-buffer-cur buf)))
|
||||||
(if (= i (bytevector-length bom))
|
(let lp ((i 1))
|
||||||
(begin
|
(if (= i (bytevector-length bom))
|
||||||
(set-port-buffer-cur! buf (+ cur i))
|
(begin
|
||||||
#t)
|
(set-port-buffer-cur! buf (+ cur i))
|
||||||
(and (eq? (bytevector-u8-ref bv (+ cur i))
|
#t)
|
||||||
(bytevector-u8-ref bom i))
|
(and (eq? (bytevector-u8-ref bv (+ cur i))
|
||||||
(lp (1+ i)))))))))
|
(bytevector-u8-ref bom i))
|
||||||
|
(lp (1+ i)))))))))))
|
||||||
(when (and (port-clear-stream-start-for-bom-read port)
|
(when (and (port-clear-stream-start-for-bom-read port)
|
||||||
(eq? io-mode 'text))
|
(eq? io-mode 'text))
|
||||||
(case (%port-encoding port)
|
(case (%port-encoding port)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue