summaryrefslogtreecommitdiff
path: root/Build/source/texk/dvisvgm/dvisvgm-src/src/XMLNode.cpp
diff options
context:
space:
mode:
authorTakuji Tanaka <ttk@t-lab.opal.ne.jp>2021-01-23 08:47:24 +0000
committerTakuji Tanaka <ttk@t-lab.opal.ne.jp>2021-01-23 08:47:24 +0000
commitd6bed26b0031e2fc1c06c7524653a0c692784286 (patch)
tree6c7f961e775ca16b18a1804538db93ed0d41927d /Build/source/texk/dvisvgm/dvisvgm-src/src/XMLNode.cpp
parentcefa6c9380ba792d6c1646c71c6ebf4934de8d7a (diff)
dvisvgm 2.11.1
git-svn-id: svn://tug.org/texlive/trunk@57501 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk/dvisvgm/dvisvgm-src/src/XMLNode.cpp')
-rw-r--r--Build/source/texk/dvisvgm/dvisvgm-src/src/XMLNode.cpp67
1 files changed, 32 insertions, 35 deletions
diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/XMLNode.cpp b/Build/source/texk/dvisvgm/dvisvgm-src/src/XMLNode.cpp
index db07d95dd2d..b71ac7e8074 100644
--- a/Build/source/texk/dvisvgm/dvisvgm-src/src/XMLNode.cpp
+++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/XMLNode.cpp
@@ -2,7 +2,7 @@
** XMLNode.cpp **
** **
** This file is part of dvisvgm -- a fast DVI to SVG converter **
-** Copyright (C) 2005-2020 Martin Gieseking <martin.gieseking@uos.de> **
+** Copyright (C) 2005-2021 Martin Gieseking <martin.gieseking@uos.de> **
** **
** This program is free software; you can redistribute it and/or **
** modify it under the terms of the GNU General Public License as **
@@ -259,7 +259,7 @@ XMLElement* XMLElement::wrap (XMLNode *first, XMLNode *last, const string &name)
XMLNode *child = first;
while (child && child != last) {
XMLNode *next = child->next();
- wrapper->insertLast(remove(child));
+ wrapper->insertLast(detach(child));
child = next;
}
XMLElement *ret = wrapper.get();
@@ -277,44 +277,41 @@ XMLElement* XMLElement::wrap (XMLNode *first, XMLNode *last, const string &name)
* Example: unwrap a child element b of a:
* <a>text1<b><c/>text2<d/></b></a> => <a>text1<c/>text2<d/></a>
* @param[in] child child element to unwrap
- * @return raw pointer to the first node C1 of the unwrapped sequence */
-XMLNode* XMLElement::unwrap (XMLElement *child) {
- if (!child || !child->parent())
+ * @return raw pointer to the first node C1 of the unwrapped sequence or nullptr if element was empty */
+XMLNode* XMLElement::unwrap (XMLElement *element) {
+ if (!element || !element->parent())
return nullptr;
- XMLElement *parent = child->parent()->toElement();
- auto removedChild = remove(child);
- if (child->empty())
- return child->next();
- XMLNode *firstGrandchild = child->firstChild();
- XMLNode *prev = child->prev();
- unique_ptr<XMLNode> grandchild = std::move(child->_firstChild);
- while (grandchild) {
- prev = parent->insertAfter(std::move(grandchild), prev);
- grandchild = std::move(prev->_next);
- }
- return firstGrandchild;
-}
-
-
-/** Removes a child node from the element.
- * @param[in] child pointer to child to remove
- * @return pointer to removed child or nullptr if given child doesn't belong to this element */
-unique_ptr<XMLNode> XMLElement::remove (XMLNode *child) {
- unique_ptr<XMLNode> node;
- if (child && child->parent()) {
- XMLElement *parent = child->parent()->toElement();
- if (child == parent->_lastChild)
- parent->_lastChild = child->prev();
- if (child != parent->firstChild())
- node = child->prev()->removeNext();
+ XMLElement *parent = element->parent()->toElement();
+ XMLNode *prev = element->prev();
+ auto detachedElement = util::static_unique_ptr_cast<XMLElement>(detach(element));
+ if (detachedElement->empty())
+ return nullptr;
+ XMLNode *firstChild = detachedElement->firstChild();
+ while (auto child = detach(detachedElement->firstChild()))
+ prev = parent->insertAfter(std::move(child), prev);
+ return firstChild;
+}
+
+
+/** Isolates a node and its descendants from a subtree.
+ * @param[in] node raw pointer to node to be detached
+ * @return unique pointer to the detached node. */
+unique_ptr<XMLNode> XMLElement::detach (XMLNode *node) {
+ unique_ptr<XMLNode> uniqueNode;
+ if (node && node->parent()) {
+ XMLElement *parent = node->parent()->toElement();
+ if (node == parent->_lastChild)
+ parent->_lastChild = node->prev();
+ if (node != parent->firstChild())
+ uniqueNode = node->prev()->removeNext();
else {
- node = std::move(parent->_firstChild);
- if ((parent->_firstChild = std::move(node->_next)))
+ uniqueNode = std::move(parent->_firstChild);
+ if ((parent->_firstChild = std::move(uniqueNode->_next)))
parent->_firstChild->prev(nullptr);
}
- child->parent(nullptr);
+ node->parent(nullptr);
}
- return node;
+ return uniqueNode;
}