Fixed erroneous operator== on ZString.

This commit is contained in:
Brad Arant 2024-10-16 11:37:18 -07:00
parent 34e2ca0566
commit d0239074a4
3 changed files with 6 additions and 14 deletions

View File

@ -104,22 +104,12 @@ namespace coreutils {
return (strncmp(data, valuex.data, valuex.length <= length ? valuex.length : length) > 0);
}
bool ZString::operator==(const ZString &valuex) {
if((valuex.getLength() == 0) && (length != 0))
return false;
bool ZString::operator==(const ZString valuex) {
if(valuex.getLength() != length)
return false;
return (strncmp(data, valuex.data, valuex.length <= length ? valuex.length : length) == 0);
}
// bool ZString::operator==(std::string value) {
// if(value.length() != length)
// return false;
// return (strncmp(data, value.c_str(), length) == 0);
// }
// bool ZString::operator==(const char *valuex) const {
// return (strncmp(data, valuex, length) == 0);
// }
bool ZString::operator!=(const ZString &valuex) const {
// if(length != valuex.getLength())
// return false;

View File

@ -114,7 +114,7 @@ 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==(const ZString valuex);
bool operator!=(const ZString &valuex) const;
bool operator!=(const char *valuex) const;

View File

@ -105,5 +105,7 @@ int main(int argc, char **argv) {
std::cout << "Null assignment" << std::endl;
coreutils::ZString test20(NULL);
std::cout << "[" << test20 << "]" << std::endl;
std::cout << "Comparisons with null value: " << (test20 == "true") << std::endl;
}