summaryrefslogtreecommitdiff
path: root/core/fxcrt/xml/cfx_xmlelement.cpp
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2018-05-02 16:02:03 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-05-02 16:02:03 +0000
commit70180648ffd01dd3716871758411d2031aaaebbe (patch)
tree6cc1d7aa3df8c3e343a1ef6f7e032bae8499f6db /core/fxcrt/xml/cfx_xmlelement.cpp
parent8ab2b2b2869f769dc169b4a96bb67ec596d5278b (diff)
downloadpdfium-70180648ffd01dd3716871758411d2031aaaebbe.tar.xz
Add a CFX_XMLDocument class.
This CL adds a CFX_XMLDocument to act as the XML node container. All nodes are now owned by the document and the document is returned by the CFX_XMLParser. Classes which parse XML files now store the document instead of the root node. BUG: chromium:835636 Change-Id: I1e07d6115cf14714911d6fd4c3fa920c94fd5faf Reviewed-on: https://pdfium-review.googlesource.com/31313 Reviewed-by: Henrique Nakashima <hnakashima@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'core/fxcrt/xml/cfx_xmlelement.cpp')
-rw-r--r--core/fxcrt/xml/cfx_xmlelement.cpp25
1 files changed, 8 insertions, 17 deletions
diff --git a/core/fxcrt/xml/cfx_xmlelement.cpp b/core/fxcrt/xml/cfx_xmlelement.cpp
index 3befb242c9..74351b8c58 100644
--- a/core/fxcrt/xml/cfx_xmlelement.cpp
+++ b/core/fxcrt/xml/cfx_xmlelement.cpp
@@ -11,6 +11,7 @@
#include "core/fxcrt/cfx_widetextbuf.h"
#include "core/fxcrt/fx_extension.h"
#include "core/fxcrt/xml/cfx_xmlchardata.h"
+#include "core/fxcrt/xml/cfx_xmldocument.h"
#include "core/fxcrt/xml/cfx_xmltext.h"
#include "third_party/base/ptr_util.h"
#include "third_party/base/stl_util.h"
@@ -26,20 +27,18 @@ FX_XMLNODETYPE CFX_XMLElement::GetType() const {
return FX_XMLNODE_Element;
}
-std::unique_ptr<CFX_XMLNode> CFX_XMLElement::Clone() {
- auto pClone = pdfium::MakeUnique<CFX_XMLElement>(name_);
- pClone->attrs_ = attrs_;
+CFX_XMLNode* CFX_XMLElement::Clone(CFX_XMLDocument* doc) {
+ auto* node = doc->CreateNode<CFX_XMLElement>(name_);
+ node->attrs_ = attrs_;
- // TODO(dsinclair): This clone is wrong. It doesn't clone child nodes just
- // copies text nodes?
- WideString wsText;
+ // TODO(dsinclair): This clone is wrong. It doesn't clone all child nodes just
+ // text nodes?
for (CFX_XMLNode* pChild = GetFirstChild(); pChild;
pChild = pChild->GetNextSibling()) {
if (pChild->GetType() == FX_XMLNODE_Text)
- wsText += static_cast<CFX_XMLText*>(pChild)->GetText();
+ node->AppendChild(pChild->Clone(doc));
}
- pClone->SetTextData(wsText);
- return std::move(pClone);
+ return node;
}
WideString CFX_XMLElement::GetLocalTagName() const {
@@ -60,7 +59,6 @@ WideString CFX_XMLElement::GetNamespaceURI() const {
attr += L":";
attr += wsPrefix;
}
-
const CFX_XMLNode* pNode = this;
while (pNode) {
if (pNode->GetType() != FX_XMLNODE_Element)
@@ -89,13 +87,6 @@ WideString CFX_XMLElement::GetTextData() const {
return buffer.MakeString();
}
-void CFX_XMLElement::SetTextData(const WideString& wsText) {
- // TODO(dsinclair): Shouldn't this remove the children if you set blank text?
- if (wsText.IsEmpty())
- return;
- AppendChild(pdfium::MakeUnique<CFX_XMLText>(wsText));
-}
-
void CFX_XMLElement::Save(
const RetainPtr<IFX_SeekableWriteStream>& pXMLStream) {
ByteString bsNameEncoded = name_.UTF8Encode();