+// copy 32bit String to 16bit MB
+size_t wxMBConvUTF16straight::WC2MB(char *buf, const wchar_t *psz, size_t n) const
+{
+ size_t len=0;
+
+ while (*psz && (!buf || len < n))
+ {
+ wxUint16 cc[2];
+ size_t pa=encode_utf16(*psz, cc);
+
+ if (pa == (size_t)-1)
+ return pa;
+
+ if (buf)
+ {
+ *(wxUint16*)buf = cc[0];
+ buf += sizeof(wxUint16);
+ if (pa > 1)
+ {
+ *(wxUint16*)buf = cc[1];
+ buf += sizeof(wxUint16);
+ }
+ }
+
+ len += pa*sizeof(wxUint16);
+ psz++;
+ }
+ if (buf && len<=n-sizeof(wxUint16)) *(wxUint16*)buf=0;
+
+ return len;
+}
+
+
+// swap 16bit MB to 32bit String
+size_t wxMBConvUTF16swap::MB2WC(wchar_t *buf, const char *psz, size_t n) const
+{
+ size_t len=0;
+
+ while (*(wxUint16*)psz && (!buf || len < n))
+ {
+ wxUint32 cc;
+ char tmp[4];
+ tmp[0]=psz[1]; tmp[1]=psz[0];
+ tmp[2]=psz[3]; tmp[3]=psz[2];
+
+ size_t pa=decode_utf16((wxUint16*)tmp, cc);
+ if (pa == (size_t)-1)
+ return pa;
+
+ if (buf)
+ *buf++ = cc;
+
+ len++;
+ psz += pa * sizeof(wxUint16);
+ }
+ if (buf && len<n) *buf=0;
+
+ return len;
+}
+
+
+// swap 32bit String to 16bit MB
+size_t wxMBConvUTF16swap::WC2MB(char *buf, const wchar_t *psz, size_t n) const
+{
+ size_t len=0;
+
+ while (*psz && (!buf || len < n))
+ {
+ wxUint16 cc[2];
+ size_t pa=encode_utf16(*psz, cc);
+
+ if (pa == (size_t)-1)
+ return pa;
+
+ if (buf)
+ {
+ *buf++ = ((char*)cc)[1];
+ *buf++ = ((char*)cc)[0];
+ if (pa > 1)
+ {
+ *buf++ = ((char*)cc)[3];
+ *buf++ = ((char*)cc)[2];
+ }
+ }
+
+ len += pa*sizeof(wxUint16);
+ psz++;
+ }
+ if (buf && len<=n-sizeof(wxUint16)) *(wxUint16*)buf=0;
+
+ return len;
+}
+
+#endif // WC_UTF16
+
+
+// ----------------------------------------------------------------------------
+// UTF-32
+// ----------------------------------------------------------------------------
+
+#ifdef WORDS_BIGENDIAN
+#define wxMBConvUTF32straight wxMBConvUTF32BE
+#define wxMBConvUTF32swap wxMBConvUTF32LE
+#else
+#define wxMBConvUTF32swap wxMBConvUTF32BE
+#define wxMBConvUTF32straight wxMBConvUTF32LE
+#endif
+
+
+WXDLLIMPEXP_DATA_BASE(wxMBConvUTF32LE) wxConvUTF32LE;
+WXDLLIMPEXP_DATA_BASE(wxMBConvUTF32BE) wxConvUTF32BE;
+
+
+#ifdef WC_UTF16
+
+// copy 32bit MB to 16bit String
+size_t wxMBConvUTF32straight::MB2WC(wchar_t *buf, const char *psz, size_t n) const
+{
+ size_t len=0;
+
+ while (*(wxUint32*)psz && (!buf || len < n))
+ {
+ wxUint16 cc[2];
+
+ size_t pa=encode_utf16(*(wxUint32*)psz, cc);
+ if (pa == (size_t)-1)
+ return pa;
+
+ if (buf)
+ {
+ *buf++ = cc[0];
+ if (pa > 1)
+ *buf++ = cc[1];
+ }
+ len += pa;
+ psz += sizeof(wxUint32);
+ }
+ if (buf && len<n) *buf=0;
+
+ return len;
+}
+
+
+// copy 16bit String to 32bit MB
+size_t wxMBConvUTF32straight::WC2MB(char *buf, const wchar_t *psz, size_t n) const
+{
+ size_t len=0;
+
+ while (*psz && (!buf || len < n))
+ {
+ wxUint32 cc;
+
+ // cast is ok for WC_UTF16
+ size_t pa = decode_utf16((const wxUint16 *)psz, cc);
+ if (pa == (size_t)-1)
+ return pa;
+
+ if (buf)
+ {
+ *(wxUint32*)buf = cc;
+ buf += sizeof(wxUint32);
+ }
+ len += sizeof(wxUint32);
+ psz += pa;
+ }
+
+ if (buf && len<=n-sizeof(wxUint32))
+ *(wxUint32*)buf=0;
+
+ return len;
+}
+
+
+
+// swap 32bit MB to 16bit String
+size_t wxMBConvUTF32swap::MB2WC(wchar_t *buf, const char *psz, size_t n) const
+{
+ size_t len=0;
+
+ while (*(wxUint32*)psz && (!buf || len < n))
+ {
+ char tmp[4];
+ tmp[0] = psz[3]; tmp[1] = psz[2];
+ tmp[2] = psz[1]; tmp[3] = psz[0];
+
+
+ wxUint16 cc[2];
+
+ size_t pa=encode_utf16(*(wxUint32*)tmp, cc);
+ if (pa == (size_t)-1)
+ return pa;
+
+ if (buf)
+ {
+ *buf++ = cc[0];
+ if (pa > 1)
+ *buf++ = cc[1];
+ }
+ len += pa;
+ psz += sizeof(wxUint32);
+ }
+
+ if (buf && len<n)
+ *buf=0;
+
+ return len;
+}
+
+
+// swap 16bit String to 32bit MB
+size_t wxMBConvUTF32swap::WC2MB(char *buf, const wchar_t *psz, size_t n) const
+{
+ size_t len=0;
+
+ while (*psz && (!buf || len < n))
+ {
+ char cc[4];
+
+ // cast is ok for WC_UTF16
+ size_t pa=decode_utf16((const wxUint16 *)psz, *(wxUint32*)cc);
+ if (pa == (size_t)-1)
+ return pa;
+
+ if (buf)
+ {
+ *buf++ = cc[3];
+ *buf++ = cc[2];
+ *buf++ = cc[1];
+ *buf++ = cc[0];
+ }
+ len += sizeof(wxUint32);
+ psz += pa;
+ }
+
+ if (buf && len<=n-sizeof(wxUint32))
+ *(wxUint32*)buf=0;
+
+ return len;
+}
+
+#else // WC_UTF16
+
+
+// copy 32bit MB to 32bit String
+size_t wxMBConvUTF32straight::MB2WC(wchar_t *buf, const char *psz, size_t n) const
+{
+ size_t len=0;
+
+ while (*(wxUint32*)psz && (!buf || len < n))
+ {
+ if (buf)
+ *buf++ = *(wxUint32*)psz;
+ len++;
+ psz += sizeof(wxUint32);
+ }
+
+ if (buf && len<n)
+ *buf=0;
+
+ return len;
+}
+
+
+// copy 32bit String to 32bit MB
+size_t wxMBConvUTF32straight::WC2MB(char *buf, const wchar_t *psz, size_t n) const
+{
+ size_t len=0;
+
+ while (*psz && (!buf || len < n))
+ {
+ if (buf)
+ {
+ *(wxUint32*)buf = *psz;
+ buf += sizeof(wxUint32);
+ }