From 191899fbb7c65cb6d7d86007ca6b0c188b64ab6e Mon Sep 17 00:00:00 2001 From: Brad Arant Date: Tue, 31 Aug 2021 17:59:24 -0700 Subject: [PATCH] Fixed equals on zstring when length mismatches occured. --- ZString.cpp | 18 +++++++++++++----- ZString.h | 17 +++++++++++------ 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/ZString.cpp b/ZString.cpp index 1454daa..7095f7b 100644 --- a/ZString.cpp +++ b/ZString.cpp @@ -36,7 +36,7 @@ namespace coreutils { data = zstring.data; length = zstring.length; cursor = zstring.cursor; - Log(LOG_DEBUG_2) << "ZSrting Copy Constructor: "; +// Log(LOG_DEBUG_2) << "ZSrting Copy Constructor: "; } std::vector &ZString::getList() { @@ -109,15 +109,23 @@ namespace coreutils { ZString &ZString::operator[](int index) { return list[index]; } - + bool ZString::eod() { return cursor >= data + length; } - + bool ZString::equals(const char *value) { + if(strlen(value) != length) + return false; return strncmp(data, value, length) == 0; } - + + bool ZString::equals(char *value) { + if(strlen(value) != length) + return false; + return strncmp(data, value, length) == 0; + } + bool ZString::equals(ZString &zstring) { if(zstring.getLength() != getLength()) return false; @@ -127,7 +135,7 @@ namespace coreutils { bool ZString::equals(std::string &string) { return string == std::string(data, length); } - + bool ZString::ifNext(const char *value) { bool test = (strncmp(cursor, value, strlen(value)) == 0); if(test) diff --git a/ZString.h b/ZString.h index 85bb20b..bb92696 100644 --- a/ZString.h +++ b/ZString.h @@ -58,7 +58,6 @@ namespace coreutils { friend std::ostream& operator<<(std::ostream& os, const ZString& zstring); friend std::ostream& operator<<(std::ostream& os, const std::string& string); - friend std::ostream& operator+(std::ostream& os, const ZString& zstring); /// @@ -131,19 +130,25 @@ namespace coreutils { /// /// /// - + bool equals(const char *value); - + /// /// /// - + + bool equals(char *value); + + /// + /// + /// + bool equals(ZString &zstring); - + /// /// /// - + bool equals(std::string &string); ///