MString updates.
This commit is contained in:
1 parent
d2f13c192c
commit
036978130d
7 files changed
+80
-45
No files matched your search
+28
-13
@@ -24,7 +24,7 @@ namespace coreutils {
|
||||
}
|
||||
|
||||
MString::MString(const char *data, size_t length) {
|
||||
setSize(length);
|
||||
setSize(length);
|
||||
memcpy(this->data, data, length);
|
||||
cursor = this->data;
|
||||
}
|
||||
@@ -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());
|
||||
@@ -53,41 +59,50 @@ namespace coreutils {
|
||||
int len = length;
|
||||
setSize(length + value.getLength());
|
||||
memcpy(data + len, value.getData(), value.getLength());
|
||||
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) {
|
||||
int len = strlen(value);
|
||||
setSize(len);
|
||||
memcpy(data, value, len);
|
||||
return *this;
|
||||
return *this;
|
||||
}
|
||||
|
||||
MString& MString::operator=(char value) {
|
||||
int len = 1;
|
||||
setSize(1);
|
||||
*data = value;
|
||||
return *this;
|
||||
return *this;
|
||||
}
|
||||
|
||||
MString& MString::operator<<(const char *value) {
|
||||
int len = strlen(value);
|
||||
setSize(len);
|
||||
memcpy(data, value, len);
|
||||
return *this;
|
||||
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) {
|
||||
@@ -95,10 +110,10 @@ namespace coreutils {
|
||||
int newBufferSize = ((size / 256) + 1) * 256;
|
||||
if(bufferSize != newBufferSize) {
|
||||
bufferSize = newBufferSize;
|
||||
data = (char *)realloc(data, bufferSize);
|
||||
data = (char *)realloc(data, bufferSize);
|
||||
cursor = data + cursorOffset;
|
||||
}
|
||||
length = size;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user