Wiki
Download
Manual
Eggs
API
Tests
Bugs
show
edit
history
You can edit this page using
wiki syntax
for markup.
Article contents:
== bvconv [[toc:]] === Description '''bvconv''' is CHICKEN6 iconv (man 3 iconv) glibc 'adapter'. Actually bvconv similar to '''iconv''' CHICKEN5 Egg. On bytevectors, or utf8 strings in R7RS manner. And args FROM and TO was swapped. === Authors [[e-mail-to:corbas.ai@gmail.com|Anton Idukov]] === Repository Sorces hosted on Codeberg https://codeberg.org/Corbas/bvconv === Requirements Just glibc or (unproven) musl. === API ==== make-conv <procedure>(make-conv FROMENC TOENC)</procedure> To make converter closure use '''make-conv''' procedure with positional args FROMENC - string - encoding name for example "ISO_8859-1" and TOENC - maybe "UTF-8". The list of available encodings we get by shell command '''iconv --list''' ==== make-conv* <procedure>(make-conv* #!keyword from to)</procedure> Same as '''make-conv''' but with keyword args '''#:from''' and '''#:to''' === Example <enscript highlight="scheme"> (import bvconv) ;; From String source we've got String result: (let* ((t "Hello") (cv (make-conv "ASCII" "UTF-8")) (converted (cv t))) (display (list converted "string?" (string? converted))) (newline)) ==> (Hello string? #t) ;; From Bytevector source we've got Bytevector result: (let ((v ((make-conv "L1" "UTF-8") #u8("Hello")))) (display (list v " bytevector? " (bytevector? v))) (newline)) ==> (#u8(72 101 108 108 111) bytevector? #t) ;; We can make reverser closure from converter closure (let* ((cv (make-conv "ASCII" "EBCDICUS")) (vc (cv'reverse)) (t #u8("Hello"))) (display (list t "->" (cv t) "->" (vc (cv t)) ":" (utf8->string (vc (cv t))))) (newline)) ==> (#u8(72 101 108 108 111) -> #u8(200 133 147 147 150) -> #u8(72 101 108 108 111) : Hello) ;; We can catch iconv error conditions by special second param to converter closure ;; (: err (bytevector fixnum fixnum -> void)) (define (err src pos errno) (raise `(bvconv-error ,errno ,pos))) (guard (ex ((and (pair? ex) (eq? (car ex) 'bvconv-error) (number? (cadr ex))) (display (string-append "!Error: " (let ((errno (cadr ex))) (cond ((= errno EINVAL) "invalid value") ((= errno E2BIG) "source converts into bit bigger than destination") ((= errno EILSEQ) "wrong source char sequence") ((= error EBADF) "bad file" ) (else "wrong answer on a bad question!"))) "\n"))) (#t (display ex) (newline))) (let ((cv (make-conv "ASCII" "UTF8"))) (cv "СОЛНЦЕ" err))) ==> !Error: wrong source char sequence </enscript> === Source code [[https://codeberg.org/Corbas/bvconv|bvconv at Codeberg]] === Licence BSD-2-Clause licence. === Version History 1.0.2 Initial release
Description of your changes:
I would like to authenticate
Authentication
Username:
Password:
Spam control
What do you get when you subtract 22 from 4?