summaryrefslogtreecommitdiff
path: root/core/fxcrt
diff options
context:
space:
mode:
Diffstat (limited to 'core/fxcrt')
-rw-r--r--core/fxcrt/xml/cxml_element.cpp44
-rw-r--r--core/fxcrt/xml/cxml_element.h4
-rw-r--r--core/fxcrt/xml/cxml_parser.cpp15
-rw-r--r--core/fxcrt/xml/cxml_parser.h4
4 files changed, 38 insertions, 29 deletions
diff --git a/core/fxcrt/xml/cxml_element.cpp b/core/fxcrt/xml/cxml_element.cpp
index f11fd1fe14..ad9859e2c6 100644
--- a/core/fxcrt/xml/cxml_element.cpp
+++ b/core/fxcrt/xml/cxml_element.cpp
@@ -9,6 +9,25 @@
#include "core/fxcrt/xml/cxml_content.h"
#include "core/fxcrt/xml/cxml_parser.h"
+namespace {
+
+void SplitQualifiedName(const ByteStringView& bsFullName,
+ ByteStringView* bsSpace,
+ ByteStringView* bsName) {
+ if (bsFullName.IsEmpty())
+ return;
+
+ auto iStart = bsFullName.Find(':');
+ if (iStart.has_value()) {
+ *bsSpace = bsFullName.Left(iStart.value());
+ *bsName = bsFullName.Right(bsFullName.GetLength() - (iStart.value() + 1));
+ } else {
+ *bsName = bsFullName;
+ }
+}
+
+} // namespace
+
// static
std::unique_ptr<CXML_Element> CXML_Element::Parse(const void* pBuffer,
size_t size) {
@@ -38,19 +57,19 @@ ByteString CXML_Element::GetTagName() const {
}
ByteString CXML_Element::GetNamespaceURI(const ByteString& qName) const {
- const WideString* pwsSpace;
const CXML_Element* pElement = this;
do {
+ const WideString* pwsSpace;
if (qName.IsEmpty())
pwsSpace = pElement->m_AttrMap.Lookup("", "xmlns");
else
pwsSpace = pElement->m_AttrMap.Lookup("xmlns", qName);
if (pwsSpace)
- break;
+ return pwsSpace->UTF8Encode();
pElement = pElement->GetParent();
} while (pElement);
- return pwsSpace ? pwsSpace->UTF8Encode() : ByteString();
+ return ByteString();
}
void CXML_Element::GetAttrByIndex(size_t index,
@@ -69,7 +88,7 @@ void CXML_Element::GetAttrByIndex(size_t index,
WideString CXML_Element::GetAttrValue(const ByteStringView& name) const {
ByteStringView bsSpace;
ByteStringView bsName;
- FX_XML_SplitQualifiedName(name, bsSpace, bsName);
+ SplitQualifiedName(name, &bsSpace, &bsName);
WideString attr;
const WideString* pValue =
@@ -82,7 +101,7 @@ WideString CXML_Element::GetAttrValue(const ByteStringView& name) const {
int CXML_Element::GetAttrInteger(const ByteStringView& name) const {
ByteStringView bsSpace;
ByteStringView bsName;
- FX_XML_SplitQualifiedName(name, bsSpace, bsName);
+ SplitQualifiedName(name, &bsSpace, &bsName);
const WideString* pwsValue =
m_AttrMap.Lookup(ByteString(bsSpace), ByteString(bsName));
@@ -94,10 +113,8 @@ size_t CXML_Element::CountElements(const ByteStringView& space,
size_t count = 0;
for (const auto& pChild : m_Children) {
const CXML_Element* pKid = pChild->AsElement();
- if (pKid && pKid->m_TagName == tag &&
- (space.IsEmpty() || pKid->m_QSpaceName == space)) {
+ if (MatchesElement(pKid, space, tag))
count++;
- }
}
return count;
}
@@ -111,8 +128,7 @@ CXML_Element* CXML_Element::GetElement(const ByteStringView& space,
size_t nth) const {
for (const auto& pChild : m_Children) {
CXML_Element* pKid = pChild->AsElement();
- if (pKid && pKid->m_TagName == tag &&
- (space.IsEmpty() || pKid->m_QSpaceName == space)) {
+ if (MatchesElement(pKid, space, tag)) {
if (nth == 0)
return pKid;
--nth;
@@ -126,3 +142,11 @@ void CXML_Element::SetAttribute(const ByteString& space,
const WideString& value) {
m_AttrMap.SetAt(space, name, value);
}
+
+// static
+bool CXML_Element::MatchesElement(const CXML_Element* pKid,
+ const ByteStringView& space,
+ const ByteStringView& tag) {
+ return pKid && pKid->m_TagName == tag &&
+ (space.IsEmpty() || pKid->m_QSpaceName == space);
+}
diff --git a/core/fxcrt/xml/cxml_element.h b/core/fxcrt/xml/cxml_element.h
index db9a214c17..038fa648d2 100644
--- a/core/fxcrt/xml/cxml_element.h
+++ b/core/fxcrt/xml/cxml_element.h
@@ -56,6 +56,10 @@ class CXML_Element : public CXML_Object {
const WideString& value);
private:
+ static bool MatchesElement(const CXML_Element* pKid,
+ const ByteStringView& space,
+ const ByteStringView& tag);
+
UnownedPtr<const CXML_Element> const m_pParent;
ByteString m_QSpaceName;
ByteString m_TagName;
diff --git a/core/fxcrt/xml/cxml_parser.cpp b/core/fxcrt/xml/cxml_parser.cpp
index 062b5bec07..76463bba23 100644
--- a/core/fxcrt/xml/cxml_parser.cpp
+++ b/core/fxcrt/xml/cxml_parser.cpp
@@ -78,21 +78,6 @@ bool g_FXCRT_XML_IsNameChar(uint8_t ch) {
} // namespace
-void FX_XML_SplitQualifiedName(const ByteStringView& bsFullName,
- ByteStringView& bsSpace,
- ByteStringView& bsName) {
- if (bsFullName.IsEmpty())
- return;
-
- auto iStart = bsFullName.Find(':');
- if (!iStart.has_value()) {
- bsName = bsFullName;
- } else {
- bsSpace = bsFullName.Left(iStart.value());
- bsName = bsFullName.Right(bsFullName.GetLength() - (iStart.value() + 1));
- }
-}
-
CXML_Parser::CXML_Parser()
: m_nOffset(0),
m_pBuffer(nullptr),
diff --git a/core/fxcrt/xml/cxml_parser.h b/core/fxcrt/xml/cxml_parser.h
index ee5a1b6e18..04e5af58e3 100644
--- a/core/fxcrt/xml/cxml_parser.h
+++ b/core/fxcrt/xml/cxml_parser.h
@@ -54,8 +54,4 @@ class CXML_Parser {
size_t m_dwIndex;
};
-void FX_XML_SplitQualifiedName(const ByteStringView& bsFullName,
- ByteStringView& bsSpace,
- ByteStringView& bsName);
-
#endif // CORE_FXCRT_XML_CXML_PARSER_H_