summaryrefslogtreecommitdiffstats
path: root/src/corelib/codecs
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/codecs
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/codecs')
-rw-r--r--src/corelib/codecs/qutfcodec.cpp21
-rw-r--r--src/corelib/codecs/qwindowscodec.cpp6
2 files changed, 27 insertions, 0 deletions
diff --git a/src/corelib/codecs/qutfcodec.cpp b/src/corelib/codecs/qutfcodec.cpp
index c518ab1d9c..d5dbd8758c 100644
--- a/src/corelib/codecs/qutfcodec.cpp
+++ b/src/corelib/codecs/qutfcodec.cpp
@@ -56,16 +56,25 @@ QUtf8Codec::~QUtf8Codec()
QByteArray QUtf8Codec::convertFromUnicode(const QChar *uc, int len, ConverterState *state) const
{
+ ConverterState s(QStringConverter::Flag::Stateless);
+ if (!state)
+ state = &s;
return QUtf8::convertFromUnicode(uc, len, state);
}
void QUtf8Codec::convertToUnicode(QString *target, const char *chars, int len, ConverterState *state) const
{
+ ConverterState s(QStringConverter::Flag::Stateless);
+ if (!state)
+ state = &s;
*target += QUtf8::convertToUnicode(chars, len, state);
}
QString QUtf8Codec::convertToUnicode(const char *chars, int len, ConverterState *state) const
{
+ ConverterState s(QStringConverter::Flag::Stateless);
+ if (!state)
+ state = &s;
return QUtf8::convertToUnicode(chars, len, state);
}
@@ -85,11 +94,17 @@ QUtf16Codec::~QUtf16Codec()
QByteArray QUtf16Codec::convertFromUnicode(const QChar *uc, int len, ConverterState *state) const
{
+ ConverterState s(QStringConverter::Flag::Stateless);
+ if (!state)
+ state = &s;
return QUtf16::convertFromUnicode(uc, len, state, e);
}
QString QUtf16Codec::convertToUnicode(const char *chars, int len, ConverterState *state) const
{
+ ConverterState s(QStringConverter::Flag::Stateless);
+ if (!state)
+ state = &s;
return QUtf16::convertToUnicode(chars, len, state, e);
}
@@ -146,11 +161,17 @@ QUtf32Codec::~QUtf32Codec()
QByteArray QUtf32Codec::convertFromUnicode(const QChar *uc, int len, ConverterState *state) const
{
+ ConverterState s(QStringConverter::Flag::Stateless);
+ if (!state)
+ state = &s;
return QUtf32::convertFromUnicode(uc, len, state, e);
}
QString QUtf32Codec::convertToUnicode(const char *chars, int len, ConverterState *state) const
{
+ ConverterState s(QStringConverter::Flag::Stateless);
+ if (!state)
+ state = &s;
return QUtf32::convertToUnicode(chars, len, state, e);
}
diff --git a/src/corelib/codecs/qwindowscodec.cpp b/src/corelib/codecs/qwindowscodec.cpp
index d8a0088d6a..4a4e9dca5b 100644
--- a/src/corelib/codecs/qwindowscodec.cpp
+++ b/src/corelib/codecs/qwindowscodec.cpp
@@ -52,11 +52,17 @@ QWindowsLocalCodec::~QWindowsLocalCodec()
QString QWindowsLocalCodec::convertToUnicode(const char *chars, int length, ConverterState *state) const
{
+ ConverterState s(QStringConverter::Flag::Stateless);
+ if (!state)
+ state = &s;
return QLocal8Bit::convertToUnicode(chars, length, state);
}
QByteArray QWindowsLocalCodec::convertFromUnicode(const QChar *ch, int uclen, ConverterState *state) const
{
+ ConverterState s(QStringConverter::Flag::Stateless);
+ if (!state)
+ state = &s;
return QLocal8Bit::convertFromUnicode(ch, uclen, state);
}