summaryrefslogtreecommitdiffstats
path: root/src/corelib/serialization
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2020-04-06 15:29:42 +0200
committerLars Knoll <lars.knoll@qt.io>2020-05-01 18:53:03 +0200
commit0a02a598a429ceba17cbe85a5fbf167730a4038b (patch)
tree877e85e9fb6765929ac09336cadaa0ad31c06c1e /src/corelib/serialization
parent5e5085c3bba07f093facbf5d48532cf77139751f (diff)
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 <hausmann@gmail.com>
Diffstat (limited to 'src/corelib/serialization')
-rw-r--r--src/corelib/serialization/qxmlstream.cpp12
1 files changed, 6 insertions, 6 deletions
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 <private/qmemory_p.h>
@@ -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)