diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2017-04-05 11:48:21 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-04-05 16:10:44 +0000 |
commit | 5fa4e981ed6c431d86c51a74eba19ea4b816f541 (patch) | |
tree | 4bfa4afc2b89e1a423ec4838937042780eaa6191 /xfa/fde/xml/cfde_xmlinstruction.cpp | |
parent | ddcb6e7f47e2769fb4565bd4430ecb465a1f5417 (diff) | |
download | pdfium-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_xmlinstruction.cpp')
-rw-r--r-- | xfa/fde/xml/cfde_xmlinstruction.cpp | 125 |
1 files changed, 3 insertions, 122 deletions
diff --git a/xfa/fde/xml/cfde_xmlinstruction.cpp b/xfa/fde/xml/cfde_xmlinstruction.cpp index 2229b4768a..d289d9e88a 100644 --- a/xfa/fde/xml/cfde_xmlinstruction.cpp +++ b/xfa/fde/xml/cfde_xmlinstruction.cpp @@ -11,9 +11,7 @@ #include "third_party/base/stl_util.h" CFDE_XMLInstruction::CFDE_XMLInstruction(const CFX_WideString& wsTarget) - : m_wsTarget(wsTarget) { - ASSERT(m_wsTarget.GetLength() > 0); -} + : CFDE_XMLAttributeNode(wsTarget) {} CFDE_XMLInstruction::~CFDE_XMLInstruction() {} @@ -22,129 +20,12 @@ FDE_XMLNODETYPE CFDE_XMLInstruction::GetType() const { } std::unique_ptr<CFDE_XMLNode> CFDE_XMLInstruction::Clone() { - auto pClone = pdfium::MakeUnique<CFDE_XMLInstruction>(m_wsTarget); - pClone->m_Attributes = m_Attributes; + auto pClone = pdfium::MakeUnique<CFDE_XMLInstruction>(GetName()); + pClone->SetAttributes(GetAttributes()); pClone->m_TargetData = m_TargetData; return pClone; } -int32_t CFDE_XMLInstruction::CountAttributes() const { - return pdfium::CollectionSize<int32_t>(m_Attributes) / 2; -} - -bool CFDE_XMLInstruction::GetAttribute(int32_t index, - CFX_WideString& wsAttriName, - CFX_WideString& wsAttriValue) const { - int32_t iCount = pdfium::CollectionSize<int32_t>(m_Attributes); - ASSERT(index > -1 && index < iCount / 2); - for (int32_t i = 0; i < iCount; i += 2) { - if (index == 0) { - wsAttriName = m_Attributes[i]; - wsAttriValue = m_Attributes[i + 1]; - return true; - } - index--; - } - return false; -} - -bool CFDE_XMLInstruction::HasAttribute(const wchar_t* pwsAttriName) const { - int32_t iCount = pdfium::CollectionSize<int32_t>(m_Attributes); - for (int32_t i = 0; i < iCount; i += 2) { - if (m_Attributes[i].Compare(pwsAttriName) == 0) { - return true; - } - } - return false; -} - -void CFDE_XMLInstruction::GetString(const wchar_t* pwsAttriName, - CFX_WideString& wsAttriValue, - const wchar_t* pwsDefValue) const { - int32_t iCount = pdfium::CollectionSize<int32_t>(m_Attributes); - for (int32_t i = 0; i < iCount; i += 2) { - if (m_Attributes[i].Compare(pwsAttriName) == 0) { - wsAttriValue = m_Attributes[i + 1]; - return; - } - } - wsAttriValue = pwsDefValue; -} - -void CFDE_XMLInstruction::SetString(const CFX_WideString& wsAttriName, - const CFX_WideString& wsAttriValue) { - ASSERT(wsAttriName.GetLength() > 0); - int32_t iCount = pdfium::CollectionSize<int32_t>(m_Attributes); - for (int32_t i = 0; i < iCount; i += 2) { - if (m_Attributes[i].Compare(wsAttriName) == 0) { - m_Attributes[i] = wsAttriName; - m_Attributes[i + 1] = wsAttriValue; - return; - } - } - m_Attributes.push_back(wsAttriName); - m_Attributes.push_back(wsAttriValue); -} - -int32_t CFDE_XMLInstruction::GetInteger(const wchar_t* pwsAttriName, - int32_t iDefValue) const { - int32_t iCount = pdfium::CollectionSize<int32_t>(m_Attributes); - for (int32_t i = 0; i < iCount; i += 2) { - if (m_Attributes[i].Compare(pwsAttriName) == 0) { - return FXSYS_wtoi(m_Attributes[i + 1].c_str()); - } - } - return iDefValue; -} - -void CFDE_XMLInstruction::SetInteger(const wchar_t* pwsAttriName, - int32_t iAttriValue) { - CFX_WideString wsValue; - wsValue.Format(L"%d", iAttriValue); - SetString(pwsAttriName, wsValue); -} - -float CFDE_XMLInstruction::GetFloat(const wchar_t* pwsAttriName, - float fDefValue) const { - int32_t iCount = pdfium::CollectionSize<int32_t>(m_Attributes); - for (int32_t i = 0; i < iCount; i += 2) { - if (m_Attributes[i].Compare(pwsAttriName) == 0) { - return FXSYS_wcstof(m_Attributes[i + 1].c_str(), -1, nullptr); - } - } - return fDefValue; -} - -void CFDE_XMLInstruction::SetFloat(const wchar_t* pwsAttriName, - float fAttriValue) { - CFX_WideString wsValue; - wsValue.Format(L"%f", fAttriValue); - SetString(pwsAttriName, wsValue); -} - -void CFDE_XMLInstruction::RemoveAttribute(const wchar_t* pwsAttriName) { - int32_t iCount = pdfium::CollectionSize<int32_t>(m_Attributes); - for (int32_t i = 0; i < iCount; i += 2) { - if (m_Attributes[i].Compare(pwsAttriName) == 0) { - m_Attributes.erase(m_Attributes.begin() + i, - m_Attributes.begin() + i + 2); - return; - } - } -} - -int32_t CFDE_XMLInstruction::CountData() const { - return pdfium::CollectionSize<int32_t>(m_TargetData); -} - -bool CFDE_XMLInstruction::GetData(int32_t index, CFX_WideString& wsData) const { - if (!pdfium::IndexInBounds(m_TargetData, index)) - return false; - - wsData = m_TargetData[index]; - return true; -} - void CFDE_XMLInstruction::AppendData(const CFX_WideString& wsData) { m_TargetData.push_back(wsData); } |