Commits

Anonymous committed b25e08f

rename bitstring-append to destructive bitstring-append!

  • Participants
  • Parent commits b302886

Comments (0)

Files changed (2)

File bitstring.scm

    bitstring-read
    bitstring-share
    bitstring=?
-   bitstring-append 
+   bitstring-append! 
    bitstring-create
    bitstring->list
    bitstring->blob
     ((_ "write" stream name continuation)
       (and-let* ((tmp (bitstring-of-any name)))
         ;(print "write-expand:" `stream " name:" `name)
-      	(bitstring-append stream tmp)
+      	(bitstring-append! stream tmp)
       	continuation))
     ((_ "write" stream name bits type continuation)
       (and-let* ((tmp (bitstring-write-expand name bits type)))
         ;(print "write-expand:" `stream " name:" `name)
-      	(bitstring-append stream tmp)
+      	(bitstring-append! stream tmp)
       	continuation))
     ((_ "read" stream name continuation) ; read all rest bytes
       (symbol?? name
     (bitstring-setter-set! bs bitstring-default-setter)
     (bitstring-getter-set! bs bitstring-default-getter)))
 
-(define (bitstring-append dest src)
+(define (bitstring-append! dest src)
   ; need ensure that dest buffer long enough
   (let ((required (bitstring-length src))
         (position (bitstring-numbits dest))

File tests/run.scm

 (test-begin "append")
 ; append aligned
 (define bs (bitstring-create))
-(bitstring-append bs (bitstring-of-any "A"))
-(bitstring-append bs (bitstring-of-any "B"))
-(bitstring-append bs (bitstring-of-any "\x20"))
+(bitstring-append! bs (bitstring-of-any "A"))
+(bitstring-append! bs (bitstring-of-any "B"))
+(bitstring-append! bs (bitstring-of-any "\x20"))
 (test #t (bitstring=? bs (bitstring-of-any "AB\x20")))
 ; append unaligned
 (define bs (bitstring-create))
-(bitstring-append bs (integer->bitstring-big #b100 3))
-(bitstring-append bs (integer->bitstring-big #b10 2))
-(bitstring-append bs (integer->bitstring-big #b1 1))
-(bitstring-append bs (integer->bitstring-big #b0101 4))
-(bitstring-append bs (integer->bitstring-big #b10 2))
-(bitstring-append bs (integer->bitstring-big #b0 1))
-(bitstring-append bs (integer->bitstring-big #b10100 5))
+(bitstring-append! bs (integer->bitstring-big #b100 3))
+(bitstring-append! bs (integer->bitstring-big #b10 2))
+(bitstring-append! bs (integer->bitstring-big #b1 1))
+(bitstring-append! bs (integer->bitstring-big #b0101 4))
+(bitstring-append! bs (integer->bitstring-big #b10 2))
+(bitstring-append! bs (integer->bitstring-big #b0 1))
+(bitstring-append! bs (integer->bitstring-big #b10100 5))
 (test #b100101010110010100 (bitstring->integer-big bs))
 ; append unaligned with overflow
 (define bs (bitstring-create))
-(bitstring-append bs (integer->bitstring-big #b100111010 9))
-(bitstring-append bs (integer->bitstring-big #b1000111100100 13))
+(bitstring-append! bs (integer->bitstring-big #b100111010 9))
+(bitstring-append! bs (integer->bitstring-big #b1000111100100 13))
 (test #b1001110101000111100100 (bitstring->integer-big bs))
 (define bs (bitstring-create))
-(bitstring-append bs (integer->bitstring-big #b0 1))
-(bitstring-append bs (integer->bitstring-big #b01001011011101 14))
-(bitstring-append bs (integer->bitstring-big #b110001 6))
-(bitstring-append bs (integer->bitstring-big #b10100011100 11))
+(bitstring-append! bs (integer->bitstring-big #b0 1))
+(bitstring-append! bs (integer->bitstring-big #b01001011011101 14))
+(bitstring-append! bs (integer->bitstring-big #b110001 6))
+(bitstring-append! bs (integer->bitstring-big #b10100011100 11))
 (test #b00100101101110111000110100011100 (bitstring->integer-big bs))
 ; append with resize
 (define bs (bitstring-create))
 (let ((a "Is There Love")
       (b "in Space?")
       (c "Nobody knows."))
-  (bitstring-append bs (bitstring-of-any a))
-  (bitstring-append bs (bitstring-of-any b))
+  (bitstring-append! bs (bitstring-of-any a))
+  (bitstring-append! bs (bitstring-of-any b))
   (test #t (bitstring=? (bitstring-of-any (string-append a b)) bs))
-  (bitstring-append bs (bitstring-of-any c))
+  (bitstring-append! bs (bitstring-of-any c))
   (test #t (bitstring=? (bitstring-of-any (string-append a b c)) bs)))
 (test-end)