Changeset 16144 in project


Ignore:
Timestamp:
10/07/09 09:31:19 (10 years ago)
Author:
Ivan Raikov
Message:

added byte-blob-span

Location:
release/4/byte-blob/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • release/4/byte-blob/trunk/byte-blob.scm

    r16143 r16144  
    5353         byte-blob-intersperse
    5454         byte-blob-take
    55          byte-blob-drop
     55         byte-blob-drop
     56         byte-blob-span
    5657         byte-blob-map
    5758         byte-blob-fold-left
     
    233234
    234235(define (byte-blob-drop b n)
    235   (assert (positive? n))
    236236  (let ((blen   (byte-blob-size b)))
    237     (if (< blen n) (byte-blob-empty)
    238         (let* ((ob     (byte-blob-object b))
    239                (ob1    (make-blob (- blen n))))
    240           (move-memory! ob ob1 (- blen n) (+ n (byte-blob-offset b)) 0)
    241           (make-byte-blob ob1 0)))))
    242  
    243 
     237    (assert (and (positive? n) (< n blen)))
     238    (byte-blob-copy b (+ n (byte-blob-offset b)))))
     239
     240
     241(define (byte-blob-span b start end)
     242  (assert (and (positive? start) (positive? end) (< start end)))
     243  (byte-blob-take (byte-blob-drop b start) (- end start)))
    244244
    245245(define (byte-blob-map f b)
  • release/4/byte-blob/trunk/tests/run.scm

    r16143 r16144  
    2727            (test (sprintf "byte-blob-append" )
    2828                   '(1 2 3 4 7 8 9) (byte-blob->list (byte-blob-append a b c)))
     29
     30            (test (sprintf "byte-blob-take" )
     31                   '(1 2 ) (byte-blob->list (byte-blob-take (byte-blob-append a b c) 2)))
     32
     33            (test (sprintf "byte-blob-drop" )
     34                   '(3 4 7 8 9) (byte-blob->list (byte-blob-drop (byte-blob-append a b c) 2)))
     35
     36            (test (sprintf "byte-blob-span" )
     37                   '(3 4 7) (byte-blob->list (byte-blob-span (byte-blob-append a b c) 2 5)))
    2938
    3039            (test (sprintf "byte-blob-map" )
Note: See TracChangeset for help on using the changeset viewer.