I'm wrapping a method that returns UTF-16 strings.
My understanding is that these should be converted
to UTF-8 before returning them, but I'm not sure
how that should be done. I don't really have much
of an understanding of Unicode, nor really of XS.

If it helps, what I have so far is (this is a method
for Mozilla's nsIDOMEvent GetType method, and PRUnichar
is a 16-bit character):

## GetType(nsAString & aType)
const char *
moz_dom_get_type (event)
        nsIDOMEvent *event;
    PREINIT:
        nsEmbedString u16container;    /* nsEmbedString implements nsAString */
        const PRUnichar *u16str;
        const char *u8str;
    CODE:
        event->GetType(u16container);  /* pass by reference */
        u16str = u16container.get();

        /* convert from utf-16 to utf-8 */
        u8str = ...?

        RETVAL = u8str;
    OUTPUT:
        RETVAL

I think that Encode can be used to go from UTF-16 to UTF-8,
but I don't see any typemap that handles UTF-16. (I'm not sure
if that statement makes sense.)

Reply via email to