summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/fxcrt/xml/cfx_xmlelement.cpp36
-rw-r--r--core/fxcrt/xml/cfx_xmlnode.cpp11
-rw-r--r--core/fxcrt/xml/cfx_xmlnode.h5
-rw-r--r--xfa/fxfa/parser/cxfa_simple_parser.cpp11
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_XMLNode> CFX_XMLElement::Clone() {
pClone->SetAttributes(GetAttributes());
WideString wsText;
- CFX_XMLNode* pChild = GetFirstChild();
- while (pChild) {
- switch (pChild->GetType()) {
- case FX_XMLNODE_Text:
- wsText += static_cast<CFX_XMLText*>(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<CFX_XMLText*>(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<CFX_XMLText*>(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<CFX_XMLText*>(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"</";
ws += GetName();
diff --git a/core/fxcrt/xml/cfx_xmlnode.cpp b/core/fxcrt/xml/cfx_xmlnode.cpp
index 6135907557..1851a4d81e 100644
--- a/core/fxcrt/xml/cfx_xmlnode.cpp
+++ b/core/fxcrt/xml/cfx_xmlnode.cpp
@@ -27,6 +27,7 @@ FX_XMLNODETYPE CFX_XMLNode::GetType() const {
void CFX_XMLNode::DeleteChildren() {
CFX_XMLNode* pChild = first_child_;
first_child_ = nullptr;
+ last_child_ = nullptr;
while (pChild) {
CFX_XMLNode* pNext = pChild->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;