summaryrefslogtreecommitdiff
path: root/AK
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2021-07-21 16:38:12 -0400
committerLinus Groh <mail@linusgroh.de>2021-07-23 23:06:57 +0100
commit0e6375558dc60811a390ee014d76486ff28d8746 (patch)
tree6d2db1dfd5a585b39e750ddfbe8cce37f219697f /AK
parent47f6bb38a1bd3c39324d11b4eec1d8d8993658a2 (diff)
downloadserenity-0e6375558dc60811a390ee014d76486ff28d8746.zip
AK+LibRegex: Partially implement case insensitive UTF-16 comparison
This will work for ASCII code points. Unicode case folding will be needed for non-ASCII.
Diffstat (limited to 'AK')
-rw-r--r--AK/Utf16View.cpp17
-rw-r--r--AK/Utf16View.h2
2 files changed, 19 insertions, 0 deletions
diff --git a/AK/Utf16View.cpp b/AK/Utf16View.cpp
index a784822167..44a2a89f73 100644
--- a/AK/Utf16View.cpp
+++ b/AK/Utf16View.cpp
@@ -4,6 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
+#include <AK/CharacterTypes.h>
#include <AK/StringBuilder.h>
#include <AK/StringView.h>
#include <AK/Utf16View.h>
@@ -214,6 +215,22 @@ bool Utf16View::operator==(Utf16View const& other) const
return true;
}
+bool Utf16View::equals_ignoring_case(Utf16View const& other) const
+{
+ if (length_in_code_units() == 0)
+ return other.length_in_code_units() == 0;
+ if (length_in_code_units() != other.length_in_code_units())
+ return false;
+
+ for (size_t i = 0; i < length_in_code_units(); ++i) {
+ // FIXME: Handle non-ASCII case insensitive comparisons.
+ if (to_ascii_lowercase(m_code_units[i]) != to_ascii_lowercase(other.m_code_units[i]))
+ return false;
+ }
+
+ return true;
+}
+
Utf16CodePointIterator& Utf16CodePointIterator::operator++()
{
size_t code_units = length_in_code_units();
diff --git a/AK/Utf16View.h b/AK/Utf16View.h
index fc1c4ca87d..5f58c12036 100644
--- a/AK/Utf16View.h
+++ b/AK/Utf16View.h
@@ -104,6 +104,8 @@ public:
return validate(valid_code_units);
}
+ bool equals_ignoring_case(Utf16View const&) const;
+
private:
u16 const* begin_ptr() const { return m_code_units.data(); }
u16 const* end_ptr() const { return begin_ptr() + m_code_units.size(); }