- const wxChar* szEnd = (*this).c_str() + length() + 1;
- const wxChar* szPos = (*this).c_str();
- const wxChar* szStart = szPos;
-
- wxWCharBuffer buffer(length() + 1);
-
- //Convert the string until the length() is reached, continuing the
- //loop every time a null character is reached
- while(szPos != szEnd)
- {
- size_t nLen = conv.MB2WC(NULL, szPos, 0);
-
- wxASSERT(nLen != (size_t)-1); //should not be true! If it is system mbtowc could be bad
-
- if ( conv.MB2WC(&buffer.data()[szPos - szStart], szPos, nLen + 1) == (size_t)-1 )
- {
- //error - return empty buffer
- wxFAIL_MSG(wxT("Error converting multi-byte string to a wide-character string"));
- buffer.data()[0] = '\0';
- return buffer;
- }
-
- szPos += nLen + 1;
- }
-
- return buffer;