summaryrefslogtreecommitdiffstats
path: root/src/xml/dom/qdom.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/xml/dom/qdom.cpp')
-rw-r--r--src/xml/dom/qdom.cpp502
1 files changed, 284 insertions, 218 deletions
diff --git a/src/xml/dom/qdom.cpp b/src/xml/dom/qdom.cpp
index b2fcac7f1b..b25cdf487f 100644
--- a/src/xml/dom/qdom.cpp
+++ b/src/xml/dom/qdom.cpp
@@ -23,6 +23,7 @@
#include <qxmlstream.h>
#include <private/qduplicatetracker_p.h>
#include <private/qstringiterator_p.h>
+#include <qvarlengtharray.h>
#include <stdio.h>
#include <limits>
@@ -46,7 +47,7 @@ using namespace Qt::StringLiterals;
/* ##### new TODOs:
- Remove empty emthods in the *Private classes
+ Remove empty methods in the *Private classes
Make a lot of the (mostly empty) methods in the public classes inline.
Specially constructors assignment operators and comparison operators are candidates.
@@ -373,52 +374,52 @@ QDomImplementation::QDomImplementation()
}
/*!
- Constructs a copy of \a x.
+ Constructs a copy of \a implementation.
*/
-QDomImplementation::QDomImplementation(const QDomImplementation &x)
+QDomImplementation::QDomImplementation(const QDomImplementation &implementation)
+ : impl(implementation.impl)
{
- impl = x.impl;
if (impl)
impl->ref.ref();
}
-QDomImplementation::QDomImplementation(QDomImplementationPrivate *p)
+QDomImplementation::QDomImplementation(QDomImplementationPrivate *pimpl)
+ : impl(pimpl)
{
// We want to be co-owners, so increase the reference count
- impl = p;
if (impl)
impl->ref.ref();
}
/*!
- Assigns \a x to this DOM implementation.
+ Assigns \a other to this DOM implementation.
*/
-QDomImplementation& QDomImplementation::operator=(const QDomImplementation &x)
+QDomImplementation& QDomImplementation::operator=(const QDomImplementation &other)
{
- if (x.impl)
- x.impl->ref.ref();
+ if (other.impl)
+ other.impl->ref.ref();
if (impl && !impl->ref.deref())
delete impl;
- impl = x.impl;
+ impl = other.impl;
return *this;
}
/*!
- Returns \c true if \a x and this DOM implementation object were
+ Returns \c true if \a other and this DOM implementation object were
created from the same QDomDocument; otherwise returns \c false.
*/
-bool QDomImplementation::operator==(const QDomImplementation &x) const
+bool QDomImplementation::operator==(const QDomImplementation &other) const
{
- return (impl == x.impl);
+ return impl == other.impl;
}
/*!
- Returns \c true if \a x and this DOM implementation object were
+ Returns \c true if \a other and this DOM implementation object were
created from different QDomDocuments; otherwise returns \c false.
*/
-bool QDomImplementation::operator!=(const QDomImplementation &x) const
+bool QDomImplementation::operator!=(const QDomImplementation &other) const
{
- return (impl != x.impl);
+ return !operator==(other);
}
/*!
@@ -645,10 +646,10 @@ bool QDomNodeListPrivate::operator==(const QDomNodeListPrivate &other) const
bool QDomNodeListPrivate::operator!=(const QDomNodeListPrivate &other) const
{
- return (node_impl != other.node_impl) || (tagname != other.tagname);
+ return !operator==(other);
}
-void QDomNodeListPrivate::createList()
+void QDomNodeListPrivate::createList() const
{
if (!node_impl)
return;
@@ -702,16 +703,21 @@ void QDomNodeListPrivate::createList()
}
}
-QDomNodePrivate* QDomNodeListPrivate::item(int index)
+bool QDomNodeListPrivate::maybeCreateList() const
{
if (!node_impl)
- return nullptr;
+ return false;
const QDomDocumentPrivate *const doc = node_impl->ownerDocument();
if (!doc || timestamp != doc->nodeListTime)
createList();
- if (index >= list.size())
+ return true;
+}
+
+QDomNodePrivate *QDomNodeListPrivate::item(int index)
+{
+ if (!maybeCreateList() || index >= list.size() || index < 0)
return nullptr;
return list.at(index);
@@ -719,16 +725,10 @@ QDomNodePrivate* QDomNodeListPrivate::item(int index)
int QDomNodeListPrivate::length() const
{
- if (!node_impl)
+ if (!maybeCreateList())
return 0;
- const QDomDocumentPrivate *const doc = node_impl->ownerDocument();
- if (!doc || timestamp != doc->nodeListTime) {
- QDomNodeListPrivate *that = const_cast<QDomNodeListPrivate *>(this);
- that->createList();
- }
-
- return list.count();
+ return list.size();
}
/**************************************************************
@@ -770,54 +770,54 @@ QDomNodeList::QDomNodeList()
{
}
-QDomNodeList::QDomNodeList(QDomNodeListPrivate* p)
- : impl(p)
+QDomNodeList::QDomNodeList(QDomNodeListPrivate *pimpl)
+ : impl(pimpl)
{
}
/*!
- Constructs a copy of \a n.
+ Constructs a copy of \a nodeList.
*/
-QDomNodeList::QDomNodeList(const QDomNodeList& n)
+QDomNodeList::QDomNodeList(const QDomNodeList &nodeList)
+ : impl(nodeList.impl)
{
- impl = n.impl;
if (impl)
impl->ref.ref();
}
/*!
- Assigns \a n to this node list.
+ Assigns \a other to this node list.
*/
-QDomNodeList& QDomNodeList::operator=(const QDomNodeList &n)
+QDomNodeList& QDomNodeList::operator=(const QDomNodeList &other)
{
- if (n.impl)
- n.impl->ref.ref();
+ if (other.impl)
+ other.impl->ref.ref();
if (impl && !impl->ref.deref())
delete impl;
- impl = n.impl;
+ impl = other.impl;
return *this;
}
/*!
- Returns \c true if the node list \a n and this node list are equal;
+ Returns \c true if the node list \a other and this node list are equal;
otherwise returns \c false.
*/
-bool QDomNodeList::operator==(const QDomNodeList &n) const
+bool QDomNodeList::operator==(const QDomNodeList &other) const
{
- if (impl == n.impl)
+ if (impl == other.impl)
return true;
- if (!impl || !n.impl)
+ if (!impl || !other.impl)
return false;
- return (*impl == *n.impl);
+ return (*impl == *other.impl);
}
/*!
- Returns \c true the node list \a n and this node list are not equal;
+ Returns \c true the node list \a other and this node list are not equal;
otherwise returns \c false.
*/
-bool QDomNodeList::operator!=(const QDomNodeList &n) const
+bool QDomNodeList::operator!=(const QDomNodeList &other) const
{
- return !operator==(n);
+ return !operator==(other);
}
/*!
@@ -1473,48 +1473,48 @@ QDomNode::QDomNode()
}
/*!
- Constructs a copy of \a n.
+ Constructs a copy of \a node.
The data of the copy is shared (shallow copy): modifying one node
will also change the other. If you want to make a deep copy, use
cloneNode().
*/
-QDomNode::QDomNode(const QDomNode &n)
+QDomNode::QDomNode(const QDomNode &node)
+ : impl(node.impl)
{
- impl = n.impl;
if (impl)
impl->ref.ref();
}
/*! \internal
- Constructs a new node for the data \a n.
+ Constructs a new node for the data \a pimpl.
*/
-QDomNode::QDomNode(QDomNodePrivate *n)
+QDomNode::QDomNode(QDomNodePrivate *pimpl)
+ : impl(pimpl)
{
- impl = n;
if (impl)
impl->ref.ref();
}
/*!
- Assigns a copy of \a n to this DOM node.
+ Assigns a copy of \a other to this DOM node.
The data of the copy is shared (shallow copy): modifying one node
will also change the other. If you want to make a deep copy, use
cloneNode().
*/
-QDomNode& QDomNode::operator=(const QDomNode &n)
+QDomNode& QDomNode::operator=(const QDomNode &other)
{
- if (n.impl)
- n.impl->ref.ref();
+ if (other.impl)
+ other.impl->ref.ref();
if (impl && !impl->ref.deref())
delete impl;
- impl = n.impl;
+ impl = other.impl;
return *this;
}
/*!
- Returns \c true if \a n and this DOM node are equal; otherwise
+ Returns \c true if \a other and this DOM node are equal; otherwise
returns \c false.
Any instance of QDomNode acts as a reference to an underlying data
@@ -1533,18 +1533,18 @@ QDomNode& QDomNode::operator=(const QDomNode &n)
\c {element3 == element4} will return false because they refer to
two different nodes in the underlying data structure.
*/
-bool QDomNode::operator== (const QDomNode& n) const
+bool QDomNode::operator==(const QDomNode &other) const
{
- return (impl == n.impl);
+ return impl == other.impl;
}
/*!
- Returns \c true if \a n and this DOM node are not equal; otherwise
+ Returns \c true if \a other and this DOM node are not equal; otherwise
returns \c false.
*/
-bool QDomNode::operator!= (const QDomNode& n) const
+bool QDomNode::operator!=(const QDomNode &other) const
{
- return (impl != n.impl);
+ return !operator==(other);
}
/*!
@@ -1621,15 +1621,14 @@ QString QDomNode::nodeValue() const
}
/*!
- Sets the node's value to \a v.
+ Sets the node's value to \a value.
\sa nodeValue()
*/
-void QDomNode::setNodeValue(const QString& v)
+void QDomNode::setNodeValue(const QString& value)
{
- if (!impl)
- return;
- IMPL->setNodeValue(v);
+ if (impl)
+ IMPL->setNodeValue(value);
}
/*!
@@ -2503,11 +2502,12 @@ int QDomNode::columnNumber() const
*
**************************************************************/
-QDomNamedNodeMapPrivate::QDomNamedNodeMapPrivate(QDomNodePrivate* n) : ref(1)
+QDomNamedNodeMapPrivate::QDomNamedNodeMapPrivate(QDomNodePrivate *pimpl)
+ : ref(1)
+ , parent(pimpl)
+ , readonly(false)
+ , appendToParent(false)
{
- readonly = false;
- parent = n;
- appendToParent = false;
}
QDomNamedNodeMapPrivate::~QDomNamedNodeMapPrivate()
@@ -2515,16 +2515,16 @@ QDomNamedNodeMapPrivate::~QDomNamedNodeMapPrivate()
clearMap();
}
-QDomNamedNodeMapPrivate* QDomNamedNodeMapPrivate::clone(QDomNodePrivate* p)
+QDomNamedNodeMapPrivate* QDomNamedNodeMapPrivate::clone(QDomNodePrivate *pimpl)
{
- std::unique_ptr<QDomNamedNodeMapPrivate> m(new QDomNamedNodeMapPrivate(p));
+ std::unique_ptr<QDomNamedNodeMapPrivate> m(new QDomNamedNodeMapPrivate(pimpl));
m->readonly = readonly;
m->appendToParent = appendToParent;
auto it = map.constBegin();
for (; it != map.constEnd(); ++it) {
- QDomNodePrivate *new_node = (*it)->cloneNode();
- new_node->setParent(p);
+ QDomNodePrivate *new_node = it.value()->cloneNode();
+ new_node->setParent(pimpl);
m->setNamedItem(new_node);
}
@@ -2539,16 +2539,16 @@ void QDomNamedNodeMapPrivate::clearMap()
if (!appendToParent) {
auto it = map.constBegin();
for (; it != map.constEnd(); ++it)
- if (!(*it)->ref.deref())
- delete *it;
+ if (!it.value()->ref.deref())
+ delete it.value();
}
map.clear();
}
QDomNodePrivate* QDomNamedNodeMapPrivate::namedItem(const QString& name) const
{
- auto it = map.constFind(name);
- return it == map.cend() ? nullptr : *it;
+ auto it = map.find(name);
+ return it == map.end() ? nullptr : it.value();
}
QDomNodePrivate* QDomNamedNodeMapPrivate::namedItemNS(const QString& nsURI, const QString& localName) const
@@ -2556,7 +2556,7 @@ QDomNodePrivate* QDomNamedNodeMapPrivate::namedItemNS(const QString& nsURI, cons
auto it = map.constBegin();
QDomNodePrivate *n;
for (; it != map.constEnd(); ++it) {
- n = *it;
+ n = it.value();
if (!n->prefix.isNull()) {
// node has a namespace
if (n->namespaceURI == nsURI && n->name == localName)
@@ -2623,12 +2623,12 @@ QDomNodePrivate* QDomNamedNodeMapPrivate::item(int index) const
{
if (index >= length() || index < 0)
return nullptr;
- return *std::next(map.cbegin(), index);
+ return std::next(map.begin(), index).value();
}
int QDomNamedNodeMapPrivate::length() const
{
- return map.count();
+ return map.size();
}
bool QDomNamedNodeMapPrivate::contains(const QString& name) const
@@ -2696,51 +2696,51 @@ QDomNamedNodeMap::QDomNamedNodeMap()
}
/*!
- Constructs a copy of \a n.
+ Constructs a copy of \a namedNodeMap.
*/
-QDomNamedNodeMap::QDomNamedNodeMap(const QDomNamedNodeMap &n)
+QDomNamedNodeMap::QDomNamedNodeMap(const QDomNamedNodeMap &namedNodeMap)
+ : impl(namedNodeMap.impl)
{
- impl = n.impl;
if (impl)
impl->ref.ref();
}
-QDomNamedNodeMap::QDomNamedNodeMap(QDomNamedNodeMapPrivate *n)
+QDomNamedNodeMap::QDomNamedNodeMap(QDomNamedNodeMapPrivate *pimpl)
+ : impl(pimpl)
{
- impl = n;
if (impl)
impl->ref.ref();
}
/*!
- Assigns \a n to this named node map.
+ Assigns \a other to this named node map.
*/
-QDomNamedNodeMap& QDomNamedNodeMap::operator=(const QDomNamedNodeMap &n)
+QDomNamedNodeMap& QDomNamedNodeMap::operator=(const QDomNamedNodeMap &other)
{
- if (n.impl)
- n.impl->ref.ref();
+ if (other.impl)
+ other.impl->ref.ref();
if (impl && !impl->ref.deref())
delete impl;
- impl = n.impl;
+ impl = other.impl;
return *this;
}
/*!
- Returns \c true if \a n and this named node map are equal; otherwise
+ Returns \c true if \a other and this named node map are equal; otherwise
returns \c false.
*/
-bool QDomNamedNodeMap::operator== (const QDomNamedNodeMap& n) const
+bool QDomNamedNodeMap::operator==(const QDomNamedNodeMap &other) const
{
- return (impl == n.impl);
+ return impl == other.impl;
}
/*!
- Returns \c true if \a n and this named node map are not equal;
+ Returns \c true if \a other and this named node map are not equal;
otherwise returns \c false.
*/
-bool QDomNamedNodeMap::operator!= (const QDomNamedNodeMap& n) const
+bool QDomNamedNodeMap::operator!=(const QDomNamedNodeMap &other) const
{
- return (impl != n.impl);
+ return !operator==(other);
}
/*!
@@ -3069,11 +3069,11 @@ void QDomDocumentTypePrivate::save(QTextStream& s, int, int indent) const
auto it2 = notations->map.constBegin();
for (; it2 != notations->map.constEnd(); ++it2)
- (*it2)->save(s, 0, indent);
+ it2.value()->save(s, 0, indent);
auto it = entities->map.constBegin();
for (; it != entities->map.constEnd(); ++it)
- (*it)->save(s, 0, indent);
+ it.value()->save(s, 0, indent);
s << ']';
}
@@ -3116,30 +3116,30 @@ QDomDocumentType::QDomDocumentType() : QDomNode()
}
/*!
- Constructs a copy of \a n.
+ Constructs a copy of \a documentType.
The data of the copy is shared (shallow copy): modifying one node
will also change the other. If you want to make a deep copy, use
cloneNode().
*/
-QDomDocumentType::QDomDocumentType(const QDomDocumentType& n)
- : QDomNode(n)
+QDomDocumentType::QDomDocumentType(const QDomDocumentType &documentType)
+ : QDomNode(documentType)
{
}
-QDomDocumentType::QDomDocumentType(QDomDocumentTypePrivate* n)
- : QDomNode(n)
+QDomDocumentType::QDomDocumentType(QDomDocumentTypePrivate *pimpl)
+ : QDomNode(pimpl)
{
}
/*!
- Assigns \a n to this document type.
+ Assigns \a other to this document type.
The data of the copy is shared (shallow copy): modifying one node
will also change the other. If you want to make a deep copy, use
cloneNode().
*/
-QDomDocumentType &QDomDocumentType::operator=(const QDomDocumentType &n) = default;
+QDomDocumentType &QDomDocumentType::operator=(const QDomDocumentType &other) = default;
/*!
Returns the name of the document type as specified in the
&lt;!DOCTYPE name&gt; tag.
@@ -3297,25 +3297,25 @@ QDomDocumentFragment::QDomDocumentFragment(QDomDocumentFragmentPrivate* n)
}
/*!
- Constructs a copy of \a x.
+ Constructs a copy of \a documentFragment.
The data of the copy is shared (shallow copy): modifying one node
will also change the other. If you want to make a deep copy, use
cloneNode().
*/
-QDomDocumentFragment::QDomDocumentFragment(const QDomDocumentFragment& x)
- : QDomNode(x)
+QDomDocumentFragment::QDomDocumentFragment(const QDomDocumentFragment &documentFragment)
+ : QDomNode(documentFragment)
{
}
/*!
- Assigns \a x to this DOM document fragment.
+ Assigns \a other to this DOM document fragment.
The data of the copy is shared (shallow copy): modifying one node
will also change the other. If you want to make a deep copy, use
cloneNode().
*/
-QDomDocumentFragment &QDomDocumentFragment::operator=(const QDomDocumentFragment &x) = default;
+QDomDocumentFragment &QDomDocumentFragment::operator=(const QDomDocumentFragment &other) = default;
/*!
\fn QDomNode::NodeType QDomDocumentFragment::nodeType() const
@@ -3354,7 +3354,7 @@ QDomNodePrivate* QDomCharacterDataPrivate::cloneNode(bool deep)
int QDomCharacterDataPrivate::dataLength() const
{
- return value.length();
+ return value.size();
}
QString QDomCharacterDataPrivate::substringData(unsigned long offset, unsigned long n) const
@@ -3423,14 +3423,14 @@ QDomCharacterData::QDomCharacterData()
}
/*!
- Constructs a copy of \a x.
+ Constructs a copy of \a characterData.
The data of the copy is shared (shallow copy): modifying one node
will also change the other. If you want to make a deep copy, use
cloneNode().
*/
-QDomCharacterData::QDomCharacterData(const QDomCharacterData& x)
- : QDomNode(x)
+QDomCharacterData::QDomCharacterData(const QDomCharacterData &characterData)
+ : QDomNode(characterData)
{
}
@@ -3440,13 +3440,13 @@ QDomCharacterData::QDomCharacterData(QDomCharacterDataPrivate* n)
}
/*!
- Assigns \a x to this character data.
+ Assigns \a other to this character data.
The data of the copy is shared (shallow copy): modifying one node
will also change the other. If you want to make a deep copy, use
cloneNode().
*/
-QDomCharacterData &QDomCharacterData::operator=(const QDomCharacterData &x) = default;
+QDomCharacterData &QDomCharacterData::operator=(const QDomCharacterData &other) = default;
/*!
Returns the string stored in this object.
@@ -3462,12 +3462,12 @@ QString QDomCharacterData::data() const
}
/*!
- Sets this object's string to \a v.
+ Sets this object's string to \a data.
*/
-void QDomCharacterData::setData(const QString& v)
+void QDomCharacterData::setData(const QString &data)
{
if (impl)
- impl->setNodeValue(v);
+ impl->setNodeValue(data);
}
/*!
@@ -3612,7 +3612,7 @@ static QString encodeText(const QString &str,
const bool encodeEOLs = false)
{
QString retval(str);
- int len = retval.length();
+ int len = retval.size();
int i = 0;
while (i < len) {
@@ -3640,8 +3640,8 @@ static QString encodeText(const QString &str,
ati == QChar(0x9))) {
const QString replacement(u"&#x"_s + QString::number(ati.unicode(), 16) + u';');
retval.replace(i, 1, replacement);
- i += replacement.length();
- len += replacement.length() - 1;
+ i += replacement.size();
+ len += replacement.size() - 1;
} else if (encodeEOLs && ati == QChar(0xD)) {
retval.replace(i, 1, "&#xd;"_L1); // Replace a single 0xD with a ref for 0xD
len += 4;
@@ -3729,14 +3729,14 @@ QDomAttr::QDomAttr()
}
/*!
- Constructs a copy of \a x.
+ Constructs a copy of \a attr.
The data of the copy is shared (shallow copy): modifying one node
will also change the other. If you want to make a deep copy, use
cloneNode().
*/
-QDomAttr::QDomAttr(const QDomAttr& x)
- : QDomNode(x)
+QDomAttr::QDomAttr(const QDomAttr &attr)
+ : QDomNode(attr)
{
}
@@ -3746,13 +3746,13 @@ QDomAttr::QDomAttr(QDomAttrPrivate* n)
}
/*!
- Assigns \a x to this DOM attribute.
+ Assigns \a other to this DOM attribute.
The data of the copy is shared (shallow copy): modifying one node
will also change the other. If you want to make a deep copy, use
cloneNode().
*/
-QDomAttr &QDomAttr::operator=(const QDomAttr &x) = default;
+QDomAttr &QDomAttr::operator=(const QDomAttr &other) = default;
/*!
Returns the attribute's name.
@@ -3804,15 +3804,15 @@ QString QDomAttr::value() const
}
/*!
- Sets the attribute's value to \a v.
+ Sets the attribute's value to \a value.
\sa value()
*/
-void QDomAttr::setValue(const QString& v)
+void QDomAttr::setValue(const QString &value)
{
if (!impl)
return;
- impl->setNodeValue(v);
+ impl->setNodeValue(value);
IMPL->m_specified = true;
}
@@ -4026,32 +4026,83 @@ void QDomElementPrivate::save(QTextStream& s, int depth, int indent) const
/* Write out attributes. */
if (!m_attr->map.isEmpty()) {
+ /*
+ * To ensure that we always output attributes in a consistent
+ * order, sort the attributes before writing them into the
+ * stream. (Note that the order may be different than the one
+ * that e.g. we've read from a file, or the program order in
+ * which these attributes have been populated. We just want to
+ * guarantee reproducibile outputs.)
+ */
+ struct SavedAttribute {
+ QString prefix;
+ QString name;
+ QString encodedValue;
+ };
+
+ /* Gather all the attributes to save. */
+ QVarLengthArray<SavedAttribute, 8> attributesToSave;
+ attributesToSave.reserve(m_attr->map.size());
+
QDuplicateTracker<QString> outputtedPrefixes;
- auto it = m_attr->map.constBegin();
- for (; it != m_attr->map.constEnd(); ++it) {
- s << ' ';
- if (it.value()->namespaceURI.isNull()) {
- s << it.value()->name << "=\"" << encodeText(it.value()->value, true, true) << '\"';
- } else {
- 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
- * the element is in a namespace, no matter what. This function do as well, meaning
- * that we get two identical namespace declaration if we don't have the if-
- * statement below.
- *
- * This doesn't work when the parent element has the same prefix as us but
- * a different namespace. However, this can only occur by the user modifying the element,
- * and we don't do fixups by that anyway, and hence it's the user responsibility to not
- * arrive in those situations. */
- 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, true, true) << '\"';
- }
+ for (const auto &[key, value] : std::as_const(m_attr->map).asKeyValueRange()) {
+ Q_UNUSED(key); /* We extract the attribute name from the value. */
+ bool mayNeedXmlNS = false;
+
+ SavedAttribute attr;
+ attr.name = value->name;
+ attr.encodedValue = encodeText(value->value, true, true);
+ if (!value->namespaceURI.isNull()) {
+ attr.prefix = value->prefix;
+ mayNeedXmlNS = true;
+ }
+
+ attributesToSave.push_back(std::move(attr));
+
+ /*
+ * This is a fix for 138243, as good as it gets.
+ *
+ * QDomElementPrivate::save() output a namespace
+ * declaration if the element is in a namespace, no matter
+ * what. This function do as well, meaning that we get two
+ * identical namespace declaration if we don't have the if-
+ * statement below.
+ *
+ * This doesn't work when the parent element has the same
+ * prefix as us but a different namespace. However, this
+ * can only occur by the user modifying the element, and we
+ * don't do fixups by that anyway, and hence it's the user
+ * responsibility to avoid those situations.
+ */
+
+ if (mayNeedXmlNS
+ && ((!value->ownerNode || value->ownerNode->prefix != value->prefix)
+ && !outputtedPrefixes.hasSeen(value->prefix)))
+ {
+ SavedAttribute nsAttr;
+ nsAttr.prefix = QStringLiteral("xmlns");
+ nsAttr.name = value->prefix;
+ nsAttr.encodedValue = encodeText(value->namespaceURI, true, true);
+ attributesToSave.push_back(std::move(nsAttr));
}
}
+
+ /* Sort the attributes by prefix and name. */
+ const auto savedAttributeComparator = [](const SavedAttribute &lhs, const SavedAttribute &rhs)
+ {
+ const int cmp = QString::compare(lhs.prefix, rhs.prefix);
+ return (cmp < 0) || ((cmp == 0) && (lhs.name < rhs.name));
+ };
+
+ std::sort(attributesToSave.begin(), attributesToSave.end(), savedAttributeComparator);
+
+ /* Actually stream the sorted attributes. */
+ for (const auto &attr : attributesToSave) {
+ s << ' ';
+ if (!attr.prefix.isEmpty())
+ s << attr.prefix << ':';
+ s << attr.name << "=\"" << attr.encodedValue << '\"';
+ }
}
if (last) {
@@ -4149,14 +4200,14 @@ QDomElement::QDomElement()
}
/*!
- Constructs a copy of \a x.
+ Constructs a copy of \a element.
The data of the copy is shared (shallow copy): modifying one node
will also change the other. If you want to make a deep copy, use
cloneNode().
*/
-QDomElement::QDomElement(const QDomElement& x)
- : QDomNode(x)
+QDomElement::QDomElement(const QDomElement &element)
+ : QDomNode(element)
{
}
@@ -4166,13 +4217,13 @@ QDomElement::QDomElement(QDomElementPrivate* n)
}
/*!
- Assigns \a x to this DOM element.
+ Assigns \a other to this DOM element.
The data of the copy is shared (shallow copy): modifying one node
will also change the other. If you want to make a deep copy, use
cloneNode().
*/
-QDomElement &QDomElement::operator=(const QDomElement &x) = default;
+QDomElement &QDomElement::operator=(const QDomElement &other) = default;
/*!
\fn QDomNode::NodeType QDomElement::nodeType() const
@@ -4619,6 +4670,10 @@ QDomTextPrivate* QDomTextPrivate::splitText(int offset)
value.truncate(offset);
parent()->insertAfter(t, this);
+ Q_ASSERT(t->ref.loadRelaxed() == 2);
+
+ // We are not interested in this node
+ t->ref.deref();
return t;
}
@@ -4666,14 +4721,14 @@ QDomText::QDomText()
}
/*!
- Constructs a copy of \a x.
+ Constructs a copy of \a text.
The data of the copy is shared (shallow copy): modifying one node
will also change the other. If you want to make a deep copy, use
cloneNode().
*/
-QDomText::QDomText(const QDomText& x)
- : QDomCharacterData(x)
+QDomText::QDomText(const QDomText &text)
+ : QDomCharacterData(text)
{
}
@@ -4683,13 +4738,13 @@ QDomText::QDomText(QDomTextPrivate* n)
}
/*!
- Assigns \a x to this DOM text.
+ Assigns \a other to this DOM text.
The data of the copy is shared (shallow copy): modifying one node
will also change the other. If you want to make a deep copy, use
cloneNode().
*/
-QDomText &QDomText::operator=(const QDomText &x) = default;
+QDomText &QDomText::operator=(const QDomText &other) = default;
/*!
\fn QDomNode::NodeType QDomText::nodeType() const
@@ -4794,14 +4849,14 @@ QDomComment::QDomComment()
}
/*!
- Constructs a copy of \a x.
+ Constructs a copy of \a comment.
The data of the copy is shared (shallow copy): modifying one node
will also change the other. If you want to make a deep copy, use
cloneNode().
*/
-QDomComment::QDomComment(const QDomComment& x)
- : QDomCharacterData(x)
+QDomComment::QDomComment(const QDomComment &comment)
+ : QDomCharacterData(comment)
{
}
@@ -4811,13 +4866,13 @@ QDomComment::QDomComment(QDomCommentPrivate* n)
}
/*!
- Assigns \a x to this DOM comment.
+ Assigns \a other to this DOM comment.
The data of the copy is shared (shallow copy): modifying one node
will also change the other. If you want to make a deep copy, use
cloneNode().
*/
-QDomComment &QDomComment::operator=(const QDomComment &x) = default;
+QDomComment &QDomComment::operator=(const QDomComment &other) = default;
/*!
\fn QDomNode::NodeType QDomComment::nodeType() const
@@ -4899,14 +4954,14 @@ QDomCDATASection::QDomCDATASection()
}
/*!
- Constructs a copy of \a x.
+ Constructs a copy of \a cdataSection.
The data of the copy is shared (shallow copy): modifying one node
will also change the other. If you want to make a deep copy, use
cloneNode().
*/
-QDomCDATASection::QDomCDATASection(const QDomCDATASection& x)
- : QDomText(x)
+QDomCDATASection::QDomCDATASection(const QDomCDATASection &cdataSection)
+ : QDomText(cdataSection)
{
}
@@ -4916,13 +4971,13 @@ QDomCDATASection::QDomCDATASection(QDomCDATASectionPrivate* n)
}
/*!
- Assigns \a x to this CDATA section.
+ Assigns \a other to this CDATA section.
The data of the copy is shared (shallow copy): modifying one node
will also change the other. If you want to make a deep copy, use
cloneNode().
*/
-QDomCDATASection &QDomCDATASection::operator=(const QDomCDATASection &x) = default;
+QDomCDATASection &QDomCDATASection::operator=(const QDomCDATASection &other) = default;
/*!
\fn QDomNode::NodeType QDomCDATASection::nodeType() const
@@ -5020,14 +5075,14 @@ QDomNotation::QDomNotation()
}
/*!
- Constructs a copy of \a x.
+ Constructs a copy of \a notation.
The data of the copy is shared (shallow copy): modifying one node
will also change the other. If you want to make a deep copy, use
cloneNode().
*/
-QDomNotation::QDomNotation(const QDomNotation& x)
- : QDomNode(x)
+QDomNotation::QDomNotation(const QDomNotation &notation)
+ : QDomNode(notation)
{
}
@@ -5037,13 +5092,13 @@ QDomNotation::QDomNotation(QDomNotationPrivate* n)
}
/*!
- Assigns \a x to this DOM notation.
+ Assigns \a other to this DOM notation.
The data of the copy is shared (shallow copy): modifying one node
will also change the other. If you want to make a deep copy, use
cloneNode().
*/
-QDomNotation &QDomNotation::operator=(const QDomNotation &x) = default;
+QDomNotation &QDomNotation::operator=(const QDomNotation &other) = default;
/*!
\fn QDomNode::NodeType QDomNotation::nodeType() const
@@ -5214,14 +5269,14 @@ QDomEntity::QDomEntity()
/*!
- Constructs a copy of \a x.
+ Constructs a copy of \a entity.
The data of the copy is shared (shallow copy): modifying one node
will also change the other. If you want to make a deep copy, use
cloneNode().
*/
-QDomEntity::QDomEntity(const QDomEntity& x)
- : QDomNode(x)
+QDomEntity::QDomEntity(const QDomEntity &entity)
+ : QDomNode(entity)
{
}
@@ -5231,13 +5286,13 @@ QDomEntity::QDomEntity(QDomEntityPrivate* n)
}
/*!
- Assigns \a x to this DOM entity.
+ Assigns \a other to this DOM entity.
The data of the copy is shared (shallow copy): modifying one node
will also change the other. If you want to make a deep copy, use
cloneNode().
*/
-QDomEntity &QDomEntity::operator=(const QDomEntity &x) = default;
+QDomEntity &QDomEntity::operator=(const QDomEntity &other) = default;
/*!
\fn QDomNode::NodeType QDomEntity::nodeType() const
@@ -5363,14 +5418,14 @@ QDomEntityReference::QDomEntityReference()
}
/*!
- Constructs a copy of \a x.
+ Constructs a copy of \a entityReference.
The data of the copy is shared (shallow copy): modifying one node
will also change the other. If you want to make a deep copy, use
cloneNode().
*/
-QDomEntityReference::QDomEntityReference(const QDomEntityReference& x)
- : QDomNode(x)
+QDomEntityReference::QDomEntityReference(const QDomEntityReference &entityReference)
+ : QDomNode(entityReference)
{
}
@@ -5380,13 +5435,13 @@ QDomEntityReference::QDomEntityReference(QDomEntityReferencePrivate* n)
}
/*!
- Assigns \a x to this entity reference.
+ Assigns \a other to this entity reference.
The data of the copy is shared (shallow copy): modifying one node
will also change the other. If you want to make a deep copy, use
cloneNode().
*/
-QDomEntityReference &QDomEntityReference::operator=(const QDomEntityReference &x) = default;
+QDomEntityReference &QDomEntityReference::operator=(const QDomEntityReference &other) = default;
/*!
\fn QDomNode::NodeType QDomEntityReference::nodeType() const
@@ -5477,14 +5532,14 @@ QDomProcessingInstruction::QDomProcessingInstruction()
}
/*!
- Constructs a copy of \a x.
+ Constructs a copy of \a processingInstruction.
The data of the copy is shared (shallow copy): modifying one node
will also change the other. If you want to make a deep copy, use
cloneNode().
*/
-QDomProcessingInstruction::QDomProcessingInstruction(const QDomProcessingInstruction& x)
- : QDomNode(x)
+QDomProcessingInstruction::QDomProcessingInstruction(const QDomProcessingInstruction &processingInstruction)
+ : QDomNode(processingInstruction)
{
}
@@ -5494,14 +5549,14 @@ QDomProcessingInstruction::QDomProcessingInstruction(QDomProcessingInstructionPr
}
/*!
- Assigns \a x to this processing instruction.
+ Assigns \a other to this processing instruction.
The data of the copy is shared (shallow copy): modifying one node
will also change the other. If you want to make a deep copy, use
cloneNode().
*/
QDomProcessingInstruction &
-QDomProcessingInstruction::operator=(const QDomProcessingInstruction &x) = default;
+QDomProcessingInstruction::operator=(const QDomProcessingInstruction &other) = default;
/*!
\fn QDomNode::NodeType QDomProcessingInstruction::nodeType() const
@@ -5534,15 +5589,14 @@ QString QDomProcessingInstruction::data() const
}
/*!
- Sets the data contained in the processing instruction to \a d.
+ Sets the data contained in the processing instruction to \a data.
\sa data()
*/
-void QDomProcessingInstruction::setData(const QString& d)
+void QDomProcessingInstruction::setData(const QString &data)
{
- if (!impl)
- return;
- impl->setNodeValue(d);
+ if (impl)
+ impl->setNodeValue(data);
}
/**************************************************************
@@ -5940,8 +5994,8 @@ void QDomDocumentPrivate::saveDocument(QTextStream& s, const int indent, QDomNod
representation of the document can be obtained using toString().
\note The DOM tree might end up reserving a lot of memory if the XML
- document is big. For such documents, the QXmlStreamReader or the
- QXmlQuery classes might be better solutions.
+ document is big. For such documents, the QXmlStreamReader class
+ might be a better solution.
It is possible to insert a node from another document into the
document using importNode().
@@ -5966,10 +6020,9 @@ void QDomDocumentPrivate::saveDocument(QTextStream& s, const int indent, QDomNod
\l{http://www.w3.org/TR/DOM-Level-2-Core/}{Level 2 Core}
Specifications.
- \sa {DOM Bookmarks Example}, {Simple DOM Model Example}
+ \sa {DOM Bookmarks Application}
*/
-
/*!
Constructs an empty document.
*/
@@ -5999,30 +6052,30 @@ QDomDocument::QDomDocument(const QDomDocumentType& doctype)
}
/*!
- Constructs a copy of \a x.
+ Constructs a copy of \a document.
The data of the copy is shared (shallow copy): modifying one node
will also change the other. If you want to make a deep copy, use
cloneNode().
*/
-QDomDocument::QDomDocument(const QDomDocument& x)
- : QDomNode(x)
+QDomDocument::QDomDocument(const QDomDocument &document)
+ : QDomNode(document)
{
}
-QDomDocument::QDomDocument(QDomDocumentPrivate* x)
- : QDomNode(x)
+QDomDocument::QDomDocument(QDomDocumentPrivate *pimpl)
+ : QDomNode(pimpl)
{
}
/*!
- Assigns \a x to this DOM document.
+ Assigns \a other to this DOM document.
The data of the copy is shared (shallow copy): modifying one node
will also change the other. If you want to make a deep copy, use
cloneNode().
*/
-QDomDocument &QDomDocument::operator=(const QDomDocument &x) = default;
+QDomDocument &QDomDocument::operator=(const QDomDocument &other) = default;
/*!
Destroys the object and frees its resources.
@@ -6031,8 +6084,12 @@ QDomDocument::~QDomDocument()
{
}
+#if QT_DEPRECATED_SINCE(6, 8)
+QT_WARNING_PUSH
+QT_WARNING_DISABLE_DEPRECATED
/*!
\overload
+ \deprecated [6.8] Use the overloads taking ParseOptions instead.
This function reads the XML document from the string \a text, returning
true if the content was successfully parsed; otherwise returns \c false.
@@ -6048,6 +6105,9 @@ bool QDomDocument::setContent(const QString& text, bool namespaceProcessing,
}
/*!
+ \deprecated [6.8] Use the overload taking ParseOptions instead.
+ \overload
+
This function parses the XML document from the byte array \a
data and sets it as the content of the document. It tries to
detect the encoding of the document as required by the XML
@@ -6119,12 +6179,13 @@ static inline void unpackParseResult(const QDomDocument::ParseResult &parseResul
if (errorLine)
*errorLine = static_cast<int>(parseResult.errorLine);
if (errorColumn)
- *errorColumn = static_cast<int>(parseResult.errorLine);
+ *errorColumn = static_cast<int>(parseResult.errorColumn);
}
}
/*!
\overload
+ \deprecated [6.8] Use the overload taking ParseOptions instead.
This function reads the XML document from the IO device \a dev, returning
true if the content was successfully parsed; otherwise returns \c false.
@@ -6144,6 +6205,7 @@ bool QDomDocument::setContent(QIODevice* dev, bool namespaceProcessing,
/*!
\overload
+ \deprecated [6.8] Use the overload returning ParseResult instead.
This function reads the XML document from the string \a text, returning
true if the content was successfully parsed; otherwise returns \c false.
@@ -6159,6 +6221,7 @@ bool QDomDocument::setContent(const QString& text, QString *errorMsg, int *error
/*!
\overload
+ \deprecated [6.8] Use the overload returning ParseResult instead.
This function reads the XML document from the byte array \a buffer,
returning true if the content was successfully parsed; otherwise returns
@@ -6173,7 +6236,7 @@ bool QDomDocument::setContent(const QByteArray& buffer, QString *errorMsg, int *
/*!
\overload
- \deprecated
+ \deprecated [6.8] Use the overload returning ParseResult instead.
This function reads the XML document from the IO device \a dev, returning
true if the content was successfully parsed; otherwise returns \c false.
@@ -6188,6 +6251,7 @@ bool QDomDocument::setContent(QIODevice* dev, QString *errorMsg, int *errorLine,
/*!
\overload
\since 5.15
+ \deprecated [6.8] Use the overload taking ParseOptions instead.
This function reads the XML document from the QXmlStreamReader \a reader
and parses it. Returns \c true if the content was successfully parsed;
@@ -6211,6 +6275,8 @@ bool QDomDocument::setContent(QXmlStreamReader *reader, bool namespaceProcessing
unpackParseResult(result, errorMsg, errorLine, errorColumn);
return bool(result);
}
+QT_WARNING_POP
+#endif // QT_DEPRECATED_SINCE(6, 8)
/*!
\enum QDomDocument::ParseOption
@@ -6272,8 +6338,8 @@ bool QDomDocument::setContent(QXmlStreamReader *reader, bool namespaceProcessing
/*!
\fn QDomDocument::ParseResult::operator bool() const
- Returns \c true if an error is found by QDomDocument::setContent();
- otherwise returns \c false.
+ Returns \c false if any error is found by QDomDocument::setContent();
+ otherwise returns \c true.
\sa QDomDocument::setContent()
*/