source: project/release/5/blob-utils/trunk/blob-hexadecimal.scm @ 38917

Last change on this file since 38917 was 38917, checked in by Kon Lovett, 2 months ago

add -strict-types, fix pack-integer single-byte error (arg order), group types

File size: 1.1 KB
Line 
1;;;; blob-hexadecimal.scm  -*- Scheme -*-
2;;;; Kon Lovett, Jul '18
3;;;; Kon Lovett, Apr '11
4
5(declare
6  (bound-to-procedure
7    ##sys#signal-hook))
8
9(module blob-hexadecimal
10
11(;export
12  blob->hex)
13
14(import scheme)
15(import (chicken base))
16(import (chicken fixnum))
17(import (chicken blob))
18(import (chicken foreign))
19(import (chicken type))
20(import (only to-hex blob_to_hex))
21(import (only type-checks check-natural-fixnum check-blob))
22
23;;
24
25(: blob->hex (blob #!optional fixnum (or fixnum boolean) -> string))
26
27;;
28
29(define (blob->hex blb #!optional (start 0) (end #f))
30  (check-blob 'blob->hex blb)
31  (check-natural-fixnum 'blob->hex start 'start)
32  (when end (check-natural-fixnum 'blob->hex end 'end))
33  (let ((end (or end (blob-size blb))))
34    (unless (fx<= start end)
35      (##sys#signal-hook
36        #:bounds-error 'blob->hex "illegal subvector specification" start end))
37    (let ((len (fx- end start)))
38      (if (fx= 0 len)
39        ""
40        (let ((res (make-string (fx* len 2))))
41          (blob_to_hex res blb start len)
42          res ) ) ) ) )
43
44) ;module blob-hexadecimal
Note: See TracBrowser for help on using the repository browser.