MString updates.
This commit is contained in:
parent
d2f13c192c
commit
036978130d
23
MString.cpp
23
MString.cpp
@ -36,6 +36,12 @@ namespace coreutils {
|
|||||||
// Log(LOG_DEBUG_2) << "MString Copy Constructor: ";
|
// 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) {
|
MString::MString(std::string data) {
|
||||||
setSize(data.length());
|
setSize(data.length());
|
||||||
memcpy(this->data, (char *)data.c_str(), data.length());
|
memcpy(this->data, (char *)data.c_str(), data.length());
|
||||||
@ -56,6 +62,15 @@ namespace coreutils {
|
|||||||
return *this;
|
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) {
|
MString& MString::operator=(const char *value) {
|
||||||
int len = strlen(value);
|
int len = strlen(value);
|
||||||
setSize(len);
|
setSize(len);
|
||||||
@ -77,17 +92,17 @@ namespace coreutils {
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
int MString::write(char ch) {
|
MString& MString::write(char ch) {
|
||||||
setSize(length + 1);
|
setSize(length + 1);
|
||||||
*(data + length - 1) = ch;
|
*(data + length - 1) = ch;
|
||||||
return 1;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
int MString::write(ZString &value) {
|
MString& MString::write(ZString &value) {
|
||||||
int len = length;
|
int len = length;
|
||||||
setSize(length + value.getLength());
|
setSize(length + value.getLength());
|
||||||
memcpy(data + len, value.getData(), value.getLength());
|
memcpy(data + len, value.getData(), value.getLength());
|
||||||
return value.getLength();
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MString::setSize(int size) {
|
void MString::setSize(int size) {
|
||||||
|
20
MString.h
20
MString.h
@ -42,13 +42,19 @@ namespace coreutils {
|
|||||||
/// Consructor providing a copy of a ZString.
|
/// 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.
|
/// Consructor from a string.
|
||||||
///
|
///
|
||||||
|
|
||||||
MString(std::string string);
|
MString(std::string data);
|
||||||
|
|
||||||
~MString();
|
~MString();
|
||||||
|
|
||||||
@ -62,6 +68,12 @@ namespace coreutils {
|
|||||||
/// Assignment operator will copy data to backing store.
|
/// 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);
|
MString& operator=(const char *data);
|
||||||
|
|
||||||
///
|
///
|
||||||
@ -80,13 +92,13 @@ namespace coreutils {
|
|||||||
///
|
///
|
||||||
///
|
///
|
||||||
|
|
||||||
int write(char ch);
|
MString& write(char ch);
|
||||||
|
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
|
|
||||||
int write(ZString &value);
|
MString& write(ZString &value);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int bufferSize = 0;
|
int bufferSize = 0;
|
||||||
|
@ -21,6 +21,11 @@ namespace coreutils {
|
|||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::ostream &operator+(std::ostream &os, const char *value) {
|
||||||
|
os << value;
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
ZString::ZString() {
|
ZString::ZString() {
|
||||||
data = NULL;
|
data = NULL;
|
||||||
length = 0;
|
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 ZString& zstring);
|
||||||
friend std::ostream& operator<<(std::ostream& os, const std::string& string);
|
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 ZString& zstring);
|
||||||
|
friend std::ostream& operator+(std::ostream& os, const char *value);
|
||||||
|
|
||||||
bool operator<(const ZString &valuex) const;
|
bool operator<(const ZString &valuex) const;
|
||||||
bool operator>(const ZString &valuex) const;
|
bool operator>(const ZString &valuex) const;
|
||||||
|
Binary file not shown.
@ -21,9 +21,11 @@ int main(int argc, char **argv) {
|
|||||||
test4 << "this is a test.";
|
test4 << "this is a test.";
|
||||||
std::cout << "char* operator<<: [" << test4 << "]." << std::endl;
|
std::cout << "char* operator<<: [" << test4 << "]." << std::endl;
|
||||||
|
|
||||||
// coreutils::ZString temp("this is literal zstring data.");
|
// String building tests.
|
||||||
// coreutils::MString test = temp;
|
coreutils::MString test5("/this/is/a/path");
|
||||||
// std::cout << "operator=: [" << test << "]." << std::endl;
|
coreutils::MString test6("/filename");
|
||||||
|
test5.write(test6);
|
||||||
|
std::cout << "test write: [" << test5 << "]." << std::endl;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user