Fixed == operator for empty string comparison.
This commit is contained in:
parent
f6e5e60e5b
commit
beb3673241
@ -38,7 +38,13 @@ namespace coreutils {
|
|||||||
cursor = this->data;
|
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());
|
setSize(zstring.getLength());
|
||||||
memcpy(data, zstring.getData(), zstring.getLength());
|
memcpy(data, zstring.getData(), zstring.getLength());
|
||||||
cursor = data;
|
cursor = data;
|
||||||
|
@ -6,8 +6,7 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
|
|
||||||
namespace coreutils
|
namespace coreutils {
|
||||||
{
|
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Use the MString object when you need a permanent backing store on the heap
|
/// 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(const unsigned char *data, size_t length);
|
||||||
|
|
||||||
MString (ZString zstring);
|
// MString (ZString zstring);
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Consructor providing a copy of a ZString.
|
/// Consructor providing a copy of a ZString.
|
||||||
///
|
///
|
||||||
|
|
||||||
|
MString (ZString &zstring);
|
||||||
|
MString (const ZString &zstring);
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Consructor providing a copy of a ZString.
|
/// Consructor providing a copy of a ZString.
|
||||||
///
|
///
|
||||||
|
@ -68,6 +68,8 @@ namespace coreutils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool ZString::operator==(const ZString &valuex) {
|
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);
|
return (strncmp(data, valuex.data, valuex.length <= length ? valuex.length : length) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -348,11 +350,11 @@ namespace coreutils {
|
|||||||
return ZString(temp, size);
|
return ZString(temp, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *ZString::getData() {
|
char *ZString::getData() const {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *ZString::getCursor() {
|
char *ZString::getCursor() const {
|
||||||
return cursor;
|
return cursor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -362,7 +364,7 @@ namespace coreutils {
|
|||||||
this->cursor = cursor;
|
this->cursor = cursor;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ZString::getLength() {
|
size_t ZString::getLength() const {
|
||||||
return length - (cursor - data);
|
return length - (cursor - data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -311,13 +311,13 @@ namespace coreutils {
|
|||||||
/// the number of bytes specified by size.
|
/// 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.
|
/// 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
|
/// Set this ZString to have the same data space as the ZString pointer
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
g++ -o zstring_test zstring_test.cpp -I.. -L.. -lCoreUtils
|
g++ -g -o zstring_test zstring_test.cpp -I.. -L.. -lCoreUtils
|
||||||
g++ -o mstring_test mstring_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
|
#g++ -o jstring_test jstring_test.cpp -I.. -L.. -lCoreUtils
|
||||||
|
Binary file not shown.
Binary file not shown.
@ -6,8 +6,9 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
// Test comparison operations.
|
// Test comparison operations.
|
||||||
|
|
||||||
coreutils::ZString test1("");
|
coreutils::ZString test1("else");
|
||||||
std::cout << (test1 != ".") << std::endl;
|
std::cout << (test1 != ".") << std::endl;
|
||||||
|
std::cout << (test1 == "") << std::endl;
|
||||||
|
|
||||||
// Test constructors.
|
// Test constructors.
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user