diff options
author | Tom Sepez <tsepez@chromium.org> | 2016-02-17 16:58:49 -0800 |
---|---|---|
committer | Tom Sepez <tsepez@chromium.org> | 2016-02-17 16:58:49 -0800 |
commit | dee2d7ba656cdf8111f879485146e0900630826a (patch) | |
tree | 3ea64c42d591456fedcf3e3cdd9d4f12dcdf1e18 /core/src/fxcrt | |
parent | 1e1d3b0f2bc6b6c185b37e0aa6b8663e901dc8bf (diff) | |
download | pdfium-dee2d7ba656cdf8111f879485146e0900630826a.tar.xz |
Banish CFX_ObjectArray to the XFA side.
Tidy whitespace, add missing consts in a few places. Remove
a few pointless typedefs.
R=thestig@chromium.org
Review URL: https://codereview.chromium.org/1707953002 .
Diffstat (limited to 'core/src/fxcrt')
-rw-r--r-- | core/src/fxcrt/fx_xml_parser.cpp | 70 |
1 files changed, 24 insertions, 46 deletions
diff --git a/core/src/fxcrt/fx_xml_parser.cpp b/core/src/fxcrt/fx_xml_parser.cpp index 88789437c9..ab729eebaf 100644 --- a/core/src/fxcrt/fx_xml_parser.cpp +++ b/core/src/fxcrt/fx_xml_parser.cpp @@ -8,6 +8,7 @@ #include "core/include/fxcrt/fx_ext.h" #include "core/include/fxcrt/fx_xml.h" +#include "third_party/base/stl_util.h" CXML_Parser::~CXML_Parser() { if (m_bOwnedStream) { @@ -748,67 +749,44 @@ FX_DWORD CXML_Element::FindElement(CXML_Element* pChild) const { } return (FX_DWORD)-1; } + +bool CXML_AttrItem::Matches(const CFX_ByteStringC& space, + const CFX_ByteStringC& name) const { + return (space.IsEmpty() || m_QSpaceName == space) && m_AttrName == name; +} + const CFX_WideString* CXML_AttrMap::Lookup(const CFX_ByteStringC& space, const CFX_ByteStringC& name) const { - if (!m_pMap) { - return NULL; - } - for (int i = 0; i < m_pMap->GetSize(); i++) { - CXML_AttrItem& item = GetAt(i); - if ((space.IsEmpty() || item.m_QSpaceName == space) && - item.m_AttrName == name) { + if (!m_pMap) + return nullptr; + + for (const auto& item : *m_pMap) { + if (item.Matches(space, name)) return &item.m_Value; - } } - return NULL; + return nullptr; } + void CXML_AttrMap::SetAt(const CFX_ByteStringC& space, const CFX_ByteStringC& name, const CFX_WideStringC& value) { - for (int i = 0; i < GetSize(); i++) { - CXML_AttrItem& item = GetAt(i); - if ((space.IsEmpty() || item.m_QSpaceName == space) && - item.m_AttrName == name) { + if (!m_pMap) + m_pMap.reset(new std::vector<CXML_AttrItem>); + + for (CXML_AttrItem& item : *m_pMap) { + if (item.Matches(space, name)) { item.m_Value = value; return; } } - if (!m_pMap) { - m_pMap = new CFX_ObjectArray<CXML_AttrItem>; - } - CXML_AttrItem* pItem = (CXML_AttrItem*)m_pMap->AddSpace(); - if (!pItem) { - return; - } - pItem->m_QSpaceName = space; - pItem->m_AttrName = name; - pItem->m_Value = value; -} -void CXML_AttrMap::RemoveAt(const CFX_ByteStringC& space, - const CFX_ByteStringC& name) { - if (!m_pMap) { - return; - } - for (int i = 0; i < m_pMap->GetSize(); i++) { - CXML_AttrItem& item = GetAt(i); - if ((space.IsEmpty() || item.m_QSpaceName == space) && - item.m_AttrName == name) { - m_pMap->RemoveAt(i); - return; - } - } + + m_pMap->push_back({space, name, value}); } + int CXML_AttrMap::GetSize() const { - return m_pMap ? m_pMap->GetSize() : 0; + return m_pMap ? pdfium::CollectionSize<int>(*m_pMap) : 0; } + CXML_AttrItem& CXML_AttrMap::GetAt(int index) const { return (*m_pMap)[index]; } -void CXML_AttrMap::RemoveAll() { - if (!m_pMap) { - return; - } - m_pMap->RemoveAll(); - delete m_pMap; - m_pMap = NULL; -} |