Merge up with master branch.
This commit is contained in:
commit
f8bc2df133
23
MString.cpp
23
MString.cpp
@ -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) {
|
||||
|
20
MString.h
20
MString.h
@ -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;
|
||||
|
@ -7,7 +7,7 @@ namespace coreutils {
|
||||
|
||||
std::ostream &operator<<(std::ostream &os, const ZString &zstring) {
|
||||
for (char *ix = zstring.data; ix < (zstring.data + zstring.length); ++ix)
|
||||
os << *ix;
|
||||
os << *ix;
|
||||
return os;
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user