aboutsummaryrefslogtreecommitdiff
path: root/include/cru
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2022-01-23 21:07:03 +0800
committercrupest <crupest@outlook.com>2022-01-23 21:07:03 +0800
commitda9bdf2baced1ff51350c98047b7ade68fcae930 (patch)
treec51b9c8538c82b19d142eb1340e6dac0e88ff4e4 /include/cru
parent13860c88910c00478abe3001cc80125e76767381 (diff)
downloadcru-da9bdf2baced1ff51350c98047b7ade68fcae930.tar.gz
cru-da9bdf2baced1ff51350c98047b7ade68fcae930.tar.bz2
cru-da9bdf2baced1ff51350c98047b7ade68fcae930.zip
...
Diffstat (limited to 'include/cru')
-rw-r--r--include/cru/common/String.hpp2
-rw-r--r--include/cru/xml/XmlNode.hpp14
2 files changed, 16 insertions, 0 deletions
diff --git a/include/cru/common/String.hpp b/include/cru/common/String.hpp
index 1d660623..5891e929 100644
--- a/include/cru/common/String.hpp
+++ b/include/cru/common/String.hpp
@@ -225,6 +225,7 @@ class CRU_BASE_API String {
std::string ToUtf8() const;
int Compare(const String& other) const;
+ int CaseInsensitiveCompare(const String& other) const;
private:
static char16_t kEmptyBuffer[1];
@@ -308,6 +309,7 @@ class CRU_BASE_API StringView {
public:
int Compare(const StringView& other) const;
+ int CaseInsensitiveCompare(const StringView& other) const;
String ToString() const { return String(ptr_, size_); }
diff --git a/include/cru/xml/XmlNode.hpp b/include/cru/xml/XmlNode.hpp
index 71753410..c9e538c0 100644
--- a/include/cru/xml/XmlNode.hpp
+++ b/include/cru/xml/XmlNode.hpp
@@ -91,6 +91,9 @@ class CRU_XML_API XmlElementNode : public XmlNode {
Index GetChildCount() const { return children_.size(); }
String GetAttribute(const String& key) const { return attributes_.at(key); }
+ String GetAttributeCaseInsensitive(const String& key) const {
+ return *GetOptionalAttributeCaseInsensitive(key);
+ }
std::optional<String> GetOptionalAttribute(const String& key) const {
auto it = attributes_.find(key);
if (it == attributes_.end()) {
@@ -99,6 +102,17 @@ class CRU_XML_API XmlElementNode : public XmlNode {
return it->second;
}
+ std::optional<String> GetOptionalAttributeCaseInsensitive(
+ const String& key) const {
+ for (auto it = attributes_.begin(); it != attributes_.end(); ++it) {
+ if (it->first.CaseInsensitiveCompare(key) == 0) {
+ return it->second;
+ }
+ }
+
+ return std::nullopt;
+ }
+
XmlNode* GetChildAt(Index index) const { return children_[index]; }
void AddAttribute(String key, String value);