From 9bad4be21482d36bff76357a000e008755b60361 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 19 May 2022 10:17:32 -0700 Subject: QStringConverter: use the QUtf8 codec when Windows is using UTF-8 The QLocal8Bit implementation assumes that there's at most one continuation byte -- that is, that all codecs are either Single or Double Byte Character Sets (SBCS or DBCS). It appears to be the case for all Windows default codepages, except for CP_UTF8, which is an opt-in anyway. Instead of fixing our codec, let's just use the optimized UTF-8 implementation. [ChangeLog][Windows] Fixed support for using Qt applications with UTF-8 as the system codepage or by enabling that in the application's manifest. Discussed-on: https://lists.qt-project.org/pipermail/interest/2022-May/038241.html Pick-to: 6.2 6.3 Change-Id: I77c8221eb2824c369feffffd16f0912550a98049 Reviewed-by: Lars Knoll --- src/corelib/text/qstringconverter.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/corelib/text/qstringconverter.cpp') diff --git a/src/corelib/text/qstringconverter.cpp b/src/corelib/text/qstringconverter.cpp index 201b1f3f24..d252d7b667 100644 --- a/src/corelib/text/qstringconverter.cpp +++ b/src/corelib/text/qstringconverter.cpp @@ -1173,6 +1173,11 @@ QChar *QUtf32::convertToUnicode(QChar *out, QByteArrayView in, QStringConverter: } #if defined(Q_OS_WIN) && !defined(QT_BOOTSTRAPPED) +int QLocal8Bit::checkUtf8() +{ + return GetACP() == CP_UTF8 ? 1 : -1; +} + static QString convertToUnicodeCharByChar(QByteArrayView in, QStringConverter::State *state) { qsizetype length = in.size(); @@ -1226,7 +1231,7 @@ static QString convertToUnicodeCharByChar(QByteArrayView in, QStringConverter::S } -QString QLocal8Bit::convertToUnicode(QByteArrayView in, QStringConverter::State *state) +QString QLocal8Bit::convertToUnicode_sys(QByteArrayView in, QStringConverter::State *state) { qsizetype length = in.size(); @@ -1314,7 +1319,7 @@ QString QLocal8Bit::convertToUnicode(QByteArrayView in, QStringConverter::State return s; } -QByteArray QLocal8Bit::convertFromUnicode(QStringView in, QStringConverter::State *state) +QByteArray QLocal8Bit::convertFromUnicode_sys(QStringView in, QStringConverter::State *state) { const QChar *ch = in.data(); qsizetype uclen = in.size(); -- cgit v1.2.3