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>
This commit is contained in:
parent
5e5085c3bb
commit
0a02a598a4
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user