From 78d444c2e58c12ec93b2d55aa275a04c59197e05 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Fri, 23 Jul 2021 21:29:17 -0500 Subject: [PATCH] [ox/std] Add comparison operators to String --- deps/ox/src/ox/std/string.hpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/deps/ox/src/ox/std/string.hpp b/deps/ox/src/ox/std/string.hpp index 951f4b6d..3dbb5d93 100644 --- a/deps/ox/src/ox/std/string.hpp +++ b/deps/ox/src/ox/std/string.hpp @@ -86,6 +86,14 @@ class BasicString { bool operator!=(const BasicString &other) const noexcept; + bool operator<(const BasicString &other) const noexcept; + + bool operator>(const BasicString &other) const noexcept; + + bool operator<=(const BasicString &other) const noexcept; + + bool operator>=(const BasicString &other) const noexcept; + char operator[](std::size_t i) const noexcept; char &operator[](std::size_t i) noexcept; @@ -350,6 +358,26 @@ bool BasicString::operator!=(const BasicString &other) const no return !operator==(other); } +template +bool BasicString::operator<(const BasicString &other) const noexcept { + return ox_strcmp(c_str(), other.c_str()) < 0; +} + +template +bool BasicString::operator>(const BasicString &other) const noexcept { + return ox_strcmp(c_str(), other.c_str()) > 0; +} + +template +bool BasicString::operator<=(const BasicString &other) const noexcept { + return ox_strcmp(c_str(), other.c_str()) < 1; +} + +template +bool BasicString::operator>=(const BasicString &other) const noexcept { + return ox_strcmp(c_str(), other.c_str()) > -1; +} + template char BasicString::operator[](std::size_t i) const noexcept { return m_buff[i];