From 9d62a09140f969b68a79162261b250c4c44d76da Mon Sep 17 00:00:00 2001 From: Brad Arant Date: Mon, 30 Sep 2024 16:50:17 -0700 Subject: [PATCH] Added >= and <= operators to ZString. --- ZString.cpp | 10 ++++++++++ ZString.h | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/ZString.cpp b/ZString.cpp index 3b4c77b..5002c64 100644 --- a/ZString.cpp +++ b/ZString.cpp @@ -80,6 +80,16 @@ namespace coreutils { return 0; } + // TODO: Fix the following comparison operators to handle the length problem appropriately. + + bool ZString::operator<=(const ZString &valuex) const { + return (strncmp(data, valuex.data, valuex.length <= length ? valuex.length : length) <= 0); + } + + bool ZString::operator>=(const ZString &valuex) const { + return (strncmp(data, valuex.data, valuex.length <= length ? valuex.length : length) >= 0); + } + bool ZString::operator>(const ZString &valuex) const { return (strncmp(data, valuex.data, valuex.length <= length ? valuex.length : length) > 0); } diff --git a/ZString.h b/ZString.h index e08e0a7..258f574 100644 --- a/ZString.h +++ b/ZString.h @@ -112,9 +112,9 @@ namespace coreutils { /// bool operator>(const ZString &valuex) const; + bool operator<=(const ZString &valuex) const; + bool operator>=(const ZString &valuex) const; bool operator==(const ZString &valuex); - // bool operator==(std::string value); - // bool operator==(const char *valuex) const; bool operator!=(const ZString &valuex) const; bool operator!=(const char *valuex) const;