From 9bf1a5efde45cd99be11c530232df349c3eb5295 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Tue, 13 Feb 2018 22:04:23 +0000 Subject: Add last_child to CFX_XMLNode This CL adds the list_child_ member into CFX_XMLNode to keep it consistent with other tree's in the system. Change-Id: I2e64f11fb9c7df40dd3467edcce177fc492d2cd2 Reviewed-on: https://pdfium-review.googlesource.com/26670 Reviewed-by: Tom Sepez Commit-Queue: dsinclair --- core/fxcrt/xml/cfx_xmlelement.cpp | 36 ++++++++++++---------------------- core/fxcrt/xml/cfx_xmlnode.cpp | 11 +++++++++++ core/fxcrt/xml/cfx_xmlnode.h | 5 +++-- xfa/fxfa/parser/cxfa_simple_parser.cpp | 11 +---------- 4 files changed, 28 insertions(+), 35 deletions(-) diff --git a/core/fxcrt/xml/cfx_xmlelement.cpp b/core/fxcrt/xml/cfx_xmlelement.cpp index 4eb3900c2f..530752e1dd 100644 --- a/core/fxcrt/xml/cfx_xmlelement.cpp +++ b/core/fxcrt/xml/cfx_xmlelement.cpp @@ -29,16 +29,10 @@ std::unique_ptr CFX_XMLElement::Clone() { pClone->SetAttributes(GetAttributes()); WideString wsText; - CFX_XMLNode* pChild = GetFirstChild(); - while (pChild) { - switch (pChild->GetType()) { - case FX_XMLNODE_Text: - wsText += static_cast(pChild)->GetText(); - break; - default: - break; - } - pChild = pChild->GetNextSibling(); + for (CFX_XMLNode* pChild = GetFirstChild(); pChild; + pChild = pChild->GetNextSibling()) { + if (pChild->GetType() == FX_XMLNODE_Text) + wsText += static_cast(pChild)->GetText(); } pClone->SetTextData(wsText); return std::move(pClone); @@ -81,17 +75,13 @@ WideString CFX_XMLElement::GetNamespaceURI() const { WideString CFX_XMLElement::GetTextData() const { CFX_WideTextBuf buffer; - CFX_XMLNode* pChild = GetFirstChild(); - while (pChild) { - switch (pChild->GetType()) { - case FX_XMLNODE_Text: - case FX_XMLNODE_CharData: - buffer << static_cast(pChild)->GetText(); - break; - default: - break; + + for (CFX_XMLNode* pChild = GetFirstChild(); pChild; + pChild = pChild->GetNextSibling()) { + if (pChild->GetType() == FX_XMLNODE_Text || + pChild->GetType() == FX_XMLNODE_CharData) { + buffer << static_cast(pChild)->GetText(); } - pChild = pChild->GetNextSibling(); } return buffer.MakeString(); } @@ -116,10 +106,10 @@ void CFX_XMLElement::Save( if (GetFirstChild()) { ws = L"\n>"; pXMLStream->WriteString(ws.AsStringView()); - CFX_XMLNode* pChild = GetFirstChild(); - while (pChild) { + + for (CFX_XMLNode* pChild = GetFirstChild(); pChild; + pChild = pChild->GetNextSibling()) { pChild->Save(pXMLStream); - pChild = pChild->GetNextSibling(); } ws = L"next_sibling_; @@ -44,11 +45,15 @@ void CFX_XMLNode::InsertChildNode(CFX_XMLNode* pNode, int32_t index) { pNode->parent_ = this; if (!first_child_) { + ASSERT(!last_child_); + first_child_ = pNode; + last_child_ = pNode; pNode->prev_sibling_ = nullptr; pNode->next_sibling_ = nullptr; return; } + if (index == 0) { pNode->next_sibling_ = first_child_; pNode->prev_sibling_ = nullptr; @@ -66,7 +71,10 @@ void CFX_XMLNode::InsertChildNode(CFX_XMLNode* pNode, int32_t index) { pNode->next_sibling_ = pFind->next_sibling_; if (pFind->next_sibling_) pFind->next_sibling_->prev_sibling_ = pNode; + pFind->next_sibling_ = pNode; + if (pFind == last_child_) + last_child_ = pNode; } void CFX_XMLNode::RemoveChildNode(CFX_XMLNode* pNode) { @@ -77,6 +85,9 @@ void CFX_XMLNode::RemoveChildNode(CFX_XMLNode* pNode) { else pNode->prev_sibling_->next_sibling_ = pNode->next_sibling_; + if (last_child_ == pNode) + last_child_ = pNode->prev_sibling_; + if (pNode->next_sibling_) pNode->next_sibling_->prev_sibling_ = pNode->prev_sibling_; diff --git a/core/fxcrt/xml/cfx_xmlnode.h b/core/fxcrt/xml/cfx_xmlnode.h index e2154c4f71..cf2158af5b 100644 --- a/core/fxcrt/xml/cfx_xmlnode.h +++ b/core/fxcrt/xml/cfx_xmlnode.h @@ -50,9 +50,10 @@ class CFX_XMLNode { private: CFX_XMLNode* parent_ = nullptr; - CFX_XMLNode* first_child_ = nullptr; - CFX_XMLNode* prev_sibling_ = nullptr; CFX_XMLNode* next_sibling_ = nullptr; + CFX_XMLNode* prev_sibling_ = nullptr; + CFX_XMLNode* first_child_ = nullptr; + CFX_XMLNode* last_child_ = nullptr; }; #endif // CORE_FXCRT_XML_CFX_XMLNODE_H_ diff --git a/xfa/fxfa/parser/cxfa_simple_parser.cpp b/xfa/fxfa/parser/cxfa_simple_parser.cpp index eee5cb3d83..42498695e9 100644 --- a/xfa/fxfa/parser/cxfa_simple_parser.cpp +++ b/xfa/fxfa/parser/cxfa_simple_parser.cpp @@ -101,8 +101,7 @@ const PacketInfo* GetPacketByName(const WideStringView& wsName) { return nullptr; } -CFX_XMLNode* GetDocumentNode(CFX_XMLDoc* pXMLDoc, - bool bVerifyWellFormness = false) { +CFX_XMLNode* GetDocumentNode(CFX_XMLDoc* pXMLDoc) { if (!pXMLDoc) return nullptr; @@ -111,14 +110,6 @@ CFX_XMLNode* GetDocumentNode(CFX_XMLDoc* pXMLDoc, if (pXMLNode->GetType() != FX_XMLNODE_Element) continue; - if (!bVerifyWellFormness) - return pXMLNode; - - for (CFX_XMLNode* pNextNode = pXMLNode->GetNextSibling(); pNextNode; - pNextNode = pNextNode->GetNextSibling()) { - if (pNextNode->GetType() == FX_XMLNODE_Element) - return nullptr; - } return pXMLNode; } return nullptr; -- cgit v1.2.3