Outdated egg!

This is an egg for CHICKEN 3, the unsupported old release. You're almost certainly looking for the CHICKEN 4 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.

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

(use iconv)

; First we obtain a conversion descriptor.  In this case we will convert
; from latin1 to utf-8:

(define *desc* (iconv-open "utf-8" "latin1"))

; Read lines from the input, convert them and write them:

(let loop ((line (read-line)))
  (unless (eof-object? line)
    (display (iconv *desc* 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

iconv-open

[procedure] (iconv-open TOCODE FROMCODE)

Allocate a conversion descriptor 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 resulting conversion descriptor can be used with iconv any number of times.

iconv

[procedure] (iconv CD SRC [INVALID [DSTLEN]])

The argument cd must be a conversion descriptor created using the function iconv-open. iconv converts the multibyte sequence SRC (a string) according to the character sets specified when CD was created.

If an invalid character is found (because of an invalid or incomplete multibyte character sequence), one byte is skipped from the input and the string INVALID, which defaults to "?", is used.

DSTLEN is an integer specifying the initial size for the buffer where the results are stored. The buffer will be dynamically adjusted to hold the entire result.

The resulting string is returned (or #f if the implementation runs out of memory).

Version history

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.