From 14768f3264a4cff8ca0096a27e41f1861b2c422b Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Wed, 13 Dec 2017 15:03:13 +0000 Subject: Get rid of CXML_AttrMap. BUG=pdfium:541 Change-Id: Id401af00e4cffebb49e187bf3a445439ce8c1082 Reviewed-on: https://pdfium-review.googlesource.com/21074 Commit-Queue: dsinclair Reviewed-by: dsinclair --- core/fxcrt/xml/cxml_attrmap.cpp | 50 ----------------------------------------- core/fxcrt/xml/cxml_attrmap.h | 33 --------------------------- core/fxcrt/xml/cxml_element.cpp | 31 +++++++++++++++++-------- core/fxcrt/xml/cxml_element.h | 13 ++++++----- 4 files changed, 30 insertions(+), 97 deletions(-) delete mode 100644 core/fxcrt/xml/cxml_attrmap.cpp delete mode 100644 core/fxcrt/xml/cxml_attrmap.h (limited to 'core/fxcrt') diff --git a/core/fxcrt/xml/cxml_attrmap.cpp b/core/fxcrt/xml/cxml_attrmap.cpp deleted file mode 100644 index 733bbeaa71..0000000000 --- a/core/fxcrt/xml/cxml_attrmap.cpp +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright 2017 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "core/fxcrt/xml/cxml_attrmap.h" - -#include "third_party/base/ptr_util.h" -#include "third_party/base/stl_util.h" - -CXML_AttrMap::CXML_AttrMap() {} - -CXML_AttrMap::~CXML_AttrMap() {} - -const WideString* CXML_AttrMap::Lookup(const ByteString& space, - const ByteString& name) const { - if (!m_pMap) - return nullptr; - - for (const auto& item : *m_pMap) { - if (item.Matches(space, name)) - return &item.m_Value; - } - return nullptr; -} - -void CXML_AttrMap::SetAt(const ByteString& space, - const ByteString& name, - const WideString& value) { - if (!m_pMap) - m_pMap = pdfium::MakeUnique>(); - - for (CXML_AttrItem& item : *m_pMap) { - if (item.Matches(space, name)) { - item.m_Value = value; - return; - } - } - - m_pMap->push_back({space, name, WideString(value)}); -} - -int CXML_AttrMap::GetSize() const { - return m_pMap ? pdfium::CollectionSize(*m_pMap) : 0; -} - -CXML_AttrItem& CXML_AttrMap::GetAt(int index) const { - return (*m_pMap)[index]; -} diff --git a/core/fxcrt/xml/cxml_attrmap.h b/core/fxcrt/xml/cxml_attrmap.h deleted file mode 100644 index a09522b53c..0000000000 --- a/core/fxcrt/xml/cxml_attrmap.h +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2017 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef CORE_FXCRT_XML_CXML_ATTRMAP_H_ -#define CORE_FXCRT_XML_CXML_ATTRMAP_H_ - -#include -#include - -#include "core/fxcrt/fx_string.h" -#include "core/fxcrt/xml/cxml_attritem.h" - -class CXML_AttrMap { - public: - CXML_AttrMap(); - ~CXML_AttrMap(); - - const WideString* Lookup(const ByteString& space, - const ByteString& name) const; - int GetSize() const; - CXML_AttrItem& GetAt(int index) const; - - void SetAt(const ByteString& space, - const ByteString& name, - const WideString& value); - - std::unique_ptr> m_pMap; -}; - -#endif // CORE_FXCRT_XML_CXML_ATTRMAP_H_ diff --git a/core/fxcrt/xml/cxml_element.cpp b/core/fxcrt/xml/cxml_element.cpp index ad9859e2c6..1d42e8eac3 100644 --- a/core/fxcrt/xml/cxml_element.cpp +++ b/core/fxcrt/xml/cxml_element.cpp @@ -61,9 +61,9 @@ ByteString CXML_Element::GetNamespaceURI(const ByteString& qName) const { do { const WideString* pwsSpace; if (qName.IsEmpty()) - pwsSpace = pElement->m_AttrMap.Lookup("", "xmlns"); + pwsSpace = pElement->Lookup("", "xmlns"); else - pwsSpace = pElement->m_AttrMap.Lookup("xmlns", qName); + pwsSpace = pElement->Lookup("xmlns", qName); if (pwsSpace) return pwsSpace->UTF8Encode(); @@ -76,10 +76,10 @@ void CXML_Element::GetAttrByIndex(size_t index, ByteString* space, ByteString* name, WideString* value) const { - if (index >= static_cast(m_AttrMap.GetSize())) + if (index >= m_AttrMap.size()) return; - CXML_AttrItem& item = m_AttrMap.GetAt(index); + const CXML_AttrItem& item = m_AttrMap[index]; *space = item.m_QSpaceName; *name = item.m_AttrName; *value = item.m_Value; @@ -91,8 +91,7 @@ WideString CXML_Element::GetAttrValue(const ByteStringView& name) const { SplitQualifiedName(name, &bsSpace, &bsName); WideString attr; - const WideString* pValue = - m_AttrMap.Lookup(ByteString(bsSpace), ByteString(bsName)); + const WideString* pValue = Lookup(ByteString(bsSpace), ByteString(bsName)); if (pValue) attr = *pValue; return attr; @@ -103,8 +102,7 @@ int CXML_Element::GetAttrInteger(const ByteStringView& name) const { ByteStringView bsName; SplitQualifiedName(name, &bsSpace, &bsName); - const WideString* pwsValue = - m_AttrMap.Lookup(ByteString(bsSpace), ByteString(bsName)); + const WideString* pwsValue = Lookup(ByteString(bsSpace), ByteString(bsName)); return pwsValue ? pwsValue->GetInteger() : 0; } @@ -140,7 +138,13 @@ CXML_Element* CXML_Element::GetElement(const ByteStringView& space, void CXML_Element::SetAttribute(const ByteString& space, const ByteString& name, const WideString& value) { - m_AttrMap.SetAt(space, name, value); + for (CXML_AttrItem& item : m_AttrMap) { + if (item.Matches(space, name)) { + item.m_Value = value; + return; + } + } + m_AttrMap.push_back({space, name, WideString(value)}); } // static @@ -150,3 +154,12 @@ bool CXML_Element::MatchesElement(const CXML_Element* pKid, return pKid && pKid->m_TagName == tag && (space.IsEmpty() || pKid->m_QSpaceName == space); } + +const WideString* CXML_Element::Lookup(const ByteString& space, + const ByteString& name) const { + for (const CXML_AttrItem& item : m_AttrMap) { + if (item.Matches(space, name)) + return &item.m_Value; + } + return nullptr; +} diff --git a/core/fxcrt/xml/cxml_element.h b/core/fxcrt/xml/cxml_element.h index 038fa648d2..d3049d77a4 100644 --- a/core/fxcrt/xml/cxml_element.h +++ b/core/fxcrt/xml/cxml_element.h @@ -11,7 +11,7 @@ #include #include -#include "core/fxcrt/xml/cxml_attrmap.h" +#include "core/fxcrt/xml/cxml_attritem.h" #include "core/fxcrt/xml/cxml_object.h" class CXML_Element : public CXML_Object { @@ -30,7 +30,7 @@ class CXML_Element : public CXML_Object { ByteString GetTagName() const; ByteString GetNamespaceURI(const ByteString& qName) const; const CXML_Element* GetParent() const { return m_pParent.Get(); } - size_t CountAttrs() const { return m_AttrMap.GetSize(); } + size_t CountAttrs() const { return m_AttrMap.size(); } void GetAttrByIndex(size_t index, ByteString* space, ByteString* name, @@ -60,10 +60,13 @@ class CXML_Element : public CXML_Object { const ByteStringView& space, const ByteStringView& tag); + const WideString* Lookup(const ByteString& space, + const ByteString& name) const; + UnownedPtr const m_pParent; - ByteString m_QSpaceName; - ByteString m_TagName; - CXML_AttrMap m_AttrMap; + const ByteString m_QSpaceName; + const ByteString m_TagName; + std::vector m_AttrMap; std::vector> m_Children; }; -- cgit v1.2.3