1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 23:38:12 +00:00

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.
This commit is contained in:
Andreas Kling 2019-08-15 14:07:23 +02:00
parent 77737be7b3
commit 2349dc1a21
3 changed files with 55 additions and 1 deletions

View file

@ -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 };