summaryrefslogtreecommitdiff
path: root/xfa/fde/xml/cfde_xmldoc.cpp
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-04-05 11:48:21 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-04-05 16:10:44 +0000
commit5fa4e981ed6c431d86c51a74eba19ea4b816f541 (patch)
tree4bfa4afc2b89e1a423ec4838937042780eaa6191 /xfa/fde/xml/cfde_xmldoc.cpp
parentddcb6e7f47e2769fb4565bd4430ecb465a1f5417 (diff)
downloadpdfium-5fa4e981ed6c431d86c51a74eba19ea4b816f541.tar.xz
Move XML attribute handling to a base class.
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 <npm@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'xfa/fde/xml/cfde_xmldoc.cpp')
-rw-r--r--xfa/fde/xml/cfde_xmldoc.cpp47
1 files changed, 21 insertions, 26 deletions
diff --git a/xfa/fde/xml/cfde_xmldoc.cpp b/xfa/fde/xml/cfde_xmldoc.cpp
index 5d427fb06e..7032700578 100644
--- a/xfa/fde/xml/cfde_xmldoc.cpp
+++ b/xfa/fde/xml/cfde_xmldoc.cpp
@@ -54,7 +54,7 @@ void CFDE_XMLDoc::SaveXMLNode(const CFX_RetainPtr<IFGAS_Stream>& 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"<?xml version=\"1.0\" encoding=\"";
uint16_t wCodePage = pXMLStream->GetCodePage();
if (wCodePage == FX_CODEPAGE_UTF16LE) {
@@ -67,31 +67,28 @@ void CFDE_XMLDoc::SaveXMLNode(const CFX_RetainPtr<IFGAS_Stream>& pXMLStream,
ws += L"\"?>";
pXMLStream->WriteString(ws.c_str(), ws.GetLength());
} else {
- ws.Format(L"<?%s", pInstruction->m_wsTarget.c_str());
+ ws.Format(L"<?%s", pInstruction->GetName().c_str());
pXMLStream->WriteString(ws.c_str(), ws.GetLength());
- std::vector<CFX_WideString>& attributes = pInstruction->m_Attributes;
- int32_t i;
- int32_t iCount = pdfium::CollectionSize<int32_t>(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"&amp;");
wsValue.Replace(L"<", L"&lt;");
wsValue.Replace(L">", L"&gt;");
wsValue.Replace(L"\'", L"&apos;");
wsValue.Replace(L"\"", L"&quot;");
+
+ ws = L" ";
+ ws += it.first;
+ ws += L"=\"";
ws += wsValue;
ws += L"\"";
pXMLStream->WriteString(ws.c_str(), ws.GetLength());
}
- std::vector<CFX_WideString>& targetdata = pInstruction->m_TargetData;
- iCount = pdfium::CollectionSize<int32_t>(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());
}
@@ -103,22 +100,20 @@ void CFDE_XMLDoc::SaveXMLNode(const CFX_RetainPtr<IFGAS_Stream>& pXMLStream,
case FDE_XMLNODE_Element: {
CFX_WideString ws;
ws = L"<";
- ws += ((CFDE_XMLElement*)pNode)->m_wsTag;
+ ws += static_cast<CFDE_XMLElement*>(pNode)->GetName();
pXMLStream->WriteString(ws.c_str(), ws.GetLength());
- std::vector<CFX_WideString>& attributes =
- static_cast<CFDE_XMLElement*>(pNode)->m_Attributes;
- int32_t iCount = pdfium::CollectionSize<int32_t>(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<CFDE_XMLElement*>(pNode)->GetAttributes()) {
+ CFX_WideString wsValue = it.second;
wsValue.Replace(L"&", L"&amp;");
wsValue.Replace(L"<", L"&lt;");
wsValue.Replace(L">", L"&gt;");
wsValue.Replace(L"\'", L"&apos;");
wsValue.Replace(L"\"", L"&quot;");
+
+ ws = L" ";
+ ws += it.first;
+ ws += L"=\"";
ws += wsValue;
ws += L"\"";
pXMLStream->WriteString(ws.c_str(), ws.GetLength());
@@ -132,7 +127,7 @@ void CFDE_XMLDoc::SaveXMLNode(const CFX_RetainPtr<IFGAS_Stream>& pXMLStream,
pChild = pChild->m_pNext;
}
ws = L"</";
- ws += ((CFDE_XMLElement*)pNode)->m_wsTag;
+ ws += static_cast<CFDE_XMLElement*>(pNode)->GetName();
ws += L"\n>";
} else {
ws = L"\n/>";