summaryrefslogtreecommitdiffstats
path: root/src/corelib/text/qstring.cpp
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2020-04-21 15:55:50 +0200
committerLars Knoll <lars.knoll@qt.io>2020-05-14 07:47:40 +0200
commit618620bc5d82619789c9f3914f0ca3f0b1752e39 (patch)
tree331e221eb08d2a4609d34f0a7744984c8ebccac6 /src/corelib/text/qstring.cpp
parentcab0d57d1eb02d93774f4e444cb4514400bac0e9 (diff)
Ensure the conversion methods in qstringconverter always get a valid state
Make sure that the conversion methods always get a valid state. This is already the ecase then using the new QStringConverter API, ensure the old QTextCodec API also passes in a valid state. This helps simplify the logic inside those methods. Change-Id: I1945e98cdefd46bf1427e11984337f1d62abcaa2 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'src/corelib/text/qstring.cpp')
-rw-r--r--src/corelib/text/qstring.cpp12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp
index 21ca6f5eb2..7753ce5f00 100644
--- a/src/corelib/text/qstring.cpp
+++ b/src/corelib/text/qstring.cpp
@@ -5206,7 +5206,8 @@ static QByteArray qt_convert_to_local_8bit(QStringView string)
{
if (string.isNull())
return QByteArray();
- return QLocal8Bit::convertFromUnicode(string.data(), string.length(), nullptr);
+ QStringEncoder fromUtf16(QStringEncoder::Locale, QStringEncoder::Flag::Stateless);
+ return fromUtf16(string);
}
/*!
@@ -5391,7 +5392,8 @@ QString QString::fromLocal8Bit_helper(const char *str, int size)
QString::DataPointer empty = { pair.first, pair.second, 0 };
return QString(empty);
}
- return QLocal8Bit::convertToUnicode(str, size, nullptr);
+ QStringDecoder toUtf16(QStringDecoder::Locale, QStringDecoder::Flag::Stateless);
+ return toUtf16(str, size);
}
/*! \fn QString QString::fromUtf8(const char *str, int size)
@@ -5458,7 +5460,8 @@ QString QString::fromUtf16(const char16_t *unicode, int size)
while (unicode[size] != 0)
++size;
}
- return QUtf16::convertToUnicode((const char *)unicode, size*2, nullptr);
+ QStringDecoder toUtf16(QStringDecoder::Utf16, QStringDecoder::Flag::Stateless);
+ return toUtf16(reinterpret_cast<const char *>(unicode), size*2);
}
/*!
@@ -5495,7 +5498,8 @@ QString QString::fromUcs4(const char32_t *unicode, int size)
while (unicode[size] != 0)
++size;
}
- return QUtf32::convertToUnicode((const char *)unicode, size*4, nullptr);
+ QStringDecoder toUtf16(QStringDecoder::Utf32, QStringDecoder::Flag::Stateless);
+ return toUtf16(reinterpret_cast<const char *>(unicode), size*4);
}