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
+47 -16

No files matched your search

+5
View File
@@ -63,4 +63,9 @@ namespace coreutils {
return std::string(buffer, size); return std::string(buffer, size);
} }
coreutils::ZString & File::asZString() {
zstring = ZString(buffer, size);
return zstring;
}
} }
+2 -1
View File
@@ -24,7 +24,7 @@ namespace coreutils {
void write(std::string data); void write(std::string data);
void write(coreutils::ZString &data); void write(coreutils::ZString &data);
std::string asString(); std::string asString();
coreutils::ZString& asZString();
char *buffer; char *buffer;
size_t size; size_t size;
@@ -33,6 +33,7 @@ namespace coreutils {
private: private:
void open(std::string fileName, int mode, int authority); void open(std::string fileName, int mode, int authority);
int fd; int fd;
coreutils::ZString zstring;
}; };
+7 -7
View File
@@ -115,13 +115,13 @@ namespace coreutils {
return *this; return *this;
} }
// MString& MString::operator<<(coreutils::ZString &zstring) { // MString& MString::operator<<(coreutils::ZString &zstring) {
// int temp = length; // int temp = length;
// int len = length + zstring.getLength(); // int len = length + zstring.getLength();
// setSize(len); // setSize(len);
// memcpy(data + temp, zstring.getData(), zstring.getLength()); // memcpy(data + temp, zstring.getData(), zstring.getLength());
// return *this; // return *this;
// } // }
MString& MString::operator<<(coreutils::ZString zstring) { MString& MString::operator<<(coreutils::ZString zstring) {
int temp = length; int temp = length;
+16 -4
View File
@@ -45,14 +45,20 @@ namespace coreutils {
// Log(LOG_DEBUG_2) << "ZString Copy Constructor: "; // Log(LOG_DEBUG_2) << "ZString Copy Constructor: ";
} }
ZString::ZString(std::string data) { ZString::ZString(std::string &data) {
this->data = (char *)data.c_str(); this->data = (char *)data.c_str();
length = data.length(); length = data.length();
cursor = (char *)data.c_str(); 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() { ZString::~ZString() {
if(cdata) if(cdata != NULL)
free(cdata); free(cdata);
} }
@@ -64,10 +70,16 @@ namespace coreutils {
return (strncmp(data, valuex.data, valuex.length <= length ? valuex.length : length) > 0); 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); 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 { bool ZString::operator==(const char *valuex) const {
return (strncmp(data, valuex, length) == 0); return (strncmp(data, valuex, length) == 0);
} }
@@ -167,7 +179,7 @@ namespace coreutils {
} }
} }
list.push_back(ZString(cursor, pos - cursor)); list.push_back(ZString(cursor, pos - cursor));
cursor = pos; cursor = data;
return list; return list;
} }
+9 -2
View File
@@ -69,7 +69,13 @@ namespace coreutils {
/// Consructor from a string. /// Consructor from a string.
/// ///
ZString(std::string string); ZString(std::string &string);
///
/// Consructor from a string.
///
// ZString(std::string string);
/// ///
/// Destructor for the ZString. /// Destructor for the ZString.
@@ -98,7 +104,8 @@ 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==(std::string value);
bool operator==(const char *valuex) const; bool operator==(const char *valuex) const;
bool operator!=(const ZString &valuex) const; bool operator!=(const ZString &valuex) const;
bool operator!=(const char *valuex) const; bool operator!=(const char *valuex) const;
Binary file not shown.
+2 -1
View File
@@ -17,8 +17,9 @@ int main(int argc, char **argv) {
test3 = 'a'; test3 = 'a';
std::cout << "char operator=: [" << test3 << "]." << std::endl; std::cout << "char operator=: [" << test3 << "]." << std::endl;
coreutils::ZString test7("zstring data");
coreutils::MString test4; coreutils::MString test4;
test4 << "this is a test."; test4 << "this is a test." << test7;
std::cout << "char* operator<<: [" << test4 << "]." << std::endl; std::cout << "char* operator<<: [" << test4 << "]." << std::endl;
test4 << "another test " << 75; test4 << "another test " << 75;
std::cout << "char* operator<<: [" << test4 << "]." << std::endl; std::cout << "char* operator<<: [" << test4 << "]." << std::endl;
Binary file not shown.
+6 -1
View File
@@ -6,7 +6,12 @@ int main(int argc, char **argv) {
// Test comparison operations. // Test comparison operations.
coreutils::ZString test1(""); coreutils::ZString test1("");
std::cout << (test1 != "."); std::cout << (test1 != ".") << std::endl;
// Test constructors.
coreutils::ZString test3("1659979856.747021214|barant@barant");
std::cout << test3 << std::endl;
// Test split operations. // Test split operations.