- //*2 is the worst case - probably for UTF8
- wxCharBuffer buffer((nLen << 1) + 1);
-
- //do the actual conversion (if it fails we get an empty string)
- size_t nActualLength = wxMbstr(buffer, pwz, nLen, conv);
-
- if ( !Alloc(nActualLength + 1) )
- {
- wxFAIL_MSG(wxT("Out of memory in wxString"));
- }
- else
- {
- //copy the data
- assign(buffer.data(), nActualLength);
- }
+ //Create a wxStringBufferLength which will access the internal
+ //C char pointer in non-stl mode
+ wxStringBufferLength internalBuffer(*this, wxString::WorstEncodingCase(nLen, conv) + 1);
+
+ //Do the actual conversion & Set the length of the buffer
+ internalBuffer.SetLength(
+ wxMbstr(internalBuffer, pwz, nLen, conv)
+ );