summaryrefslogtreecommitdiff
path: root/AK/String.h
diff options
context:
space:
mode:
authorkleines Filmröllchen <filmroellchen@serenityos.org>2022-12-11 14:31:41 +0100
committerLinus Groh <mail@linusgroh.de>2022-12-11 16:05:23 +0000
commitca80353efedc0ececa0f68da74f75c3fdb1f1f3e (patch)
treef4dcd71434976557f057cbc9b8e874d367833130 /AK/String.h
parentad6a55e1f088f525b1bd2ee7e926fcafedead4c1 (diff)
downloadserenity-ca80353efedc0ececa0f68da74f75c3fdb1f1f3e.zip
AK: Add comparison operator
s p a c e s h i p o p e r a t o r Comparing UTF-8 can be done by simple byte lexicographic comparison per definition, so we just piggy-back on StringView's high-performance comparator.
Diffstat (limited to 'AK/String.h')
-rw-r--r--AK/String.h3
1 files changed, 3 insertions, 0 deletions
diff --git a/AK/String.h b/AK/String.h
index 1df4edac92..01c4c3cc1b 100644
--- a/AK/String.h
+++ b/AK/String.h
@@ -73,6 +73,9 @@ public:
[[nodiscard]] bool operator==(char const* cstring) const;
[[nodiscard]] bool operator!=(char const* cstring) const { return !(*this == cstring); }
+ // NOTE: UTF-8 is defined in a way that lexicographic ordering of code points is equivalent to lexicographic ordering of bytes.
+ [[nodiscard]] int operator<=>(String const& other) const { return this->bytes_as_string_view().compare(other.bytes_as_string_view()); }
+
[[nodiscard]] u32 hash() const;
template<Arithmetic T>