diff --git a/MString.cpp b/MString.cpp index 4b48dd5..d645ccd 100644 --- a/MString.cpp +++ b/MString.cpp @@ -38,12 +38,18 @@ namespace coreutils { cursor = this->data; } - MString::MString(ZString zstring) { + MString::MString(const ZString &zstring) { setSize(zstring.getLength()); memcpy(data, zstring.getData(), zstring.getLength()); cursor = data; } - + + MString::MString(ZString &zstring) { + setSize(zstring.getLength()); + memcpy(data, zstring.getData(), zstring.getLength()); + cursor = data; + } + MString::MString(const MString &mstring) { setSize(mstring.length); memcpy(data, mstring.data, mstring.length); diff --git a/MString.h b/MString.h index 7413744..70b8cdb 100644 --- a/MString.h +++ b/MString.h @@ -6,8 +6,7 @@ #include #include -namespace coreutils -{ +namespace coreutils { /// /// Use the MString object when you need a permanent backing store on the heap @@ -42,12 +41,15 @@ namespace coreutils MString(const unsigned char *data, size_t length); - MString (ZString zstring); +// MString (ZString zstring); /// /// Consructor providing a copy of a ZString. /// + MString (ZString &zstring); + MString (const ZString &zstring); + /// /// Consructor providing a copy of a ZString. /// diff --git a/ZString.cpp b/ZString.cpp index 355b87f..c17c812 100644 --- a/ZString.cpp +++ b/ZString.cpp @@ -68,6 +68,8 @@ namespace coreutils { } bool ZString::operator==(const ZString &valuex) { + if((valuex.getLength() == 0) && (length != 0)) + return false; return (strncmp(data, valuex.data, valuex.length <= length ? valuex.length : length) == 0); } @@ -348,11 +350,11 @@ namespace coreutils { return ZString(temp, size); } - char *ZString::getData() { + char *ZString::getData() const { return data; } - char *ZString::getCursor() { + char *ZString::getCursor() const { return cursor; } @@ -362,7 +364,7 @@ namespace coreutils { this->cursor = cursor; } - size_t ZString::getLength() { + size_t ZString::getLength() const { return length - (cursor - data); } diff --git a/ZString.h b/ZString.h index 62abfa5..830674f 100644 --- a/ZString.h +++ b/ZString.h @@ -311,13 +311,13 @@ namespace coreutils { /// the number of bytes specified by size. /// - char *getData(); + char *getData() const; /// /// /// - char *getCursor(); + char *getCursor() const; /// /// @@ -329,7 +329,7 @@ namespace coreutils { /// Return the length of the ZString. /// - size_t getLength(); + size_t getLength() const; /// /// Set this ZString to have the same data space as the ZString pointer diff --git a/testing/compile b/testing/compile index af391cf..12cdd09 100755 --- a/testing/compile +++ b/testing/compile @@ -1,4 +1,4 @@ #!/bin/bash -g++ -o zstring_test zstring_test.cpp -I.. -L.. -lCoreUtils -g++ -o mstring_test mstring_test.cpp -I.. -L.. -lCoreUtils +g++ -g -o zstring_test zstring_test.cpp -I.. -L.. -lCoreUtils +g++ -g -o mstring_test mstring_test.cpp -I.. -L.. -lCoreUtils #g++ -o jstring_test jstring_test.cpp -I.. -L.. -lCoreUtils diff --git a/testing/mstring_test b/testing/mstring_test index 4a1eda2..abdf6a1 100755 Binary files a/testing/mstring_test and b/testing/mstring_test differ diff --git a/testing/zstring_test b/testing/zstring_test index 7d95339..065d9ae 100755 Binary files a/testing/zstring_test and b/testing/zstring_test differ diff --git a/testing/zstring_test.cpp b/testing/zstring_test.cpp index 56ac33a..c075315 100644 --- a/testing/zstring_test.cpp +++ b/testing/zstring_test.cpp @@ -6,8 +6,9 @@ int main(int argc, char **argv) { // Test comparison operations. - coreutils::ZString test1(""); + coreutils::ZString test1("else"); std::cout << (test1 != ".") << std::endl; + std::cout << (test1 == "") << std::endl; // Test constructors.