Merge up with master branch.

This commit is contained in:
Brad Arant 2022-07-28 18:52:30 -07:00
commit f8bc2df133
5 changed files with 68 additions and 35 deletions

View File

@ -36,6 +36,12 @@ namespace coreutils {
// Log(LOG_DEBUG_2) << "MString Copy Constructor: ";
}
MString::MString(ZString &zstring) {
setSize(zstring.getLength());
memcpy(data, zstring.getData(), zstring.getLength());
cursor = data;
}
MString::MString(std::string data) {
setSize(data.length());
memcpy(this->data, (char *)data.c_str(), data.length());
@ -61,6 +67,15 @@ namespace coreutils {
return *this;
}
MString& MString::operator=(coreutils::MString& value) {
if(*this == value)
return *this;
int len = length;
setSize(length + value.getLength());
memcpy(data + len, value.getData(), value.getLength());
return *this;
}
MString& MString::operator=(const char *value) {
int len = strlen(value);
setSize(len);
@ -106,17 +121,17 @@ namespace coreutils {
return *this;
}
int MString::write(char ch) {
MString& MString::write(char ch) {
setSize(length + 1);
*(data + length - 1) = ch;
return 1;
return *this;
}
int MString::write(ZString &value) {
MString& MString::write(ZString &value) {
int len = length;
setSize(length + value.getLength());
memcpy(data + len, value.getData(), value.getLength());
return value.getLength();
return *this;
}
void MString::setSize(int size) {

View File

@ -42,13 +42,19 @@ namespace coreutils {
/// Consructor providing a copy of a ZString.
///
MString(const MString &zstring);
MString(ZString &zstring);
///
/// Consructor providing a copy of a ZString.
///
MString(const MString &mstring);
///
/// Consructor from a string.
///
MString(std::string string);
MString(std::string data);
~MString();
@ -62,6 +68,12 @@ namespace coreutils {
/// Assignment operator will copy data to backing store.
///
MString& operator=(coreutils::MString& data);
///
/// Assignment operator will copy data to backing store.
///
MString& operator=(const char *data);
///
@ -86,13 +98,13 @@ namespace coreutils {
///
///
int write(char ch);
MString& write(char ch);
///
///
///
int write(ZString &value);
MString& write(ZString &value);
private:
int bufferSize = 0;

View File

@ -21,6 +21,11 @@ namespace coreutils {
return os;
}
std::ostream &operator+(std::ostream &os, const char *value) {
os << value;
return os;
}
ZString::ZString() {
data = NULL;
length = 0;

View File

@ -81,6 +81,7 @@ namespace coreutils {
friend std::ostream& operator<<(std::ostream& os, const ZString& zstring);
friend std::ostream& operator<<(std::ostream& os, const std::string& string);
friend std::ostream& operator+(std::ostream& os, const ZString& zstring);
friend std::ostream& operator+(std::ostream& os, const char *value);
bool operator<(const ZString &valuex) const;
bool operator>(const ZString &valuex) const;