mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-07-16 17:37:34 +02:00
Fixing make-generated-input-port for non-ascii chars.
This commit is contained in:
parent
76a4cfa952
commit
35500df1d6
2 changed files with 33 additions and 6 deletions
|
@ -349,9 +349,10 @@
|
|||
((>= (- len offset) n)
|
||||
(string-copy! str start buf offset (+ offset n))
|
||||
(set! offset (+ offset n))
|
||||
n)
|
||||
(- (string-index->offset str end)
|
||||
(string-index->offset str start)))
|
||||
(else
|
||||
(string-copy! str start buf offset (+ offset len))
|
||||
(string-copy! str start buf offset len)
|
||||
(let lp ((i (+ start (- len offset))))
|
||||
(set! buf (generator))
|
||||
(cond
|
||||
|
@ -359,15 +360,17 @@
|
|||
(set! buf "")
|
||||
(set! len 0)
|
||||
(set! offset 0)
|
||||
(- i start))
|
||||
(- (string-index->offset str i)
|
||||
(string-index->offset str start)))
|
||||
(else
|
||||
(set! len (string-length buf))
|
||||
(set! offset 0)
|
||||
(cond
|
||||
((>= (- len offset) (- n i))
|
||||
(string-copy! str i buf offset (+ offset (- n i)))
|
||||
(set! offset (+ offset (- n i)))
|
||||
n)
|
||||
(string-copy! str i buf 0 (- n i))
|
||||
(set! offset (- n i))
|
||||
(- (string-index->offset str end)
|
||||
(string-index->offset str start)))
|
||||
(else
|
||||
(string-copy! str i buf offset len)
|
||||
(lp (+ i (- len offset)))))))))))))))
|
||||
|
|
|
@ -89,6 +89,30 @@
|
|||
(display "abc" out)
|
||||
(close-output-port out)))))
|
||||
|
||||
(define (strings->input-port str-ls)
|
||||
(make-generated-input-port
|
||||
(lambda ()
|
||||
(and (pair? str-ls)
|
||||
(let ((res (car str-ls)))
|
||||
(set! str-ls (cdr str-ls))
|
||||
res)))))
|
||||
|
||||
(test "abcdef" (read-line (strings->input-port '("abcdef"))))
|
||||
(test "abcdef" (read-line (strings->input-port '("abc" "def"))))
|
||||
(test "abcdef" (read-line (strings->input-port '("a" "b" "c" "d" "e" "f"))))
|
||||
(test "日本語" (read-line (strings->input-port '("日本語"))))
|
||||
(test "日本語" (read-line (strings->input-port '("日" "本" "語"))))
|
||||
(test "abc"
|
||||
(let ((in (strings->input-port
|
||||
(list "日本語" (make-string 4087 #\-) "abc"))))
|
||||
(read-string 4090 in)
|
||||
(read-line in)))
|
||||
(test "abc"
|
||||
(let ((in (strings->input-port
|
||||
(list "日本語" (make-string 4093 #\-) "abc"))))
|
||||
(read-string 4096 in)
|
||||
(read-line in)))
|
||||
|
||||
(let ((in (make-custom-binary-input-port
|
||||
(let ((i 0))
|
||||
(lambda (bv start end)
|
||||
|
|
Loading…
Add table
Reference in a new issue