diff --git a/AK/AKString.h b/AK/AKString.h index 8606d2934e4..0325f3831dd 100755 --- a/AK/AKString.h +++ b/AK/AKString.h @@ -133,6 +133,9 @@ public: bool operator==(const String&) const; bool operator!=(const String& other) const { return !(*this == other); } + bool operator==(const StringView&) const; + bool operator!=(const StringView& other) const { return !(*this == other); } + bool operator<(const String&) const; bool operator<(const char*) const; bool operator>=(const String& other) const { return !(*this < other); } diff --git a/AK/String.cpp b/AK/String.cpp index 4f8d2302591..40513aa6db8 100644 --- a/AK/String.cpp +++ b/AK/String.cpp @@ -19,6 +19,20 @@ bool String::operator==(const String& other) const return !memcmp(characters(), other.characters(), length()); } +bool String::operator==(const StringView& other) const +{ + if (!m_impl) + return !other.m_characters; + + if (!other.m_characters) + return false; + + if (length() != other.length()) + return false; + + return !memcmp(characters(), other.characters_without_null_termination(), length()); +} + bool String::operator<(const String& other) const { if (!m_impl)