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.6 6.5 Task-number: QTBUG-118185 Task-number: QTBUG-105105 Change-Id: I798c387170c73a953be874de139868543b2d775e Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
2e9bb2ee5d
commit
ef24784f88
@ -1292,7 +1292,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 {
|
||||
@ -1339,7 +1339,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();
|
||||
@ -1350,12 +1350,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<wchar_t *>(sp.data());
|
||||
|
@ -2568,10 +2568,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);
|
||||
|
Loading…
Reference in New Issue
Block a user