virtual void OnExit()
{
#if wxUSE_WCHAR_T
- wxConvLocal.Clear();
+ wxConvLocal.Clear();
#endif
}
{
for (size_t i = 0; i < strlen( psz )+1; i++)
buf[i] = (wchar_t) psz[i];
- // printf( "libc %s\n", buf );
return strlen( psz );
}
else
{
for (size_t i = 0; i < wxStrlen( psz )+1; i++)
buf[i] = (char) psz[i];
- // printf( "libc %s\n", buf );
return wxStrlen( psz );
}
else
return wxWCharBuffer((wchar_t *) NULL);
}
-const wxCharBuffer wxMBConv::cWC2MB(const wchar_t *psz) const
+const wxCharBuffer wxMBConv::cWC2MB(const wchar_t *pwz) const
{
- if (psz)
- {
- size_t nLen = WC2MB((char *) NULL, psz, 0); // return value excludes /0
- if (nLen == (size_t)-1)
- return wxCharBuffer((char *) NULL);
- wxCharBuffer buf(nLen); // this allocates nLen+1
- WC2MB((char *)(const char *) buf, psz, nLen+1);
- // printf( "str %s\n", (const char*) buf );
- return buf;
- }
- else
- return wxCharBuffer((char *) NULL);
+ // return value excludes NUL
+ size_t nLen = pwz ? WC2MB((char *) NULL, pwz, 0) : (size_t)-1;
+ if (nLen == (size_t)-1)
+ return wxCharBuffer((const char *)NULL);
+
+ wxCharBuffer buf(nLen); // this allocates nLen+1
+ WC2MB((char *)(const char *) buf, pwz, nLen+1);
+ return buf;
}
// ----------------------------------------------------------------------------
WC_BSWAP(buf /* _not_ bufPtr */, res)
}
- // iconv doesn't seem to set the trailing 0
- buf[res] = 0;
+ // NB: iconv was given only strlen(psz) characters on input, and so
+ // it couldn't convert the trailing zero. Let's do it ourselves
+ // if there's some room left for it in the output buffer.
+ if (res < n)
+ buf[res] = 0;
}
else
{
res = n-outbuf;
- // iconv() doesn't set the trailing zero, but moves buf to
- // that position
- buf[0] = 0;
+ // NB: iconv was given only wcslen(psz) characters on input, and so
+ // it couldn't convert the trailing zero. Let's do it ourselves
+ // if there's some room left for it in the output buffer.
+ if (res < n)
+ buf[0] = 0;
}
else
{