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
commit 2349dc1a21
Notes: sideshowbarker 2024-07-19 12:40:43 +09:00
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 };