StringView: operator==(const char*) needs to stop when the view ends.

We were comparing past the end of the view, which was clearly not correct.
This commit is contained in:
Andreas Kling 2019-06-07 19:22:58 +02:00
parent f90d75e5b9
commit de9edb0169

View file

@ -38,8 +38,17 @@ public:
Vector<StringView> split_view(char) const;
unsigned to_uint(bool& ok) const;
bool operator==(const char* cstring) const { return !strcmp(m_characters, cstring); }
bool operator!=(const char* cstring) const { return strcmp(m_characters, cstring); }
bool operator==(const char* cstring) const
{
int other_length = strlen(cstring);
if (m_length != other_length)
return false;
return !memcmp(m_characters, cstring, m_length);
}
bool operator!=(const char* cstring) const
{
return !(*this == cstring);
}
bool operator==(const String&) const;