Many fixes for MString, ZString.
This commit is contained in:
parent
d0d5172afa
commit
2a349c6ceb
5
File.cpp
5
File.cpp
@ -63,4 +63,9 @@ namespace coreutils {
|
||||
return std::string(buffer, size);
|
||||
}
|
||||
|
||||
coreutils::ZString & File::asZString() {
|
||||
zstring = ZString(buffer, size);
|
||||
return zstring;
|
||||
}
|
||||
|
||||
}
|
||||
|
3
File.h
3
File.h
@ -24,7 +24,7 @@ namespace coreutils {
|
||||
void write(std::string data);
|
||||
void write(coreutils::ZString &data);
|
||||
std::string asString();
|
||||
|
||||
coreutils::ZString& asZString();
|
||||
char *buffer;
|
||||
size_t size;
|
||||
|
||||
@ -33,6 +33,7 @@ namespace coreutils {
|
||||
private:
|
||||
void open(std::string fileName, int mode, int authority);
|
||||
int fd;
|
||||
coreutils::ZString zstring;
|
||||
|
||||
};
|
||||
|
||||
|
14
MString.cpp
14
MString.cpp
@ -115,13 +115,13 @@ namespace coreutils {
|
||||
return *this;
|
||||
}
|
||||
|
||||
// MString& MString::operator<<(coreutils::ZString &zstring) {
|
||||
// int temp = length;
|
||||
// int len = length + zstring.getLength();
|
||||
// setSize(len);
|
||||
// memcpy(data + temp, zstring.getData(), zstring.getLength());
|
||||
// return *this;
|
||||
// }
|
||||
// MString& MString::operator<<(coreutils::ZString &zstring) {
|
||||
// int temp = length;
|
||||
// int len = length + zstring.getLength();
|
||||
// setSize(len);
|
||||
// memcpy(data + temp, zstring.getData(), zstring.getLength());
|
||||
// return *this;
|
||||
// }
|
||||
|
||||
MString& MString::operator<<(coreutils::ZString zstring) {
|
||||
int temp = length;
|
||||
|
20
ZString.cpp
20
ZString.cpp
@ -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);
|
||||
}
|
||||
@ -167,7 +179,7 @@ namespace coreutils {
|
||||
}
|
||||
}
|
||||
list.push_back(ZString(cursor, pos - cursor));
|
||||
cursor = pos;
|
||||
cursor = data;
|
||||
return list;
|
||||
}
|
||||
|
||||
|
11
ZString.h
11
ZString.h
@ -69,7 +69,13 @@ namespace coreutils {
|
||||
/// Consructor from a string.
|
||||
///
|
||||
|
||||
ZString(std::string string);
|
||||
ZString(std::string &string);
|
||||
|
||||
///
|
||||
/// Consructor from a string.
|
||||
///
|
||||
|
||||
// ZString(std::string string);
|
||||
|
||||
///
|
||||
/// 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);
|
||||
bool operator==(std::string value);
|
||||
bool operator==(const char *valuex) const;
|
||||
bool operator!=(const ZString &valuex) const;
|
||||
bool operator!=(const char *valuex) const;
|
||||
|
Binary file not shown.
@ -17,8 +17,9 @@ int main(int argc, char **argv) {
|
||||
test3 = 'a';
|
||||
std::cout << "char operator=: [" << test3 << "]." << std::endl;
|
||||
|
||||
coreutils::ZString test7("zstring data");
|
||||
coreutils::MString test4;
|
||||
test4 << "this is a test.";
|
||||
test4 << "this is a test." << test7;
|
||||
std::cout << "char* operator<<: [" << test4 << "]." << std::endl;
|
||||
test4 << "another test " << 75;
|
||||
std::cout << "char* operator<<: [" << test4 << "]." << std::endl;
|
||||
|
Binary file not shown.
@ -6,7 +6,12 @@ int main(int argc, char **argv) {
|
||||
// Test comparison operations.
|
||||
|
||||
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.
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user