diff --git a/MString.cpp b/MString.cpp index 05a83ca..c23fb92 100644 --- a/MString.cpp +++ b/MString.cpp @@ -47,6 +47,11 @@ namespace coreutils { free(data); } + int overflow(int c) { + std::cout << '{' << c << "}"; + return 0; + } + MString& MString::operator=(coreutils::ZString& value) { if(*this == value) return *this; @@ -71,9 +76,33 @@ namespace coreutils { } MString& MString::operator<<(const char *value) { + int temp = length; int len = strlen(value); + setSize(len + length); + memcpy(data + temp, value, len); + return *this; + } + + MString& MString::operator<<(const int value) { + std::stringstream temp; + temp << value; + *this << temp.str(); + return *this; + } + + MString& MString::operator<<(coreutils::ZString &zstring) { + int temp = length; + int len = length + zstring.getLength(); setSize(len); - memcpy(data, value, len); + memcpy(data + temp, zstring.getData(), zstring.getLength()); + return *this; + } + + MString& MString::operator<<(std::string value) { + int temp = length; + int len = length + value.length(); + setSize(len); + memcpy(data + temp, value.c_str(), value.length()); return *this; } diff --git a/MString.h b/MString.h index 9252399..b2cc03b 100644 --- a/MString.h +++ b/MString.h @@ -75,7 +75,13 @@ namespace coreutils { /// MString& operator<<(const char *value); - + + MString& operator<<(const int value); + + MString& operator<<(coreutils::ZString &zstring); + + MString& operator<<(std::string value); + /// /// /// diff --git a/testing/mstring_test b/testing/mstring_test index ecf0e8f..7069478 100755 Binary files a/testing/mstring_test and b/testing/mstring_test differ diff --git a/testing/mstring_test.cpp b/testing/mstring_test.cpp index e0aae0d..9fb9fc5 100644 --- a/testing/mstring_test.cpp +++ b/testing/mstring_test.cpp @@ -20,11 +20,15 @@ int main(int argc, char **argv) { coreutils::MString test4; test4 << "this is a test."; std::cout << "char* operator<<: [" << test4 << "]." << std::endl; + test4 << "another test " << 75; + 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; - + // Stream assignment capabilities. + coreutils::MString test6; + int number = 75; + test6 << "Will this work? " << number << test4 << " See how this works."; + std::cout << "streaming: [" << test6 << "]." << std::endl; + return 0; }