QLocal8Bit::convertFromUnicode[win]: Pre 2Gi changes
As we did for convertToUnicode, we do some smaller changes, like increasing indentation, and switching to using pointers and calculating the input-size in this commit, so that the real changes in the next commit are (hopefully) easier to read. Pick-to: 6.6 6.5 Task-number: QTBUG-105105 Change-Id: I3bf1a487f63a3e24efd7a945152647dd8fc0aca8 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> (cherry picked from commit cba0efc2705af1ef027603f7ee4cb60f184412d8) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
22f2fcd354
commit
5e882b5de9
@ -1504,13 +1504,21 @@ QByteArray QLocal8Bit::convertFromUnicode_sys(QStringView in, quint32 codePage,
|
|||||||
Q_ASSERT(uclen > 0);
|
Q_ASSERT(uclen > 0);
|
||||||
|
|
||||||
int len = 0;
|
int len = 0;
|
||||||
while (!(len = WideCharToMultiByte(codePage, 0, ch, int(uclen), out, int(outlen), nullptr,
|
while (uclen > 0) {
|
||||||
nullptr))) {
|
const int nextIn = qt_saturate<int>(uclen);
|
||||||
|
const int nextOut = qt_saturate<int>(outlen);
|
||||||
|
len = WideCharToMultiByte(codePage, 0, ch, nextIn, out, nextOut, nullptr, nullptr);
|
||||||
|
if (len > 0) {
|
||||||
|
ch += nextIn;
|
||||||
|
uclen -= nextIn;
|
||||||
|
out += len;
|
||||||
|
outlen -= len;
|
||||||
|
} else {
|
||||||
int r = GetLastError();
|
int r = GetLastError();
|
||||||
if (r == ERROR_INSUFFICIENT_BUFFER) {
|
if (r == ERROR_INSUFFICIENT_BUFFER) {
|
||||||
Q_ASSERT(mb.isEmpty());
|
Q_ASSERT(mb.isEmpty());
|
||||||
int neededLength = WideCharToMultiByte(codePage, 0, ch, int(uclen), nullptr, 0, nullptr,
|
int neededLength = WideCharToMultiByte(codePage, 0, ch, nextIn, nullptr, 0,
|
||||||
nullptr);
|
nullptr, nullptr);
|
||||||
const qsizetype currentLength = out - buf.data();
|
const qsizetype currentLength = out - buf.data();
|
||||||
mb.resize(currentLength + neededLength);
|
mb.resize(currentLength + neededLength);
|
||||||
memcpy(mb.data(), out, currentLength * sizeof(*out));
|
memcpy(mb.data(), out, currentLength * sizeof(*out));
|
||||||
@ -1521,14 +1529,15 @@ QByteArray QLocal8Bit::convertFromUnicode_sys(QStringView in, quint32 codePage,
|
|||||||
// Fail. Probably can't happen in fact (dwFlags is 0).
|
// Fail. Probably can't happen in fact (dwFlags is 0).
|
||||||
#ifndef QT_NO_DEBUG
|
#ifndef QT_NO_DEBUG
|
||||||
// Can't use qWarning(), as it'll recurse to handle %ls
|
// Can't use qWarning(), as it'll recurse to handle %ls
|
||||||
fprintf(stderr, "WideCharToMultiByte: Cannot convert multibyte text (error %d): %ls\n",
|
fprintf(stderr,
|
||||||
r,
|
"WideCharToMultiByte: Cannot convert multibyte text (error %d): %ls\n", r,
|
||||||
reinterpret_cast<const wchar_t *>(QStringView(ch, uclen).toString().utf16()));
|
reinterpret_cast<const wchar_t *>(
|
||||||
|
QStringView(ch, uclen).left(100).toString().utf16()));
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
out += len;
|
}
|
||||||
if (mb.isEmpty()) {
|
if (mb.isEmpty()) {
|
||||||
// We must have only used the stack buffer
|
// We must have only used the stack buffer
|
||||||
if (out != buf.data()) // else: we return null-array
|
if (out != buf.data()) // else: we return null-array
|
||||||
|
Loading…
x
Reference in New Issue
Block a user