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: ";
|
||||
}
|
||||
|
||||
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());
|
||||
@ -56,6 +62,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);
|
||||
@ -77,17 +92,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);
|
||||
|
||||
///
|
||||
@ -80,13 +92,13 @@ namespace coreutils {
|
||||
///
|
||||
///
|
||||
|
||||
int write(char ch);
|
||||
MString& write(char ch);
|
||||
|
||||
///
|
||||
///
|
||||
///
|
||||
|
||||
int write(ZString &value);
|
||||
MString& write(ZString &value);
|
||||
|
||||
private:
|
||||
int bufferSize = 0;
|
||||
|
@ -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;
|
||||
|
Binary file not shown.
@ -21,9 +21,11 @@ int main(int argc, char **argv) {
|
||||
test4 << "this is a test.";
|
||||
std::cout << "char* operator<<: [" << test4 << "]." << std::endl;
|
||||
|
||||
// coreutils::ZString temp("this is literal zstring data.");
|
||||
// coreutils::MString test = temp;
|
||||
// std::cout << "operator=: [" << test << "]." << std::endl;
|
||||
// String building tests.
|
||||
coreutils::MString test5("/this/is/a/path");
|
||||
coreutils::MString test6("/filename");
|
||||
test5.write(test6);
|
||||
std::cout << "test write: [" << test5 << "]." << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user