summaryrefslogtreecommitdiff
path: root/core/fxcrt/xml/cxml_element.cpp
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2017-12-13 15:03:13 +0000
committerChromium commit bot <commit-bot@chromium.org>2017-12-13 15:03:13 +0000
commit14768f3264a4cff8ca0096a27e41f1861b2c422b (patch)
treea5cbe644752c817a037a0470880d1e1cea161000 /core/fxcrt/xml/cxml_element.cpp
parentad38ca5a030e17e48495e52457192914a749912b (diff)
downloadpdfium-14768f3264a4cff8ca0096a27e41f1861b2c422b.tar.xz
Get rid of CXML_AttrMap.
BUG=pdfium:541 Change-Id: Id401af00e4cffebb49e187bf3a445439ce8c1082 Reviewed-on: https://pdfium-review.googlesource.com/21074 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'core/fxcrt/xml/cxml_element.cpp')
-rw-r--r--core/fxcrt/xml/cxml_element.cpp31
1 files changed, 22 insertions, 9 deletions
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<size_t>(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;
+}