diff options
author | Lars Knoll <lars.knoll@qt.io> | 2020-04-17 19:40:33 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2020-05-14 07:50:35 +0200 |
commit | 7e65f6a45d7ad4e67b8c27f983edd9c4b2281641 (patch) | |
tree | 3dcefd23601bbcdffb1d741076b3c30c71e52bb5 /src/corelib/kernel/qmimedata.cpp | |
parent | 124d587bb95f35c853ab3458bdeb1519d369cdf1 (diff) |
Remove QTextCodec dependency from QMimeData
We already assumed that 8bit data is utf8 encoded in all cases
but for HTML. Handle HTML through QStringDecoder now. This
removes support for encodings other than UTF based one and Latin1.
This is ok, as HTML should nowadays always be encoded in utf8 as
well (anything else is strongly discouraged by the HTML spec). In
addition, utf-8 and latin1 together seem to cover ~98% of all HTML
data.
Change-Id: I7e7165edd38cfac395faf72681e5715b6d014c14
Reviewed-by: David Faure <david.faure@kdab.com>
Diffstat (limited to 'src/corelib/kernel/qmimedata.cpp')
-rw-r--r-- | src/corelib/kernel/qmimedata.cpp | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/src/corelib/kernel/qmimedata.cpp b/src/corelib/kernel/qmimedata.cpp index c38dab3e3f..21a1350fc5 100644 --- a/src/corelib/kernel/qmimedata.cpp +++ b/src/corelib/kernel/qmimedata.cpp @@ -42,9 +42,7 @@ #include "private/qobject_p.h" #include "qurl.h" #include "qstringlist.h" -#if QT_CONFIG(textcodec) -#include "qtextcodec.h" -#endif +#include "qstringconverter.h" QT_BEGIN_NAMESPACE @@ -157,15 +155,18 @@ QVariant QMimeDataPrivate::retrieveTypedData(const QString &format, QMetaType::T if (data.userType() == QMetaType::QByteArray) { // see if we can convert to the requested type switch(type) { -#if QT_CONFIG(textcodec) case QMetaType::QString: { const QByteArray ba = data.toByteArray(); - QTextCodec *codec = QTextCodec::codecForName("utf-8"); - if (format == QLatin1String("text/html")) - codec = QTextCodec::codecForHtml(ba, codec); - return codec->toUnicode(ba); + if (format == QLatin1String("text/html")) { + auto encoding = QStringConverter::encodingForHtml(ba.constData(), ba.size()); + if (encoding) { + QStringDecoder toUtf16(*encoding); + return QString(toUtf16(ba)); + } + // fall back to utf8 + } + return QString::fromUtf8(ba); } -#endif // textcodec case QMetaType::QColor: { QVariant newData = data; newData.convert(QMetaType::QColor); |