From c1fa39cd8c4e72ae60ab55d020fa7bff7eaaa10b Mon Sep 17 00:00:00 2001 From: Madeline Busig Date: Sun, 18 Aug 2024 23:51:22 -0700 Subject: [PATCH] Add string_view equal/not equal comparison operators --- include/mtl/string_view.hpp | 7 +++++++ src/string_view.cpp | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/include/mtl/string_view.hpp b/include/mtl/string_view.hpp index 0ef0e89..508e6fd 100644 --- a/include/mtl/string_view.hpp +++ b/include/mtl/string_view.hpp @@ -85,6 +85,13 @@ public: int32_t compare(size_t pos, size_t count, const string_view& str) const; int32_t compare(size_t pos1, size_t count1, const string_view& str, size_t pos2, size_t count2 = npos) const; + bool operator==(const string_view& rhs) const; + bool operator!=(const string_view& rhs) const; + bool operator<(const string_view& rhs) const; + bool operator<=(const string_view& rhs) const; + bool operator>(const string_view& rhs) const; + bool operator>=(const string_view& rhs) const; + friend bool operator==(const istring& lhs, const istring& rhs); friend bool operator!=(const istring& lhs, const istring& rhs); friend bool operator<(const istring& lhs, const istring& rhs); diff --git a/src/string_view.cpp b/src/string_view.cpp index 072ff70..a93069d 100644 --- a/src/string_view.cpp +++ b/src/string_view.cpp @@ -18,4 +18,11 @@ size_t string_view::copy(char* dest, size_t count, size_t pos) const { return count; } +bool string_view::operator==(const string_view& rhs) const { + return strcmp(m_str, rhs.m_str) == 0; +} +bool string_view::operator!=(const string_view& rhs) const { + return strcmp(m_str, rhs.m_str) != 0; +} + } // namespace mtl