Many fixes for MString, ZString.

This commit is contained in:
Brad Arant committed 2022-08-23 09:30:56 -07:00
1 parent d0d5172afa
commit 2a349c6ceb
9 files changed
+65 -34

No files matched your search

+20 -8
View File
@@ -45,14 +45,20 @@ namespace coreutils {
// Log(LOG_DEBUG_2) << "ZString Copy Constructor: ";
}
ZString::ZString(std::string data) {
ZString::ZString(std::string &data) {
this->data = (char *)data.c_str();
length = data.length();
cursor = (char *)data.c_str();
}
// ZString::ZString(std::string data) {
// this->data = (char *)data.c_str();
// length = data.length();
// cursor = (char *)data.c_str();
// }
ZString::~ZString() {
if(cdata)
if(cdata != NULL)
free(cdata);
}
@@ -64,10 +70,16 @@ namespace coreutils {
return (strncmp(data, valuex.data, valuex.length <= length ? valuex.length : length) > 0);
}
bool ZString::operator==(const ZString &valuex) const {
bool ZString::operator==(const ZString &valuex) {
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);
}
@@ -105,14 +117,14 @@ namespace coreutils {
}
void ZString::push() {
stack.push(cursor);
stack.push(cursor);
}
void ZString::pop() {
cursor = stack.top();
stack.pop();
stack.pop();
}
std::string ZString::str() {
return std::string(data, length);
}
@@ -126,7 +138,7 @@ namespace coreutils {
strncpy(cdata, data, length);
cdata[length] = '\0';
return cdata;
}
}
ZString ZString::substring(int start) {
char *end = data + length;
@@ -167,7 +179,7 @@ namespace coreutils {
}
}
list.push_back(ZString(cursor, pos - cursor));
cursor = pos;
cursor = data;
return list;
}