From 0a02a598a429ceba17cbe85a5fbf167730a4038b Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Mon, 6 Apr 2020 15:29:42 +0200 Subject: Read XML as utf-8 not latin1 if we don't have codecs 99.5% of all XML documents in the world are encoded in utf-8, not in latin1. Also fix the tr() methods to use fromUtf8() in line with the Qt6 policy that source code should be in utf8. Change-Id: Ie8744786185de839bfa5c9853b7bc36e36af293a Reviewed-by: Simon Hausmann --- src/corelib/serialization/qxmlstream.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/corelib/serialization') diff --git a/src/corelib/serialization/qxmlstream.cpp b/src/corelib/serialization/qxmlstream.cpp index 3e42a58bbe..bbec904795 100644 --- a/src/corelib/serialization/qxmlstream.cpp +++ b/src/corelib/serialization/qxmlstream.cpp @@ -60,13 +60,13 @@ #define Q_DECLARE_TR_FUNCTIONS(context) \ public: \ static inline QString tr(const char *sourceText, const char *comment = nullptr) \ - { Q_UNUSED(comment); return QString::fromLatin1(sourceText); } \ + { Q_UNUSED(comment); return QString::fromUtf8(sourceText); } \ static inline QString trUtf8(const char *sourceText, const char *comment = nullptr) \ - { Q_UNUSED(comment); return QString::fromLatin1(sourceText); } \ + { Q_UNUSED(comment); return QString::fromUtf8(sourceText); } \ static inline QString tr(const char *sourceText, const char*, int) \ - { return QString::fromLatin1(sourceText); } \ + { return QString::fromUtf8(sourceText); } \ static inline QString trUtf8(const char *sourceText, const char*, int) \ - { return QString::fromLatin1(sourceText); } \ + { return QString::fromUtf8(sourceText); } \ private: #endif #include @@ -1546,7 +1546,7 @@ uint QXmlStreamReaderPrivate::getChar_helper() return StreamEOF; } #else - readBuffer = QString::fromLatin1(rawReadBuffer.data(), nbytesread); + readBuffer = QString::fromUtf8(rawReadBuffer.data(), nbytesread); #endif // textcodec readBuffer.reserve(1); // keep capacity when calling resize() next time @@ -1821,7 +1821,7 @@ void QXmlStreamReaderPrivate::startDocument() err = QXmlStream::tr("%1 is an invalid encoding name.").arg(value); else { #if !QT_CONFIG(textcodec) - readBuffer = QString::fromLatin1(rawReadBuffer.data(), nbytesread); + readBuffer = QString::fromUtf8(rawReadBuffer.data(), nbytesread); #else QTextCodec *const newCodec = QTextCodec::codecForName(value.toLatin1()); if (!newCodec) -- cgit v1.2.3