From 4d67b9dcfbb379d9d65a5a1fec74600273941637 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Tue, 28 Apr 2020 18:15:54 +0200 Subject: Get rid of QTextCodec in QTextStream Use QStringConverter instead. Also change the default encoding of QTextStream to utf8. Change-Id: I30682e75fe0462d1a937539f773640c83a2d82e1 Reviewed-by: Thiago Macieira --- src/xml/dom/qdom.cpp | 37 +++++++++---------------------------- 1 file changed, 9 insertions(+), 28 deletions(-) (limited to 'src/xml/dom') diff --git a/src/xml/dom/qdom.cpp b/src/xml/dom/qdom.cpp index 5224c8b31c..c09770db82 100644 --- a/src/xml/dom/qdom.cpp +++ b/src/xml/dom/qdom.cpp @@ -3648,17 +3648,10 @@ bool QDomAttrPrivate::specified() const If \a encodeEOLs is true, characters will be escaped to survive End-of-Line Handling. */ static QString encodeText(const QString &str, - QTextStream &s, const bool encodeQuotes = true, const bool performAVN = false, const bool encodeEOLs = false) { -#if !QT_CONFIG(textcodec) - Q_UNUSED(s); -#else - const QTextCodec *const codec = s.codec(); - Q_ASSERT(codec); -#endif QString retval(str); int len = retval.length(); int i = 0; @@ -3695,19 +3688,7 @@ static QString encodeText(const QString &str, len += 4; i += 5; } else { -#if QT_CONFIG(textcodec) - if(codec->canEncode(ati)) - ++i; - else -#endif - { - // We have to use a character reference to get it through. - const ushort codepoint(ati.unicode()); - const QString replacement(QLatin1String("&#x") + QString::number(codepoint, 16) + QLatin1Char(';')); - retval.replace(i, 1, replacement); - i += replacement.length(); - len += replacement.length() - 1; - } + ++i; } } @@ -3717,9 +3698,9 @@ static QString encodeText(const QString &str, void QDomAttrPrivate::save(QTextStream& s, int, int) const { if (namespaceURI.isNull()) { - s << name << "=\"" << encodeText(value, s, true, true) << '\"'; + s << name << "=\"" << encodeText(value, true, true) << '\"'; } else { - s << prefix << ':' << name << "=\"" << encodeText(value, s, true, true) << '\"'; + s << prefix << ':' << name << "=\"" << encodeText(value, true, true) << '\"'; /* This is a fix for 138243, as good as it gets. * * QDomElementPrivate::save() output a namespace declaration if @@ -3733,7 +3714,7 @@ void QDomAttrPrivate::save(QTextStream& s, int, int) const * arrive in those situations. */ if(!ownerNode || ownerNode->prefix != prefix) { - s << " xmlns:" << prefix << "=\"" << encodeText(namespaceURI, s, true, true) << '\"'; + s << " xmlns:" << prefix << "=\"" << encodeText(namespaceURI, true, true) << '\"'; } } } @@ -4082,7 +4063,7 @@ void QDomElementPrivate::save(QTextStream& s, int depth, int indent) const qName = prefix + QLatin1Char(':') + name; nsDecl = QLatin1String(" xmlns:") + prefix; } - nsDecl += QLatin1String("=\"") + encodeText(namespaceURI, s) + QLatin1Char('\"'); + nsDecl += QLatin1String("=\"") + encodeText(namespaceURI) + QLatin1Char('\"'); } s << '<' << qName << nsDecl; @@ -4094,9 +4075,9 @@ void QDomElementPrivate::save(QTextStream& s, int depth, int indent) const for (; it != m_attr->map.constEnd(); ++it) { s << ' '; if (it.value()->namespaceURI.isNull()) { - s << it.value()->name << "=\"" << encodeText(it.value()->value, s, true, true) << '\"'; + s << it.value()->name << "=\"" << encodeText(it.value()->value, true, true) << '\"'; } else { - s << it.value()->prefix << ':' << it.value()->name << "=\"" << encodeText(it.value()->value, s, true, true) << '\"'; + s << it.value()->prefix << ':' << it.value()->name << "=\"" << encodeText(it.value()->value, true, true) << '\"'; /* This is a fix for 138243, as good as it gets. * * QDomElementPrivate::save() output a namespace declaration if @@ -4111,7 +4092,7 @@ void QDomElementPrivate::save(QTextStream& s, int depth, int indent) const if((!it.value()->ownerNode || it.value()->ownerNode->prefix != it.value()->prefix) && !outputtedPrefixes.hasSeen(it.value()->prefix)) { - s << " xmlns:" << it.value()->prefix << "=\"" << encodeText(it.value()->namespaceURI, s, true, true) << '\"'; + s << " xmlns:" << it.value()->prefix << "=\"" << encodeText(it.value()->namespaceURI, true, true) << '\"'; } } } @@ -4692,7 +4673,7 @@ QDomTextPrivate* QDomTextPrivate::splitText(int offset) void QDomTextPrivate::save(QTextStream& s, int, int) const { QDomTextPrivate *that = const_cast(this); - s << encodeText(value, s, !(that->parent() && that->parent()->isElement()), false, true); + s << encodeText(value, !(that->parent() && that->parent()->isElement()), false, true); } /************************************************************** -- cgit v1.2.3