[racket-dev] hex decoding?

From: David Vanderson (david.vanderson at gmail.com)
Date: Wed Sep 4 13:23:08 EDT 2013

Sorry it took so long, but I've submitted a pull request to make this 
function public in file/sha1:

https://github.com/plt/racket/pull/426

Let me know if I screwed up, it's my first pull request.

Thanks,
Dave

On 06/11/2013 05:11 PM, Robby Findler wrote:
> Yes, I think file/sha1 is the right place.
>
> Thanks!
>
> Robby
>
>
> On Tue, Jun 11, 2013 at 3:26 PM, David Vanderson 
> <david.vanderson at gmail.com <mailto:david.vanderson at gmail.com>> wrote:
>
>     Thank you Stephen and Tony for your examples.  I found the
>     following private function in db/private/mysql/connection.rkt:
>
>     (define (hex-string->bytes s)
>       (define (hex-digit->int c)
>         (let ([c (char->integer c)])
>           (cond [(<= (char->integer #\0) c (char->integer #\9))
>                  (- c (char->integer #\0))]
>                 [(<= (char->integer #\a) c (char->integer #\f))
>                  (+ 10 (- c (char->integer #\a)))]
>                 [(<= (char->integer #\A) c (char->integer #\F))
>                  (+ 10 (- c (char->integer #\A)))])))
>       (unless (and (string? s) (even? (string-length s))
>                    (regexp-match? #rx"[0-9a-zA-Z]*" s))
>         (raise-type-error 'hex-string->bytes
>                           "string containing an even number of
>     hexadecimal digits" s))
>       (let* ([c (quotient (string-length s) 2)]
>              [b (make-bytes c)])
>         (for ([i (in-range c)])
>           (let ([high (hex-digit->int (string-ref s (+ i i)))]
>                 [low  (hex-digit->int (string-ref s (+ i i 1)))])
>             (bytes-set! b i (+ (arithmetic-shift high 4) low))))
>         b))
>
>
>     Can this function be exported?  I'm willing to make a patch with
>     docs and tests - is file/sha1 the right place?
>
>
>     Thanks,
>     Dave
>
>     _________________________
>      Racket Developers list:
>     http://lists.racket-lang.org/dev
>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/dev/archive/attachments/20130904/3fb80d0b/attachment.html>

Posted on the dev mailing list.