Hi all, I'm trying to generate a typemap that will map perl internal strings (whether UTF8 or not) to wchar_t* strings.
Here is what I have: INUPT T_WCHAR if (SvUTF8($arg)) { STRLEN len; U8 *utf8_src = (U8 *) SvPV_nolen($arg); wchar_t* dst = (wchar_t*) $var; // Alloc memory for wide char string. This could be a bit more // then necessary. Newz(0, $var, 1 + SvLEN($arg), wchar_t); // Do actual UTF8 to wide char mapping while (*utf8_src) { *dst++ = utf8_to_uv(utf8_src, &len); utf8_src += len; } *dst++ = 0; } else { char* src = SvPV_nolen($arg); wchar_t* dst = (wchar_t*) $var; // Alloc memory for wide char string. Newz(0, $var, 1 + SvLEN($arg), wchar_t); // Do char to wide char mapping while (*src) *dst++ = (wchar_t) src; *dst++ = 0; } SAVEFREEPV($var); OUTPUT T_WCHAR { I32 byte_len = strlen((char*) $var); I32 new_byte_len; U8* utf8_tmp; U8* utf8_end; Newz(0, utf8_tmp, 1 + (3 * byte_len / 2), char); utf16_to_utf8($var, utf8_tmp, byte_len, &new_byte_len); utf8_end = utf8_tmp + new_byte_len; *utf8_end = 0; sv_setpv((SV*)$arg, utf8_tmp); sv_utf8_decode($arg); Safefree(utf8_tmp); } My first problem with this is, the compiler doesn't find utf8_to_uv. What do I need to do ? Also does this code seem ok to a perl XS expert ? Is there any better or more effecient way to do this ? Many thanks in advance. Thomas.