Commits

rivo  committed 8dd1cc3

immutable bitstring-append

  • Participants
  • Parent commits b25e08f

Comments (0)

Files changed (2)

File bitstring.scm

    bitstring-read
    bitstring-share
    bitstring=?
+   bitstring-append
    bitstring-append! 
    bitstring-create
    bitstring->list
     (bitstring-setter-set! bs bitstring-default-setter)
     (bitstring-getter-set! bs bitstring-default-getter)))
 
+(define (bitstring-append dest src)
+  (bitconstruct 
+    (dest bitstring)
+    (src bitstring)))
+
 (define (bitstring-append! dest src)
   ; need ensure that dest buffer long enough
   (let ((required (bitstring-length src))

File tests/run.scm

 (bitstring-append! bs (bitstring-of-any "B"))
 (bitstring-append! bs (bitstring-of-any "\x20"))
 (test #t (bitstring=? bs (bitstring-of-any "AB\x20")))
+; test immutable append
+(define a (bitstring-of-any "A"))
+(define b (bitstring-of-any "B"))
+(define c (bitstring-append a b))
+(test #t (bitstring=? (bitconstruct ("AB")) c))
+(test #t (bitstring=? (bitconstruct ("A")) a))
+(test #t (bitstring=? (bitconstruct ("B")) b))
+(test 16 (bitstring-length c))
 ; append unaligned
 (define bs (bitstring-create))
 (bitstring-append! bs (integer->bitstring-big #b100 3))