summaryrefslogtreecommitdiff
path: root/AK/StringView.h
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-08-15 14:07:23 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-08-15 14:09:27 +0200
commit2349dc1a21a9f82943532214f4e1189af1d33c16 (patch)
treee268af52fcb28b7565ab378e8700c6822eeb8b29 /AK/StringView.h
parent77737be7b3b8a6d5a9000997ec58a2d507817b6f (diff)
downloadserenity-2349dc1a21a9f82943532214f4e1189af1d33c16.zip
StringView: Add StringView::operator==(StringView)
Previously we'd implicitly convert the second StringView to a String when comparing two StringViews, which is obviously not what we wanted.
Diffstat (limited to 'AK/StringView.h')
-rw-r--r--AK/StringView.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/AK/StringView.h b/AK/StringView.h
index 7d5d50a99f..7fceb76885 100644
--- a/AK/StringView.h
+++ b/AK/StringView.h
@@ -83,6 +83,22 @@ public:
bool operator==(const String&) const;
+ bool operator==(const StringView& other) const
+ {
+ if (is_null())
+ return other.is_null();
+ if (other.is_null())
+ return false;
+ if (length() != other.length())
+ return false;
+ return !memcmp(m_characters, other.m_characters, m_length);
+ }
+
+ bool operator!=(const StringView& other) const
+ {
+ return !(*this == other);
+ }
+
private:
friend class String;
const StringImpl* m_impl { nullptr };