diff options
Diffstat (limited to 'xfa/fde/xml')
-rw-r--r-- | xfa/fde/xml/cfde_xmlchardata.cpp | 9 | ||||
-rw-r--r-- | xfa/fde/xml/cfde_xmlchardata.h | 15 | ||||
-rw-r--r-- | xfa/fde/xml/cfde_xmldoc.cpp | 17 | ||||
-rw-r--r-- | xfa/fde/xml/cfde_xmlelement.cpp | 39 | ||||
-rw-r--r-- | xfa/fde/xml/cfde_xmlelement.h | 3 | ||||
-rw-r--r-- | xfa/fde/xml/cfde_xmlinstruction.cpp | 11 | ||||
-rw-r--r-- | xfa/fde/xml/cfde_xmlinstruction.h | 3 | ||||
-rw-r--r-- | xfa/fde/xml/cfde_xmlnode.cpp | 35 | ||||
-rw-r--r-- | xfa/fde/xml/cfde_xmlnode.h | 5 | ||||
-rw-r--r-- | xfa/fde/xml/cfde_xmltext.cpp | 7 | ||||
-rw-r--r-- | xfa/fde/xml/cfde_xmltext.h | 7 |
11 files changed, 66 insertions, 85 deletions
diff --git a/xfa/fde/xml/cfde_xmlchardata.cpp b/xfa/fde/xml/cfde_xmlchardata.cpp index 2339307938..bb2991937b 100644 --- a/xfa/fde/xml/cfde_xmlchardata.cpp +++ b/xfa/fde/xml/cfde_xmlchardata.cpp @@ -6,8 +6,10 @@ #include "xfa/fde/xml/cfde_xmlchardata.h" +#include "third_party/base/ptr_util.h" + CFDE_XMLCharData::CFDE_XMLCharData(const CFX_WideString& wsCData) - : CFDE_XMLNode(), m_wsCharData(wsCData) {} + : CFDE_XMLText(wsCData) {} CFDE_XMLCharData::~CFDE_XMLCharData() {} @@ -15,7 +17,6 @@ FDE_XMLNODETYPE CFDE_XMLCharData::GetType() const { return FDE_XMLNODE_CharData; } -CFDE_XMLNode* CFDE_XMLCharData::Clone(bool bRecursive) { - CFDE_XMLCharData* pClone = new CFDE_XMLCharData(m_wsCharData); - return pClone; +std::unique_ptr<CFDE_XMLNode> CFDE_XMLCharData::Clone() { + return pdfium::MakeUnique<CFDE_XMLCharData>(GetText()); } diff --git a/xfa/fde/xml/cfde_xmlchardata.h b/xfa/fde/xml/cfde_xmlchardata.h index ea1d3aa4bf..56babbc8b4 100644 --- a/xfa/fde/xml/cfde_xmlchardata.h +++ b/xfa/fde/xml/cfde_xmlchardata.h @@ -7,23 +7,18 @@ #ifndef XFA_FDE_XML_CFDE_XMLCHARDATA_H_ #define XFA_FDE_XML_CFDE_XMLCHARDATA_H_ +#include <memory> + #include "core/fxcrt/fx_string.h" -#include "xfa/fde/xml/cfde_xmlnode.h" +#include "xfa/fde/xml/cfde_xmltext.h" -class CFDE_XMLCharData : public CFDE_XMLNode { +class CFDE_XMLCharData : public CFDE_XMLText { public: explicit CFDE_XMLCharData(const CFX_WideString& wsCData); ~CFDE_XMLCharData() override; FDE_XMLNODETYPE GetType() const override; - CFDE_XMLNode* Clone(bool bRecursive) override; - - void GetCharData(CFX_WideString& wsCharData) const { - wsCharData = m_wsCharData; - } - void SetCharData(const CFX_WideString& wsCData) { m_wsCharData = wsCData; } - - CFX_WideString m_wsCharData; + std::unique_ptr<CFDE_XMLNode> Clone() override; }; #endif // XFA_FDE_XML_CFDE_XMLCHARDATA_H_ diff --git a/xfa/fde/xml/cfde_xmldoc.cpp b/xfa/fde/xml/cfde_xmldoc.cpp index bc526ae4b3..5d427fb06e 100644 --- a/xfa/fde/xml/cfde_xmldoc.cpp +++ b/xfa/fde/xml/cfde_xmldoc.cpp @@ -98,7 +98,8 @@ void CFDE_XMLDoc::SaveXMLNode(const CFX_RetainPtr<IFGAS_Stream>& pXMLStream, ws = L"?>"; pXMLStream->WriteString(ws.c_str(), ws.GetLength()); } - } break; + break; + } case FDE_XMLNODE_Element: { CFX_WideString ws; ws = L"<"; @@ -137,24 +138,26 @@ void CFDE_XMLDoc::SaveXMLNode(const CFX_RetainPtr<IFGAS_Stream>& pXMLStream, ws = L"\n/>"; } pXMLStream->WriteString(ws.c_str(), ws.GetLength()); - } break; + break; + } case FDE_XMLNODE_Text: { - CFX_WideString ws = ((CFDE_XMLText*)pNode)->m_wsText; + CFX_WideString ws = static_cast<CFDE_XMLText*>(pNode)->GetText(); ws.Replace(L"&", L"&"); ws.Replace(L"<", L"<"); ws.Replace(L">", L">"); ws.Replace(L"\'", L"'"); ws.Replace(L"\"", L"""); pXMLStream->WriteString(ws.c_str(), ws.GetLength()); - } break; + break; + } case FDE_XMLNODE_CharData: { CFX_WideString ws = L"<![CDATA["; - ws += ((CFDE_XMLCharData*)pNode)->m_wsCharData; + ws += static_cast<CFDE_XMLCharData*>(pNode)->GetText(); ws += L"]]>"; pXMLStream->WriteString(ws.c_str(), ws.GetLength()); - } break; - case FDE_XMLNODE_Unknown: break; + } + case FDE_XMLNODE_Unknown: default: break; } diff --git a/xfa/fde/xml/cfde_xmlelement.cpp b/xfa/fde/xml/cfde_xmlelement.cpp index aca27c50e3..646eea2ee2 100644 --- a/xfa/fde/xml/cfde_xmlelement.cpp +++ b/xfa/fde/xml/cfde_xmlelement.cpp @@ -7,6 +7,7 @@ #include "xfa/fde/xml/cfde_xmlelement.h" #include "core/fxcrt/fx_ext.h" +#include "third_party/base/ptr_util.h" #include "third_party/base/stl_util.h" #include "xfa/fde/xml/cfde_xmlchardata.h" #include "xfa/fde/xml/cfde_xmltext.h" @@ -22,29 +23,23 @@ FDE_XMLNODETYPE CFDE_XMLElement::GetType() const { return FDE_XMLNODE_Element; } -CFDE_XMLNode* CFDE_XMLElement::Clone(bool bRecursive) { - CFDE_XMLElement* pClone = new CFDE_XMLElement(m_wsTag); - if (!pClone) - return nullptr; - +std::unique_ptr<CFDE_XMLNode> CFDE_XMLElement::Clone() { + auto pClone = pdfium::MakeUnique<CFDE_XMLElement>(m_wsTag); pClone->m_Attributes = m_Attributes; - if (bRecursive) { - CloneChildren(pClone); - } else { - CFX_WideString wsText; - CFDE_XMLNode* pChild = m_pChild; - while (pChild) { - switch (pChild->GetType()) { - case FDE_XMLNODE_Text: - wsText += ((CFDE_XMLText*)pChild)->m_wsText; - break; - default: - break; - } - pChild = pChild->m_pNext; + + CFX_WideString wsText; + CFDE_XMLNode* pChild = m_pChild; + while (pChild) { + switch (pChild->GetType()) { + case FDE_XMLNODE_Text: + wsText += static_cast<CFDE_XMLText*>(pChild)->GetText(); + break; + default: + break; } - pClone->SetTextData(wsText); + pChild = pChild->m_pNext; } + pClone->SetTextData(wsText); return pClone; } @@ -202,10 +197,8 @@ void CFDE_XMLElement::GetTextData(CFX_WideString& wsText) const { while (pChild) { switch (pChild->GetType()) { case FDE_XMLNODE_Text: - buffer << ((CFDE_XMLText*)pChild)->m_wsText; - break; case FDE_XMLNODE_CharData: - buffer << ((CFDE_XMLCharData*)pChild)->m_wsCharData; + buffer << static_cast<CFDE_XMLText*>(pChild)->GetText(); break; default: break; diff --git a/xfa/fde/xml/cfde_xmlelement.h b/xfa/fde/xml/cfde_xmlelement.h index 8f61035979..c4c522e8a5 100644 --- a/xfa/fde/xml/cfde_xmlelement.h +++ b/xfa/fde/xml/cfde_xmlelement.h @@ -7,6 +7,7 @@ #ifndef XFA_FDE_XML_CFDE_XMLELEMENT_H_ #define XFA_FDE_XML_CFDE_XMLELEMENT_H_ +#include <memory> #include <vector> #include "core/fxcrt/fx_string.h" @@ -19,7 +20,7 @@ class CFDE_XMLElement : public CFDE_XMLNode { // CFDE_XMLNode FDE_XMLNODETYPE GetType() const override; - CFDE_XMLNode* Clone(bool bRecursive) override; + std::unique_ptr<CFDE_XMLNode> Clone() override; void GetTagName(CFX_WideString& wsTag) const; void GetLocalTagName(CFX_WideString& wsTag) const; diff --git a/xfa/fde/xml/cfde_xmlinstruction.cpp b/xfa/fde/xml/cfde_xmlinstruction.cpp index 64c980b439..2229b4768a 100644 --- a/xfa/fde/xml/cfde_xmlinstruction.cpp +++ b/xfa/fde/xml/cfde_xmlinstruction.cpp @@ -7,6 +7,7 @@ #include "xfa/fde/xml/cfde_xmlinstruction.h" #include "core/fxcrt/fx_ext.h" +#include "third_party/base/ptr_util.h" #include "third_party/base/stl_util.h" CFDE_XMLInstruction::CFDE_XMLInstruction(const CFX_WideString& wsTarget) @@ -20,16 +21,10 @@ FDE_XMLNODETYPE CFDE_XMLInstruction::GetType() const { return FDE_XMLNODE_Instruction; } -CFDE_XMLNode* CFDE_XMLInstruction::Clone(bool bRecursive) { - CFDE_XMLInstruction* pClone = new CFDE_XMLInstruction(m_wsTarget); - if (!pClone) - return nullptr; - +std::unique_ptr<CFDE_XMLNode> CFDE_XMLInstruction::Clone() { + auto pClone = pdfium::MakeUnique<CFDE_XMLInstruction>(m_wsTarget); pClone->m_Attributes = m_Attributes; pClone->m_TargetData = m_TargetData; - if (bRecursive) - CloneChildren(pClone); - return pClone; } diff --git a/xfa/fde/xml/cfde_xmlinstruction.h b/xfa/fde/xml/cfde_xmlinstruction.h index 58dc5f17ac..4e891e1fac 100644 --- a/xfa/fde/xml/cfde_xmlinstruction.h +++ b/xfa/fde/xml/cfde_xmlinstruction.h @@ -7,6 +7,7 @@ #ifndef XFA_FDE_XML_CFDE_XMLINSTRUCTION_H_ #define XFA_FDE_XML_CFDE_XMLINSTRUCTION_H_ +#include <memory> #include <vector> #include "core/fxcrt/fx_string.h" @@ -19,7 +20,7 @@ class CFDE_XMLInstruction : public CFDE_XMLNode { // CFDE_XMLNode FDE_XMLNODETYPE GetType() const override; - CFDE_XMLNode* Clone(bool bRecursive) override; + std::unique_ptr<CFDE_XMLNode> Clone() override; void GetTargetName(CFX_WideString& wsTarget) const { wsTarget = m_wsTarget; } int32_t CountAttributes() const; diff --git a/xfa/fde/xml/cfde_xmlnode.cpp b/xfa/fde/xml/cfde_xmlnode.cpp index bd86c0b071..22bd262bf2 100644 --- a/xfa/fde/xml/cfde_xmlnode.cpp +++ b/xfa/fde/xml/cfde_xmlnode.cpp @@ -325,7 +325,7 @@ CFDE_XMLNode* CFDE_XMLNode::RemoveNodeItem(CFDE_XMLNode::NodeItem eItem) { return pNode; } -CFDE_XMLNode* CFDE_XMLNode::Clone(bool bRecursive) { +std::unique_ptr<CFDE_XMLNode> CFDE_XMLNode::Clone() { return nullptr; } @@ -379,7 +379,8 @@ void CFDE_XMLNode::SaveXMLNode(const CFX_RetainPtr<IFGAS_Stream>& pXMLStream) { ws = L"?>"; pXMLStream->WriteString(ws.c_str(), ws.GetLength()); } - } break; + break; + } case FDE_XMLNODE_Element: { CFX_WideString ws; ws = L"<"; @@ -418,41 +419,27 @@ void CFDE_XMLNode::SaveXMLNode(const CFX_RetainPtr<IFGAS_Stream>& pXMLStream) { ws = L"\n/>"; } pXMLStream->WriteString(ws.c_str(), ws.GetLength()); - } break; + break; + } case FDE_XMLNODE_Text: { - CFX_WideString ws = ((CFDE_XMLText*)pNode)->m_wsText; + CFX_WideString ws = static_cast<CFDE_XMLText*>(pNode)->GetText(); ws.Replace(L"&", L"&"); ws.Replace(L"<", L"<"); ws.Replace(L">", L">"); ws.Replace(L"\'", L"'"); ws.Replace(L"\"", L"""); pXMLStream->WriteString(ws.c_str(), ws.GetLength()); - } break; + break; + } case FDE_XMLNODE_CharData: { CFX_WideString ws = L"<![CDATA["; - ws += ((CFDE_XMLCharData*)pNode)->m_wsCharData; + ws += static_cast<CFDE_XMLCharData*>(pNode)->GetText(); ws += L"]]>"; pXMLStream->WriteString(ws.c_str(), ws.GetLength()); - } break; - case FDE_XMLNODE_Unknown: break; + } + case FDE_XMLNODE_Unknown: default: break; } } - -void CFDE_XMLNode::CloneChildren(CFDE_XMLNode* pClone) { - if (!m_pChild) { - return; - } - CFDE_XMLNode* pNext = m_pChild; - CFDE_XMLNode* pCloneNext = pNext->Clone(true); - pClone->InsertChildNode(pCloneNext); - pNext = pNext->m_pNext; - while (pNext) { - CFDE_XMLNode* pChild = pNext->Clone(true); - pCloneNext->InsertNodeItem(CFDE_XMLNode::NextSibling, pChild); - pCloneNext = pChild; - pNext = pNext->m_pNext; - } -} diff --git a/xfa/fde/xml/cfde_xmlnode.h b/xfa/fde/xml/cfde_xmlnode.h index 178150fda5..3cfcd5c980 100644 --- a/xfa/fde/xml/cfde_xmlnode.h +++ b/xfa/fde/xml/cfde_xmlnode.h @@ -7,6 +7,8 @@ #ifndef XFA_FDE_XML_CFDE_XMLNODE_H_ #define XFA_FDE_XML_CFDE_XMLNODE_H_ +#include <memory> + #include "core/fxcrt/cfx_retain_ptr.h" #include "xfa/fgas/crt/ifgas_stream.h" @@ -44,7 +46,7 @@ class CFDE_XMLNode { virtual ~CFDE_XMLNode(); virtual FDE_XMLNODETYPE GetType() const; - virtual CFDE_XMLNode* Clone(bool bRecursive); + virtual std::unique_ptr<CFDE_XMLNode> Clone(); int32_t CountChildNodes() const; CFDE_XMLNode* GetChildNode(int32_t index) const; @@ -52,7 +54,6 @@ class CFDE_XMLNode { int32_t InsertChildNode(CFDE_XMLNode* pNode, int32_t index = -1); void RemoveChildNode(CFDE_XMLNode* pNode); void DeleteChildren(); - void CloneChildren(CFDE_XMLNode* pClone); CFDE_XMLNode* GetPath(const wchar_t* pPath, int32_t iLength = -1, diff --git a/xfa/fde/xml/cfde_xmltext.cpp b/xfa/fde/xml/cfde_xmltext.cpp index 6bc2d64354..2af66ac70c 100644 --- a/xfa/fde/xml/cfde_xmltext.cpp +++ b/xfa/fde/xml/cfde_xmltext.cpp @@ -6,6 +6,8 @@ #include "xfa/fde/xml/cfde_xmltext.h" +#include "third_party/base/ptr_util.h" + CFDE_XMLText::CFDE_XMLText(const CFX_WideString& wsText) : CFDE_XMLNode(), m_wsText(wsText) {} @@ -15,7 +17,6 @@ FDE_XMLNODETYPE CFDE_XMLText::GetType() const { return FDE_XMLNODE_Text; } -CFDE_XMLNode* CFDE_XMLText::Clone(bool bRecursive) { - CFDE_XMLText* pClone = new CFDE_XMLText(m_wsText); - return pClone; +std::unique_ptr<CFDE_XMLNode> CFDE_XMLText::Clone() { + return pdfium::MakeUnique<CFDE_XMLText>(m_wsText); } diff --git a/xfa/fde/xml/cfde_xmltext.h b/xfa/fde/xml/cfde_xmltext.h index 6f3945be09..6987c49980 100644 --- a/xfa/fde/xml/cfde_xmltext.h +++ b/xfa/fde/xml/cfde_xmltext.h @@ -7,6 +7,8 @@ #ifndef XFA_FDE_XML_CFDE_XMLTEXT_H_ #define XFA_FDE_XML_CFDE_XMLTEXT_H_ +#include <memory> + #include "core/fxcrt/fx_string.h" #include "xfa/fde/xml/cfde_xmlnode.h" @@ -17,11 +19,12 @@ class CFDE_XMLText : public CFDE_XMLNode { // CFDE_XMLNode FDE_XMLNODETYPE GetType() const override; - CFDE_XMLNode* Clone(bool bRecursive) override; + std::unique_ptr<CFDE_XMLNode> Clone() override; - void GetText(CFX_WideString& wsText) const { wsText = m_wsText; } + CFX_WideString GetText() const { return m_wsText; } void SetText(const CFX_WideString& wsText) { m_wsText = wsText; } + private: CFX_WideString m_wsText; }; |