BAN: overloaded operator== for more types
This commit is contained in:
parent
fd6e0ed0f7
commit
5345b6b8c3
|
@ -134,6 +134,20 @@ namespace BAN
|
|||
return memcmp(m_data, other.m_data, m_size) == 0;
|
||||
}
|
||||
|
||||
bool String::operator==(StringView other) const
|
||||
{
|
||||
if (m_size != other.Size())
|
||||
return false;
|
||||
return memcmp(m_data, other.Data(), m_size) == 0;
|
||||
}
|
||||
|
||||
bool String::operator==(const char* other) const
|
||||
{
|
||||
if (m_size != strlen(other))
|
||||
return false;
|
||||
return memcmp(m_data, other, m_size) == 0;
|
||||
}
|
||||
|
||||
ErrorOr<void> String::Resize(size_type size, char ch)
|
||||
{
|
||||
if (size < m_size)
|
||||
|
|
|
@ -29,13 +29,27 @@ namespace BAN
|
|||
return m_data[index];
|
||||
}
|
||||
|
||||
bool StringView::operator==(const StringView& other) const
|
||||
bool StringView::operator==(const String& other) const
|
||||
{
|
||||
if (m_size != other.Size())
|
||||
return false;
|
||||
return memcmp(m_data, other.Data(), m_size) == 0;
|
||||
}
|
||||
|
||||
bool StringView::operator==(StringView other) const
|
||||
{
|
||||
if (m_size != other.m_size)
|
||||
return false;
|
||||
return memcmp(m_data, other.m_data, m_size) == 0;
|
||||
}
|
||||
|
||||
bool StringView::operator==(const char* other) const
|
||||
{
|
||||
if (m_size != strlen(other))
|
||||
return false;
|
||||
return memcmp(m_data, other, m_size) == 0;
|
||||
}
|
||||
|
||||
StringView StringView::Substring(size_type index, size_type len) const
|
||||
{
|
||||
assert(index <= m_size);
|
||||
|
|
|
@ -37,6 +37,8 @@ namespace BAN
|
|||
char& operator[](size_type);
|
||||
|
||||
bool operator==(const String&) const;
|
||||
bool operator==(StringView) const;
|
||||
bool operator==(const char*) const;
|
||||
|
||||
ErrorOr<void> Resize(size_type, char = '\0');
|
||||
ErrorOr<void> Reserve(size_type);
|
||||
|
|
|
@ -18,7 +18,9 @@ namespace BAN
|
|||
|
||||
char operator[](size_type) const;
|
||||
|
||||
bool operator==(const StringView&) const;
|
||||
bool operator==(const String&) const;
|
||||
bool operator==(StringView) const;
|
||||
bool operator==(const char*) const;
|
||||
|
||||
StringView Substring(size_type, size_type = -1) const;
|
||||
|
||||
|
|
Loading…
Reference in New Issue