Outdated egg!

This is an egg for CHICKEN 4, the unsupported old release. You're almost certainly looking for the CHICKEN 5 version of this egg, if it exists.

If it does not exist, there may be equivalent functionality provided by another egg; have a look at the egg index. Otherwise, please consider porting this egg to the current version of CHICKEN.

iconv

Introduction

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).

Examples

Converting

(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))))

Authors

This egg was created by Alejandro Forero Cuervo.

License

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.

Conversion

make-iconv

[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.

Version history

2.0
Port to CHICKEN 5, simplify API. [Chris Brannon]
1.5
Use of 'foreign-safe-lambda*'. [Kon Lovett]
1.4
Links with libiconv when (software-version) is unknown. This is the case of Cygwin, which requires libiconv. This was suggested by Dekai Wu.
1.3
Links with libiconv on Mac OS X.
1.2
Uses callback to allocate result buffer.
1.1
First release.