MString now string builds with << operator.

This commit is contained in:
Brad Arant committed 2022-07-28 18:36:44 -07:00
1 parent d2f13c192c
commit db801727c6
4 files changed
+45 -6

No files matched your search

+30 -1
View File
@@ -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;
}