+#ifdef WC_UTF16
+ typedef wchar_t wxDecodeSurrogate_t;
+#else // !WC_UTF16
+ typedef wxUint16 wxDecodeSurrogate_t;
+#endif // WC_UTF16/!WC_UTF16
+
+// returns the next UTF-32 character from the wchar_t buffer and advances the
+// pointer to the character after this one
+//
+// if an invalid character is found, *pSrc is set to NULL, the caller must
+// check for this
+static wxUint32 wxDecodeSurrogate(const wxDecodeSurrogate_t **pSrc)
+{
+ wxUint32 out;
+ const size_t
+ n = decode_utf16(wx_reinterpret_cast(const wxUint16 *, *pSrc), out);
+ if ( n == wxCONV_FAILED )
+ *pSrc = NULL;
+ else
+ *pSrc += n;
+
+ return out;
+}
+
+// ----------------------------------------------------------------------------
+// wxMBConv
+// ----------------------------------------------------------------------------
+
+size_t
+wxMBConv::ToWChar(wchar_t *dst, size_t dstLen,
+ const char *src, size_t srcLen) const
+{
+ // although new conversion classes are supposed to implement this function
+ // directly, the existins ones only implement the old MB2WC() and so, to
+ // avoid to have to rewrite all conversion classes at once, we provide a
+ // default (but not efficient) implementation of this one in terms of the
+ // old function by copying the input to ensure that it's NUL-terminated and
+ // then using MB2WC() to convert it
+
+ // the number of chars [which would be] written to dst [if it were not NULL]
+ size_t dstWritten = 0;
+
+ // the number of NULs terminating this string
+ size_t nulLen = 0; // not really needed, but just to avoid warnings
+
+ // if we were not given the input size we just have to assume that the
+ // string is properly terminated as we have no way of knowing how long it
+ // is anyhow, but if we do have the size check whether there are enough
+ // NULs at the end
+ wxCharBuffer bufTmp;
+ const char *srcEnd;
+ if ( srcLen != wxNO_LEN )
+ {
+ // we need to know how to find the end of this string
+ nulLen = GetMBNulLen();
+ if ( nulLen == wxCONV_FAILED )
+ return wxCONV_FAILED;
+
+ // if there are enough NULs we can avoid the copy
+ if ( srcLen < nulLen || NotAllNULs(src + srcLen - nulLen, nulLen) )
+ {
+ // make a copy in order to properly NUL-terminate the string
+ bufTmp = wxCharBuffer(srcLen + nulLen - 1 /* 1 will be added */);
+ char * const p = bufTmp.data();
+ memcpy(p, src, srcLen);
+ for ( char *s = p + srcLen; s < p + srcLen + nulLen; s++ )
+ *s = '\0';
+
+ src = bufTmp;
+ }
+
+ srcEnd = src + srcLen;
+ }
+ else // quit after the first loop iteration
+ {
+ srcEnd = NULL;
+ }
+
+ for ( ;; )
+ {
+ // try to convert the current chunk
+ size_t lenChunk = MB2WC(NULL, src, 0);
+ if ( lenChunk == wxCONV_FAILED )
+ return wxCONV_FAILED;
+
+ lenChunk++; // for the L'\0' at the end of this chunk
+
+ dstWritten += lenChunk;
+
+ if ( lenChunk == 1 )
+ {
+ // nothing left in the input string, conversion succeeded
+ break;
+ }
+
+ if ( dst )
+ {
+ if ( dstWritten > dstLen )
+ return wxCONV_FAILED;
+
+ if ( MB2WC(dst, src, lenChunk) == wxCONV_FAILED )
+ return wxCONV_FAILED;
+
+ dst += lenChunk;
+ }
+
+ if ( !srcEnd )
+ {
+ // we convert just one chunk in this case as this is the entire
+ // string anyhow
+ break;
+ }
+
+ // advance the input pointer past the end of this chunk
+ while ( NotAllNULs(src, nulLen) )
+ {
+ // notice that we must skip over multiple bytes here as we suppose
+ // that if NUL takes 2 or 4 bytes, then all the other characters do
+ // too and so if advanced by a single byte we might erroneously
+ // detect sequences of NUL bytes in the middle of the input
+ src += nulLen;
+ }
+
+ src += nulLen; // skipping over its terminator as well
+
+ // note that ">=" (and not just "==") is needed here as the terminator
+ // we skipped just above could be inside or just after the buffer
+ // delimited by inEnd
+ if ( src >= srcEnd )
+ break;
+ }
+
+ return dstWritten;
+}
+
+size_t
+wxMBConv::FromWChar(char *dst, size_t dstLen,
+ const wchar_t *src, size_t srcLen) const
+{
+ // the number of chars [which would be] written to dst [if it were not NULL]
+ size_t dstWritten = 0;
+
+ // make a copy of the input string unless it is already properly
+ // NUL-terminated
+ //
+ // if we don't know its length we have no choice but to assume that it is,
+ // indeed, properly terminated
+ wxWCharBuffer bufTmp;
+ if ( srcLen == wxNO_LEN )
+ {
+ srcLen = wxWcslen(src) + 1;
+ }
+ else if ( srcLen != 0 && src[srcLen - 1] != L'\0' )
+ {
+ // make a copy in order to properly NUL-terminate the string
+ bufTmp = wxWCharBuffer(srcLen);
+ memcpy(bufTmp.data(), src, srcLen * sizeof(wchar_t));
+ src = bufTmp;
+ }
+
+ const size_t lenNul = GetMBNulLen();
+ for ( const wchar_t * const srcEnd = src + srcLen;
+ src < srcEnd;
+ src += wxWcslen(src) + 1 /* skip L'\0' too */ )
+ {
+ // try to convert the current chunk
+ size_t lenChunk = WC2MB(NULL, src, 0);
+
+ if ( lenChunk == wxCONV_FAILED )
+ return wxCONV_FAILED;
+
+ lenChunk += lenNul;
+ dstWritten += lenChunk;
+
+ if ( dst )
+ {
+ if ( dstWritten > dstLen )
+ return wxCONV_FAILED;
+
+ if ( WC2MB(dst, src, lenChunk) == wxCONV_FAILED )
+ return wxCONV_FAILED;
+
+ dst += lenChunk;
+ }
+ }
+
+ return dstWritten;
+}
+
+size_t wxMBConv::MB2WC(wchar_t *outBuff, const char *inBuff, size_t outLen) const
+{
+ size_t rc = ToWChar(outBuff, outLen, inBuff);
+ if ( rc != wxCONV_FAILED )
+ {
+ // ToWChar() returns the buffer length, i.e. including the trailing
+ // NUL, while this method doesn't take it into account
+ rc--;
+ }
+
+ return rc;
+}
+
+size_t wxMBConv::WC2MB(char *outBuff, const wchar_t *inBuff, size_t outLen) const
+{
+ size_t rc = FromWChar(outBuff, outLen, inBuff);
+ if ( rc != wxCONV_FAILED )
+ {
+ rc -= GetMBNulLen();
+ }
+
+ return rc;
+}
+
+wxMBConv::~wxMBConv()
+{
+ // nothing to do here (necessary for Darwin linking probably)
+}
+
+const wxWCharBuffer wxMBConv::cMB2WC(const char *psz) const
+{
+ if ( psz )
+ {
+ // calculate the length of the buffer needed first
+ const size_t nLen = ToWChar(NULL, 0, psz);
+ if ( nLen != wxCONV_FAILED )
+ {
+ // now do the actual conversion
+ wxWCharBuffer buf(nLen - 1 /* +1 added implicitly */);
+
+ // +1 for the trailing NULL
+ if ( ToWChar(buf.data(), nLen, psz) != wxCONV_FAILED )
+ return buf;
+ }
+ }
+
+ return wxWCharBuffer();
+}
+
+const wxCharBuffer wxMBConv::cWC2MB(const wchar_t *pwz) const
+{
+ if ( pwz )
+ {
+ const size_t nLen = FromWChar(NULL, 0, pwz);
+ if ( nLen != wxCONV_FAILED )
+ {
+ wxCharBuffer buf(nLen - 1);
+ if ( FromWChar(buf.data(), nLen, pwz) != wxCONV_FAILED )
+ return buf;
+ }
+ }
+
+ return wxCharBuffer();
+}
+
+const wxWCharBuffer
+wxMBConv::cMB2WC(const char *inBuff, size_t inLen, size_t *outLen) const
+{
+ const size_t dstLen = ToWChar(NULL, 0, inBuff, inLen);
+ if ( dstLen != wxCONV_FAILED )
+ {
+ // notice that we allocate space for dstLen+1 wide characters here
+ // because we want the buffer to always be NUL-terminated, even if the
+ // input isn't (as otherwise the caller has no way to know its length)
+ wxWCharBuffer wbuf(dstLen);
+ wbuf.data()[dstLen - 1] = L'\0';
+ if ( ToWChar(wbuf.data(), dstLen, inBuff, inLen) != wxCONV_FAILED )
+ {
+ if ( outLen )
+ {
+ *outLen = dstLen;
+ if ( wbuf[dstLen - 1] == L'\0' )
+ (*outLen)--;
+ }
+
+ return wbuf;
+ }
+ }
+
+ if ( outLen )
+ *outLen = 0;
+
+ return wxWCharBuffer();
+}
+
+const wxCharBuffer
+wxMBConv::cWC2MB(const wchar_t *inBuff, size_t inLen, size_t *outLen) const
+{
+ size_t dstLen = FromWChar(NULL, 0, inBuff, inLen);
+ if ( dstLen != wxCONV_FAILED )
+ {
+ const size_t nulLen = GetMBNulLen();
+
+ // as above, ensure that the buffer is always NUL-terminated, even if
+ // the input is not
+ wxCharBuffer buf(dstLen + nulLen - 1);
+ memset(buf.data() + dstLen, 0, nulLen);
+ if ( FromWChar(buf.data(), dstLen, inBuff, inLen) != wxCONV_FAILED )
+ {
+ if ( outLen )
+ {
+ *outLen = dstLen;
+
+ if ( dstLen >= nulLen &&
+ !NotAllNULs(buf.data() + dstLen - nulLen, nulLen) )
+ {
+ // in this case the output is NUL-terminated and we're not
+ // supposed to count NUL
+ *outLen -= nulLen;
+ }
+ }
+
+ return buf;
+ }
+ }
+
+ if ( outLen )
+ *outLen = 0;
+
+ return wxCharBuffer();
+}
+
+// ----------------------------------------------------------------------------
+// wxMBConvLibc
+// ----------------------------------------------------------------------------
+
+size_t wxMBConvLibc::MB2WC(wchar_t *buf, const char *psz, size_t n) const
+{
+ return wxMB2WC(buf, psz, n);
+}
+
+size_t wxMBConvLibc::WC2MB(char *buf, const wchar_t *psz, size_t n) const
+{
+ return wxWC2MB(buf, psz, n);
+}
+
+// ----------------------------------------------------------------------------
+// wxConvBrokenFileNames
+// ----------------------------------------------------------------------------
+
+#ifdef __UNIX__
+
+wxConvBrokenFileNames::wxConvBrokenFileNames(const wxString& charset)
+{
+ if ( wxStricmp(charset, _T("UTF-8")) == 0 ||
+ wxStricmp(charset, _T("UTF8")) == 0 )
+ m_conv = new wxMBConvUTF8(wxMBConvUTF8::MAP_INVALID_UTF8_TO_PUA);
+ else
+ m_conv = new wxCSConv(charset);
+}
+
+#endif // __UNIX__
+
+// ----------------------------------------------------------------------------
+// UTF-7
+// ----------------------------------------------------------------------------
+
+// Implementation (C) 2004 Fredrik Roubert
+//
+// Changes to work in streaming mode (C) 2008 Vadim Zeitlin
+
+//
+// BASE64 decoding table
+//
+static const unsigned char utf7unb64[] =
+{
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0x3e, 0xff, 0xff, 0xff, 0x3f,
+ 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b,
+ 0x3c, 0x3d, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
+ 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
+ 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16,
+ 0x17, 0x18, 0x19, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20,
+ 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28,
+ 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30,
+ 0x31, 0x32, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
+};
+
+size_t wxMBConvUTF7::ToWChar(wchar_t *dst, size_t dstLen,
+ const char *src, size_t srcLen) const
+{
+ DecoderState stateOrig,
+ *statePtr;
+ if ( srcLen == wxNO_LEN )
+ {
+ // convert the entire string, up to and including the trailing NUL
+ srcLen = strlen(src) + 1;
+
+ // when working on the entire strings we don't update nor use the shift
+ // state from the previous call
+ statePtr = &stateOrig;
+ }
+ else // when working with partial strings we do use the shift state
+ {
+ statePtr = wx_const_cast(DecoderState *, &m_stateDecoder);
+
+ // also save the old state to be able to rollback to it on error
+ stateOrig = m_stateDecoder;
+ }
+
+ // but to simplify the code below we use this variable in both cases
+ DecoderState& state = *statePtr;
+
+
+ // number of characters [which would have been] written to dst [if it were
+ // not NULL]
+ size_t len = 0;
+
+ const char * const srcEnd = src + srcLen;
+
+ while ( (src < srcEnd) && (!dst || (len < dstLen)) )
+ {
+ const unsigned char cc = *src++;
+
+ if ( state.IsShifted() )
+ {
+ const unsigned char dc = utf7unb64[cc];
+ if ( dc == 0xff )
+ {
+ // end of encoded part
+ state.ToDirect();
+
+ // re-parse this character normally below unless it's '-' which
+ // is consumed by the decoder
+ if ( cc == '-' )
+ continue;
+ }
+ else // valid encoded character
+ {
+ // mini base64 decoder: each character is 6 bits
+ state.bit += 6;
+ state.accum <<= 6;
+ state.accum += dc;
+
+ if ( state.bit >= 8 )
+ {
+ // got the full byte, consume it
+ state.bit -= 8;
+ unsigned char b = (state.accum >> state.bit) & 0x00ff;
+
+ if ( state.isLSB )
+ {
+ // we've got the full word, output it
+ if ( dst )
+ *dst++ = (state.msb << 8) | b;
+ len++;
+ state.isLSB = false;
+ }
+ else // MSB
+ {
+ // just store it while we wait for LSB
+ state.msb = b;
+ state.isLSB = true;
+ }
+ }
+ }
+ }
+
+ if ( state.IsDirect() )
+ {
+ // start of an encoded segment?
+ if ( cc == '+' )
+ {
+ if ( src == srcEnd )
+ return wxCONV_FAILED; // can't have '+' at the end
+
+ if ( *src == '-' )
+ {
+ // just the encoded plus sign, don't switch to shifted mode
+ if ( dst )
+ *dst++ = '+';
+ len++;
+ src++;
+ }
+ else
+ {
+ state.ToShifted();
+ }
+ }
+ else // not '+'
+ {
+ // only printable 7 bit ASCII characters (with the exception of
+ // NUL, TAB, CR and LF) can be used directly
+ if ( cc >= 0x7f || (cc < ' ' &&
+ !(cc == '\0' || cc == '\t' || cc == '\r' || cc == '\n')) )
+ return wxCONV_FAILED;
+
+ if ( dst )
+ *dst++ = cc;
+ len++;
+ }
+ }
+ }
+
+ if ( !len )
+ {
+ // as we didn't read any characters we should be called with the same
+ // data (followed by some more new data) again later so don't save our
+ // state
+ state = stateOrig;
+
+ return wxCONV_FAILED;
+ }
+
+ return len;
+}
+
+//
+// BASE64 encoding table
+//
+static const unsigned char utf7enb64[] =
+{
+ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
+ 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
+ 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
+ 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
+ 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
+ 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
+ 'w', 'x', 'y', 'z', '0', '1', '2', '3',
+ '4', '5', '6', '7', '8', '9', '+', '/'
+};
+
+//
+// UTF-7 encoding table
+//
+// 0 - Set D (directly encoded characters)
+// 1 - Set O (optional direct characters)
+// 2 - whitespace characters (optional)
+// 3 - special characters
+//
+static const unsigned char utf7encode[128] =
+{
+ 0, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 3, 3, 2, 3, 3,
+ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
+ 2, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 3, 0, 0, 0, 3,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0,
+ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 1, 1, 1,
+ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 3, 3
+};
+
+static inline bool wxIsUTF7Direct(wchar_t wc)
+{
+ return wc < 0x80 && utf7encode[wc] < 1;
+}
+
+size_t wxMBConvUTF7::FromWChar(char *dst, size_t dstLen,
+ const wchar_t *src, size_t srcLen) const
+{
+ EncoderState stateOrig,
+ *statePtr;
+ if ( srcLen == wxNO_LEN )
+ {
+ // we don't apply the stored state when operating on entire strings at
+ // once
+ statePtr = &stateOrig;
+
+ srcLen = wxWcslen(src) + 1;
+ }
+ else // do use the mode we left the output in previously
+ {
+ stateOrig = m_stateEncoder;
+ statePtr = wx_const_cast(EncoderState *, &m_stateEncoder);
+ }
+
+ EncoderState& state = *statePtr;
+
+
+ size_t len = 0;
+
+ const wchar_t * const srcEnd = src + srcLen;
+ while ( src < srcEnd && (!dst || len < dstLen) )
+ {
+ wchar_t cc = *src++;
+ if ( wxIsUTF7Direct(cc) )
+ {
+ if ( state.IsShifted() )
+ {
+ // pad with zeros the last encoded block if necessary
+ if ( state.bit )
+ {
+ if ( dst )
+ *dst++ = utf7enb64[((state.accum % 16) << (6 - state.bit)) % 64];
+ len++;
+ }
+
+ state.ToDirect();
+
+ if ( dst )
+ *dst++ = '-';
+ len++;
+ }
+
+ if ( dst )
+ *dst++ = (char)cc;
+ len++;
+ }
+ else if ( cc == '+' && state.IsDirect() )
+ {
+ if ( dst )
+ {
+ *dst++ = '+';
+ *dst++ = '-';
+ }
+
+ len += 2;
+ }
+#ifndef WC_UTF16
+ else if (((wxUint32)cc) > 0xffff)
+ {
+ // no surrogate pair generation (yet?)
+ return wxCONV_FAILED;
+ }
+#endif
+ else
+ {
+ if ( state.IsDirect() )
+ {
+ state.ToShifted();
+
+ if ( dst )
+ *dst++ = '+';
+ len++;
+ }
+
+ // BASE64 encode string
+ for ( ;; )
+ {
+ for ( unsigned lsb = 0; lsb < 2; lsb++ )
+ {
+ state.accum <<= 8;
+ state.accum += lsb ? cc & 0xff : (cc & 0xff00) >> 8;
+
+ for (state.bit += 8; state.bit >= 6; )
+ {
+ state.bit -= 6;
+ if ( dst )
+ *dst++ = utf7enb64[(state.accum >> state.bit) % 64];
+ len++;
+ }
+ }
+
+ if ( src == srcEnd || wxIsUTF7Direct(cc = *src) )
+ break;
+
+ src++;
+ }
+ }
+ }
+
+ // we need to restore the original encoder state if we were called just to
+ // calculate the amount of space needed as we will presumably be called
+ // again to really convert the data now
+ if ( !dst )
+ state = stateOrig;
+
+ return len;
+}
+
+// ----------------------------------------------------------------------------
+// UTF-8
+// ----------------------------------------------------------------------------
+
+static const wxUint32 utf8_max[]=
+ { 0x7f, 0x7ff, 0xffff, 0x1fffff, 0x3ffffff, 0x7fffffff, 0xffffffff };
+
+// boundaries of the private use area we use to (temporarily) remap invalid
+// characters invalid in a UTF-8 encoded string
+const wxUint32 wxUnicodePUA = 0x100000;
+const wxUint32 wxUnicodePUAEnd = wxUnicodePUA + 256;
+
+// this table gives the length of the UTF-8 encoding from its first character:
+const unsigned char tableUtf8Lengths[256] = {
+ // single-byte sequences (ASCII):
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 00..0F
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 10..1F
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 20..2F
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 30..3F
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 40..4F
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 50..5F
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 60..6F
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 70..7F
+
+ // these are invalid:
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 80..8F
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 90..9F
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // A0..AF
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // B0..BF
+ 0, 0, // C0,C1
+
+ // two-byte sequences:
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // C2..CF
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // D0..DF
+
+ // three-byte sequences:
+ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, // E0..EF
+
+ // four-byte sequences:
+ 4, 4, 4, 4, 4, // F0..F4
+
+ // these are invalid again (5- or 6-byte
+ // sequences and sequences for code points
+ // above U+10FFFF, as restricted by RFC 3629):
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // F5..FF
+};
+
+size_t
+wxMBConvStrictUTF8::ToWChar(wchar_t *dst, size_t dstLen,
+ const char *src, size_t srcLen) const
+{
+ wchar_t *out = dstLen ? dst : NULL;
+ size_t written = 0;
+
+ if ( srcLen == wxNO_LEN )
+ srcLen = strlen(src) + 1;
+
+ for ( const char *p = src; ; p++ )
+ {
+ if ( !(srcLen == wxNO_LEN ? *p : srcLen) )
+ {
+ // all done successfully, just add the trailing NULL if we are not
+ // using explicit length
+ if ( srcLen == wxNO_LEN )
+ {
+ if ( out )
+ {
+ if ( !dstLen )
+ break;
+
+ *out = L'\0';
+ }
+
+ written++;
+ }
+
+ return written;
+ }
+
+ if ( out && !dstLen-- )
+ break;