Fix some nits in CXML_Element.

Move FX_XML_SplitQualifiedName() out of CXML_Parser, and add
CXML_Element::MatchesElement().
Change-Id: I34adc6f3b19e745ae33db0edf65184346cc1c13f
Reviewed-on: https://pdfium-review.googlesource.com/21073
Commit-Queue: dsinclair <dsinclair@chromium.org>
Reviewed-by: dsinclair <dsinclair@chromium.org>
diff --git a/core/fxcrt/xml/cxml_element.cpp b/core/fxcrt/xml/cxml_element.cpp
index f11fd1f..ad9859e 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::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 @@
 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 @@
 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 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 @@
                                        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 @@
                                 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 db9a214..038fa64 100644
--- a/core/fxcrt/xml/cxml_element.h
+++ b/core/fxcrt/xml/cxml_element.h
@@ -56,6 +56,10 @@
                     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 062b5be..76463bb 100644
--- a/core/fxcrt/xml/cxml_parser.cpp
+++ b/core/fxcrt/xml/cxml_parser.cpp
@@ -78,21 +78,6 @@
 
 }  // 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 ee5a1b6..04e5af5 100644
--- a/core/fxcrt/xml/cxml_parser.h
+++ b/core/fxcrt/xml/cxml_parser.h
@@ -54,8 +54,4 @@
   size_t m_dwIndex;
 };
 
-void FX_XML_SplitQualifiedName(const ByteStringView& bsFullName,
-                               ByteStringView& bsSpace,
-                               ByteStringView& bsName);
-
 #endif  // CORE_FXCRT_XML_CXML_PARSER_H_