add missing bytevector functions

This commit is contained in:
Yuichi Nishiwaki 2013-11-18 01:40:57 +09:00
parent 926924982d
commit 7352cf8bcf
2 changed files with 28 additions and 1 deletions

View File

@ -71,7 +71,7 @@
| 6.6 Characters | yes | |
| 6.7 Strings | yes | `substring` is not provided |
| 6.8 Vectors | yes | |
| 6.9 Bytevectors | incomplete | TODO: string<->utf8 conversion, etc |
| 6.9 Bytevectors | incomplete | TODO: string<->utf8 conversion |
| 6.10 Control features | incomplete | TODO: `string-map`, `vector-map`, ...etc |
| 6.11 Exceptions | yes | TODO: native error handling |
| 6.12 Environments and evaluation | N/A | |

View File

@ -519,3 +519,30 @@
((< i len)
v)
(bytevector-u8-set! v i (car l))))))
(define (bytevector-copy! to at from . opts)
(let ((start (if (pair? opts) (car opts) 0))
(end (if (>= (length opts) 2)
(cadr opts)
(bytevector-length from))))
(do ((i at (+ i 1))
(j start (+ j 1)))
((< j end))
(bytevector-u8-set! to i (bytevector-u8-ref from j)))))
(define (bytevector-copy v . opts)
(let ((start (if (pair? opts) (car opts) 0))
(end (if (>= (length opts) 2)
(cadr opts)
(bytevector-length v))))
(let ((res (make-bytevector (bytevector-length v))))
(bytevector-copy! res 0 v start end)
res)))
(define (bytevector-append . vs)
(define (bytevector-append-2-inv w v)
(let ((res (make-bytevector (+ (bytevector-length v) (bytevector-length w)))))
(bytevector-copy! res 0 v)
(bytevector-copy! res (bytevector-length v) w)
res))
(fold bytevector-append-2-inv #() vs))