From e542a2f9e55a046101ca1ed61803497194fbe89e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Fri, 20 Oct 2023 14:05:52 +0200 Subject: [PATCH] QLocal8Bit::convertToUnicode[win]: Drop MB_PRECOMPOSED flag A few code pages do not support this flag[0]. It's also deprecated[1] and is what Windows prefers to generate by default. So let's drop it. [0] https://learn.microsoft.com/en-us/windows/win32/api/stringapiset/nf-stringapiset-multibytetowidechar See note at the end for the dwFlags parameter. [1] It's mentioned in the header files, but not online... Pick-to: 6.5 Task-number: QTBUG-118185 Task-number: QTBUG-105105 Change-Id: I798c387170c73a953be874de139868543b2d775e Reviewed-by: Thiago Macieira (cherry picked from commit ef24784f886ee12363cce38b05167efe7e7f8d89) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/text/qstringconverter.cpp | 8 ++++---- .../text/qstringconverter/tst_qstringconverter.cpp | 5 +---- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/corelib/text/qstringconverter.cpp b/src/corelib/text/qstringconverter.cpp index 744ccfa7635..7072da02a4d 100644 --- a/src/corelib/text/qstringconverter.cpp +++ b/src/corelib/text/qstringconverter.cpp @@ -1291,7 +1291,7 @@ static QString convertToUnicodeCharByChar(QByteArrayView in, quint32 codePage, while ((next = CharNextExA(codePage, mb, 0)) != mb) { wchar_t wc[2] ={0}; int charlength = int(next - mb); // always just a few bytes - int len = MultiByteToWideChar(codePage, MB_PRECOMPOSED|MB_ERR_INVALID_CHARS, mb, charlength, wc, 2); + int len = MultiByteToWideChar(codePage, MB_ERR_INVALID_CHARS, mb, charlength, wc, 2); if (len>0) { s.append(QChar(wc[0])); } else { @@ -1338,7 +1338,7 @@ QString QLocal8Bit::convertToUnicode_sys(QByteArrayView in, quint32 codePage, prev[0] = state->state_data[0]; prev[1] = mb[0]; state->remainingChars = 0; - len = MultiByteToWideChar(codePage, MB_PRECOMPOSED, prev, 2, out, outlen); + len = MultiByteToWideChar(codePage, 0, prev, 2, out, outlen); if (len) { if (mblen == 1) return QStringView(out, len).toString(); @@ -1349,12 +1349,12 @@ QString QLocal8Bit::convertToUnicode_sys(QByteArrayView in, quint32 codePage, } } - while (!(len=MultiByteToWideChar(codePage, MB_PRECOMPOSED|MB_ERR_INVALID_CHARS, + while (!(len=MultiByteToWideChar(codePage, MB_ERR_INVALID_CHARS, mb, mblen, out, int(outlen)))) { int r = GetLastError(); if (r == ERROR_INSUFFICIENT_BUFFER) { Q_ASSERT(QtPrivate::q_points_into_range(out, buf.data(), buf.data() + buf.size())); - const int wclen = MultiByteToWideChar(codePage, MB_PRECOMPOSED, mb, mblen, 0, 0); + const int wclen = MultiByteToWideChar(codePage, 0, mb, mblen, 0, 0); const qsizetype offset = qsizetype(out - buf.data()); sp.resize(offset + wclen); auto it = reinterpret_cast(sp.data()); diff --git a/tests/auto/corelib/text/qstringconverter/tst_qstringconverter.cpp b/tests/auto/corelib/text/qstringconverter/tst_qstringconverter.cpp index 67047e9f37f..97d0e85a2d7 100644 --- a/tests/auto/corelib/text/qstringconverter/tst_qstringconverter.cpp +++ b/tests/auto/corelib/text/qstringconverter/tst_qstringconverter.cpp @@ -2559,10 +2559,7 @@ void tst_QStringConverter::fromLocal8Bit_special_cases() result = QLocal8Bit::convertToUnicode_sys(octets.first(2), GB_18030, &state); QCOMPARE(result, QString()); QVERIFY(result.isNull()); - QEXPECT_FAIL("", - "We don't store enough state to handle this case. + GB 18030 does not work with " - "the MB_PRECOMPOSED flag.", - Abort); + QEXPECT_FAIL("", "We don't store enough state to handle this case.", Abort); QCOMPARE_GT(state.remainingChars, 0); // Then provide one more octet: result = QLocal8Bit::convertToUnicode_sys(octets.sliced(2, 1), GB_18030, &state);