From 5fa4e981ed6c431d86c51a74eba19ea4b816f541 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Wed, 5 Apr 2017 11:48:21 -0400 Subject: Move XML attribute handling to a base class. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This CL moves the attribute handling out of CFDE_XMLElement and CFDE_XMLInstruction into a common CFDE_XMLAttributeNode. The handling is also converted to a std::map from either a) a vector storing name,value,name,value or b) two vectors one for names and the other for values. The unused Get/Set methods for interger and float are removed and the iteration is converted to use iterators. Change-Id: Icda00ae898a595d58b06af0ced337f55f47c317c Reviewed-on: https://pdfium-review.googlesource.com/3753 Reviewed-by: Nicolás Peña Commit-Queue: dsinclair --- xfa/fde/xml/cfde_xmlnode.cpp | 63 ++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 34 deletions(-) (limited to 'xfa/fde/xml/cfde_xmlnode.cpp') diff --git a/xfa/fde/xml/cfde_xmlnode.cpp b/xfa/fde/xml/cfde_xmlnode.cpp index 22bd262bf2..82db939a23 100644 --- a/xfa/fde/xml/cfde_xmlnode.cpp +++ b/xfa/fde/xml/cfde_xmlnode.cpp @@ -109,17 +109,17 @@ CFDE_XMLNode* CFDE_XMLNode::GetPath(const wchar_t* pPath, CFDE_XMLNode* pNode = m_pChild; while (pNode) { if (pNode->GetType() == FDE_XMLNODE_Element) { - if (bQualifiedName) { - ((CFDE_XMLElement*)pNode)->GetTagName(wsTag); - } else { - ((CFDE_XMLElement*)pNode)->GetLocalTagName(wsTag); - } + if (bQualifiedName) + wsTag = static_cast(pNode)->GetName(); + else + wsTag = static_cast(pNode)->GetLocalTagName(); + if (wsTag.Compare(csPath) == 0) { - if (iLength < 1) { + if (iLength < 1) pFind = pNode; - } else { + else pFind = pNode->GetPath(pStart, iLength, bQualifiedName); - } + if (pFind) return pFind; } @@ -335,7 +335,7 @@ void CFDE_XMLNode::SaveXMLNode(const CFX_RetainPtr& pXMLStream) { case FDE_XMLNODE_Instruction: { CFX_WideString ws; CFDE_XMLInstruction* pInstruction = (CFDE_XMLInstruction*)pNode; - if (pInstruction->m_wsTarget.CompareNoCase(L"xml") == 0) { + if (pInstruction->GetName().CompareNoCase(L"xml") == 0) { ws = L"GetCodePage(); if (wCodePage == FX_CODEPAGE_UTF16LE) { @@ -348,31 +348,28 @@ void CFDE_XMLNode::SaveXMLNode(const CFX_RetainPtr& pXMLStream) { ws += L"\"?>"; pXMLStream->WriteString(ws.c_str(), ws.GetLength()); } else { - ws.Format(L"m_wsTarget.c_str()); + ws.Format(L"GetName().c_str()); pXMLStream->WriteString(ws.c_str(), ws.GetLength()); - std::vector& attributes = pInstruction->m_Attributes; - int32_t i; - int32_t iCount = pdfium::CollectionSize(attributes); - CFX_WideString wsValue; - for (i = 0; i < iCount; i += 2) { - ws = L" "; - ws += attributes[i]; - ws += L"=\""; - wsValue = attributes[i + 1]; + + for (auto it : pInstruction->GetAttributes()) { + CFX_WideString wsValue = it.second; wsValue.Replace(L"&", L"&"); wsValue.Replace(L"<", L"<"); wsValue.Replace(L">", L">"); wsValue.Replace(L"\'", L"'"); wsValue.Replace(L"\"", L"""); + + ws = L" "; + ws += it.first; + ws += L"=\""; ws += wsValue; ws += L"\""; pXMLStream->WriteString(ws.c_str(), ws.GetLength()); } - std::vector& targetdata = pInstruction->m_TargetData; - iCount = pdfium::CollectionSize(targetdata); - for (i = 0; i < iCount; i++) { + + for (auto target : pInstruction->GetTargetData()) { ws = L" \""; - ws += targetdata[i]; + ws += target; ws += L"\""; pXMLStream->WriteString(ws.c_str(), ws.GetLength()); } @@ -384,22 +381,20 @@ void CFDE_XMLNode::SaveXMLNode(const CFX_RetainPtr& pXMLStream) { case FDE_XMLNODE_Element: { CFX_WideString ws; ws = L"<"; - ws += ((CFDE_XMLElement*)pNode)->m_wsTag; + ws += static_cast(pNode)->GetName(); pXMLStream->WriteString(ws.c_str(), ws.GetLength()); - std::vector& attributes = - static_cast(pNode)->m_Attributes; - int32_t iCount = pdfium::CollectionSize(attributes); - CFX_WideString wsValue; - for (int32_t i = 0; i < iCount; i += 2) { - ws = L" "; - ws += attributes[i]; - ws += L"=\""; - wsValue = attributes[i + 1]; + + for (auto it : static_cast(pNode)->GetAttributes()) { + CFX_WideString wsValue = it.second; wsValue.Replace(L"&", L"&"); wsValue.Replace(L"<", L"<"); wsValue.Replace(L">", L">"); wsValue.Replace(L"\'", L"'"); wsValue.Replace(L"\"", L"""); + + ws = L" "; + ws += it.first; + ws += L"=\""; ws += wsValue; ws += L"\""; pXMLStream->WriteString(ws.c_str(), ws.GetLength()); @@ -413,7 +408,7 @@ void CFDE_XMLNode::SaveXMLNode(const CFX_RetainPtr& pXMLStream) { pChild = pChild->m_pNext; } ws = L"m_wsTag; + ws += static_cast(pNode)->GetName(); ws += L"\n>"; } else { ws = L"\n/>"; -- cgit v1.2.3