Allows conversion of multi-byte sequences from one character set (encoding) to another by means of the iconv functionality present in glibc (and thus is probably not very portable).
(import iconv) ; First we obtain a converter procedure. In this case we will convert ; from latin1 to utf-8: (define latin1->utf8 (make-iconv "utf-8" "latin1")) ; Read lines from the input, convert them and write them: (let loop ((line (read-line))) (unless (eof-object? line) (display (latin1->utf8 line)) (newline) (loop (read-line))))
This egg was created by Alejandro Forero Cuervo.
The iconv egg for Chicken Scheme is in the public domain and may be reproduced or copied without permission from its author. Citation of the source is appreciated.
[procedure] (make-iconv TOCODE FROMCODE)
Create a converter procedure suitable for converting byte sequences from character encoding FROMCODE (a string) to character encoding TOCODE (a string).
The values permitted for FROMCODE and TOCODE and the supported combinations are system dependent. For the GNU C library, the permitted values are listed by the iconv --list command, and all combinations of the listed values are supported.
The returned procedure takes a string encoded in FROMCODE and returns a new string encoded in TOCODE.
The resulting converter procedure can be used any number of times.
- Port to CHICKEN 5, simplify API. [Chris Brannon]
- Use of 'foreign-safe-lambda*'. [Kon Lovett]
- Links with libiconv when (software-version) is unknown. This is the case of Cygwin, which requires libiconv. This was suggested by Dekai Wu.
- Links with libiconv on Mac OS X.
- Uses callback to allocate result buffer.
- First release.