From 0e714d5eb4fb6217f6782f790d3a56c0e60cc553 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Sun, 24 Dec 2023 13:36:46 +0200 Subject: [PATCH] BAN: Implement String::operator==(const String&) --- BAN/BAN/String.cpp | 10 ++++++++++ BAN/include/BAN/String.h | 1 + 2 files changed, 11 insertions(+) diff --git a/BAN/BAN/String.cpp b/BAN/BAN/String.cpp index 07dc2657..dfe9bc7b 100644 --- a/BAN/BAN/String.cpp +++ b/BAN/BAN/String.cpp @@ -134,6 +134,16 @@ namespace BAN data()[m_size] = '\0'; } + bool String::operator==(const String& str) const + { + if (size() != str.size()) + return false; + for (size_type i = 0; i < m_size; i++) + if (data()[i] != str.data()[i]) + return false; + return true; + } + bool String::operator==(StringView str) const { if (size() != str.size()) diff --git a/BAN/include/BAN/String.h b/BAN/include/BAN/String.h index 3eecccd8..a0c47171 100644 --- a/BAN/include/BAN/String.h +++ b/BAN/include/BAN/String.h @@ -55,6 +55,7 @@ namespace BAN char operator[](size_type index) const { ASSERT(index < m_size); return data()[index]; } char& operator[](size_type index) { ASSERT(index < m_size); return data()[index]; } + bool operator==(const String&) const; bool operator==(StringView) const; bool operator==(const char*) const;