Hi,

for those who are interested, this typemap for wchar_t
seems to work.

Thomas.

============================================================

INPUT
T_WCHAR
        {
          // Alloc memory for wide char string.  This could be a bit more
          // then necessary.
          Newz(0, $var, SvLEN($arg), wchar_t);

          char* src = SvPV_nolen($arg);
          wchar_t* dst = (wchar_t*) $var;

          if (SvUTF8($arg)) {
            // UTF8 to wide char mapping
            STRLEN len;
            while (*src) {
              *dst++ = utf8_to_uvuni((U8*) src, &len);
              src += len;
            }
          } else {
            // char to wide char mapping
            while (*src) {
              *dst++ = (wchar_t) *src++;
            }
          }
          *dst = 0;
          SAVEFREEPV($var);
        }

OUTPUT
T_WCHAR
        {
          wchar_t* src = (wchar_t*) $var;
          U8* dst;
          U8* d;

          // Alloc memory for wide char string.  This is clearly wider
          // then necessary in most cases but no choice.
          Newz(0, dst, 3 * wcslen(src), U8);

          d = dst;
          while (*src) {
            d = uvuni_to_utf8(d, *src++);
          }
          *d = 0;

          sv_setpv((SV*)$arg, (char*) dst);
          sv_utf8_decode($arg);

          Safefree(dst);
        }


Reply via email to