diff --git a/BAN/BAN/String.cpp b/BAN/BAN/String.cpp index c79360ed..9644f634 100644 --- a/BAN/BAN/String.cpp +++ b/BAN/BAN/String.cpp @@ -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 String::Resize(size_type size, char ch) { if (size < m_size) diff --git a/BAN/BAN/StringView.cpp b/BAN/BAN/StringView.cpp index 97295ab9..b86d78c7 100644 --- a/BAN/BAN/StringView.cpp +++ b/BAN/BAN/StringView.cpp @@ -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); diff --git a/BAN/include/BAN/String.h b/BAN/include/BAN/String.h index c37fe22b..371b10f4 100644 --- a/BAN/include/BAN/String.h +++ b/BAN/include/BAN/String.h @@ -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 Resize(size_type, char = '\0'); ErrorOr Reserve(size_type); diff --git a/BAN/include/BAN/StringView.h b/BAN/include/BAN/StringView.h index 2c92c339..0bc531a5 100644 --- a/BAN/include/BAN/StringView.h +++ b/BAN/include/BAN/StringView.h @@ -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;