From 01046f4790c15f0a7ef1d352eddfa95c5ccf4451 Mon Sep 17 00:00:00 2001 From: ARATA Mizuki Date: Sat, 26 Mar 2016 13:31:35 +0900 Subject: [PATCH] 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. --- src/stc/PlatWX.cpp | 29 +++++------------------------ 1 file changed, 5 insertions(+), 24 deletions(-) diff --git a/src/stc/PlatWX.cpp b/src/stc/PlatWX.cpp index 8c2576999e..79e6e16af8 100644 --- a/src/stc/PlatWX.cpp +++ b/src/stc/PlatWX.cpp @@ -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