Use wxWidgets conversions to/from UTF-8 in Scintilla code

Scintilla conversions use UTF-16, as indicated by their names, while wxString
uses UTF-32 under Unix, so they don't work correctly for the characters
outside of BMP.

Simply use our own UTF-8 conversions, it doesn't seem possible to get invalid
UTF-8 sequences here anyhow, so the comment saying that Scintilla functions
are used to avoid asserts doesn't seem to be relevant.

Closes #15621.
This commit is contained in:
ARATA Mizuki 2016-03-26 13:31:35 +09:00 committed by Vadim Zeitlin
parent 5e4aacd3b7
commit 01046f4790

View File

@ -1618,44 +1618,25 @@ double ElapsedTime::Duration(bool reset) {
#if wxUSE_UNICODE
#include "UniConversion.h"
// Convert using Scintilla's functions instead of wx's, Scintilla's are more
// forgiving and won't assert...
// For historical reasons, we use Scintilla-specific conversion functions, we
// should probably just call FromUTF8()/utf8_str() directly instead now.
wxString stc2wx(const char* str, size_t len)
{
if (!len)
return wxEmptyString;
size_t wclen = UTF16Length(str, len);
wxWCharBuffer buffer(wclen+1);
size_t actualLen = UTF16FromUTF8(str, len, buffer.data(), wclen+1);
return wxString(buffer.data(), actualLen);
return wxString::FromUTF8(str, len);
}
wxString stc2wx(const char* str)
{
return stc2wx(str, strlen(str));
return wxString::FromUTF8(str);
}
wxWX2MBbuf wx2stc(const wxString& str)
{
const wchar_t* wcstr = str.c_str();
size_t wclen = str.length();
size_t len = UTF8Length(wcstr, wclen);
// The buffer object adds extra byte for the terminating NUL and we must
// pass the total length, including this NUL, to UTF8FromUTF16() to ensure
// that it NULL-terminates the string.
wxCharBuffer buffer(len);
UTF8FromUTF16(wcstr, wclen, buffer.data(), len + 1);
return buffer;
return str.utf8_str();
}
#endif