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);
|
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(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;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
22
MString.cpp
22
MString.cpp
@ -105,30 +105,30 @@ namespace coreutils {
|
|||||||
int len = strlen(value);
|
int len = strlen(value);
|
||||||
setSize(len + length);
|
setSize(len + length);
|
||||||
memcpy(data + temp, value, len);
|
memcpy(data + temp, value, len);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
MString& MString::operator<<(const int value) {
|
MString& MString::operator<<(const int value) {
|
||||||
std::stringstream temp;
|
std::stringstream temp;
|
||||||
temp << value;
|
temp << value;
|
||||||
*this << temp.str();
|
*this << temp.str();
|
||||||
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;
|
||||||
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<<(std::string value) {
|
MString& MString::operator<<(std::string value) {
|
||||||
@ -136,7 +136,7 @@ namespace coreutils {
|
|||||||
int len = length + value.length();
|
int len = length + value.length();
|
||||||
setSize(len);
|
setSize(len);
|
||||||
memcpy(data + temp, value.c_str(), value.length());
|
memcpy(data + temp, value.c_str(), value.length());
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
MString& MString::write(char ch) {
|
MString& MString::write(char ch) {
|
||||||
|
28
ZString.cpp
28
ZString.cpp
@ -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);
|
||||||
}
|
}
|
||||||
@ -105,14 +117,14 @@ namespace coreutils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ZString::push() {
|
void ZString::push() {
|
||||||
stack.push(cursor);
|
stack.push(cursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZString::pop() {
|
void ZString::pop() {
|
||||||
cursor = stack.top();
|
cursor = stack.top();
|
||||||
stack.pop();
|
stack.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ZString::str() {
|
std::string ZString::str() {
|
||||||
return std::string(data, length);
|
return std::string(data, length);
|
||||||
}
|
}
|
||||||
@ -126,7 +138,7 @@ namespace coreutils {
|
|||||||
strncpy(cdata, data, length);
|
strncpy(cdata, data, length);
|
||||||
cdata[length] = '\0';
|
cdata[length] = '\0';
|
||||||
return cdata;
|
return cdata;
|
||||||
}
|
}
|
||||||
|
|
||||||
ZString ZString::substring(int start) {
|
ZString ZString::substring(int start) {
|
||||||
char *end = data + length;
|
char *end = data + length;
|
||||||
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
31
ZString.h
31
ZString.h
@ -56,7 +56,7 @@ namespace coreutils {
|
|||||||
///
|
///
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
|
|
||||||
ZString(const char *data, size_t length);
|
ZString(const char *data, size_t length);
|
||||||
|
|
||||||
///
|
///
|
||||||
@ -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.
|
||||||
@ -90,15 +96,16 @@ 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) 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;
|
||||||
@ -165,9 +172,9 @@ namespace coreutils {
|
|||||||
///
|
///
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
|
|
||||||
ZString substring(int start, int len);
|
ZString substring(int start, int len);
|
||||||
|
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
@ -197,7 +204,7 @@ namespace coreutils {
|
|||||||
///
|
///
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
|
|
||||||
ZString getTokenExclude(std::string exclude);
|
ZString getTokenExclude(std::string exclude);
|
||||||
|
|
||||||
///
|
///
|
||||||
@ -252,13 +259,13 @@ namespace coreutils {
|
|||||||
///
|
///
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
|
|
||||||
bool ifNext(ZString &value);
|
bool ifNext(ZString &value);
|
||||||
|
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
|
|
||||||
int ifEqualsCount(ZString &comparator);
|
int ifEqualsCount(ZString &comparator);
|
||||||
|
|
||||||
///
|
///
|
||||||
@ -296,7 +303,7 @@ namespace coreutils {
|
|||||||
///
|
///
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
|
|
||||||
void setCursor(char *cursor);
|
void setCursor(char *cursor);
|
||||||
|
|
||||||
///
|
///
|
||||||
@ -323,7 +330,7 @@ namespace coreutils {
|
|||||||
///
|
///
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
|
|
||||||
ZString unparsed();
|
ZString unparsed();
|
||||||
|
|
||||||
///
|
///
|
||||||
|
Binary file not shown.
@ -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,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.
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user