[Haskell-cafe] Quickest way to pass Text to C code

Yves Parès yves.pares at gmail.com
Wed Mar 21 09:35:48 CET 2012


Hello,

I have to interact with a C++ library that accepts as string types (putting
c++ strings aside) pointers of wchar_t (CWString in Haskell) or unsigned
32-bit int (Ptr Word32 for UTF-32 codepoints).

I have read what text, bytestring and base provide, but Text can only be
directly converted to (Ptr Word16), and if I use encodeUTF32 to get a
ByteString, then I only get useAsCString, no direct conversion to CWString
or Ptr WordXX is possible.
Not to mention the extra memory allocations due to intermediate conversions.

base provides Foreign.C.String.useAsCWString, but it requires that either I
use simple Strings at the first place or (same thing than before) I convert
from Text to String before passing to C.

Is there something I'm missing or isn't this kind of conversion that easy?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20120321/39be653f/attachment.htm>


More information about the Haskell-Cafe mailing list