From 7e65f6a45d7ad4e67b8c27f983edd9c4b2281641 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Fri, 17 Apr 2020 19:40:33 +0200 Subject: 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 --- src/corelib/kernel/qmimedata.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'src/corelib/kernel/qmimedata.cpp') 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); -- cgit v1.2.3