Marshalling Haskell String <-> UTF-8

Ross Paterson ross at soi.city.ac.uk
Wed Sep 1 06:13:23 EDT 2004


On Wed, Sep 01, 2004 at 10:16:23AM +0100, Bayley, Alistair wrote:
> I want to call a foreign C function that takes a UTF-8 encoded string as one
> of its arguments (and there's also a version of the function that receives
> UTF-16). Can someone point me to documentation or examples of how this would
> be done? AFAICT (reading the FFI spec) marshalling a String to a CString is
> locale-dependent, whereas I know that I want UTF-8/16.

The locale-dependent marshalling of CString described by the FFI spec
isn't yet implemented in the library.  There is some code by John Meacham
including UTF-8 conversion at

	http://www.haskell.org/pipermail/ffi/2003-August/001355.html

> Can I use the UTF-16 functions directly with CWStrings? (I'm not sure
> exactly what wchar_t is, as it's apparently dependent on the locale at
> compile-time, and could be 8, 16, or 32 bits).

Under Windows, CWString uses the UTF-16 encoding.  On systems that define
__STDC_ISO_10646__ (e.g. glibc as used under Linux) it uses UTF-32.
(This is in the CVS version that will become 6.4, not the current release.)


More information about the Glasgow-haskell-users mailing list