<< operator now outputs fulll ZString.

This commit is contained in:
Brad Arant committed 2022-04-04 13:35:15 -07:00
1 parent 59228ad356
commit b25650c5a7
4 files changed
+83 -43

No files matched your search

+21 -19
View File
@@ -1,6 +1,7 @@
#include "MString.h"
#include "Log.h"
#include <iostream>
#include <stdlib.h>
namespace coreutils {
@@ -12,7 +13,7 @@ namespace coreutils {
MString::MString(const char *data) {
this->length = strlen(data);
bufferSize = (this->length % 256) + 256;
setSize(this->length);
this->data = (char *)malloc(bufferSize);
memcpy(this->data, data, length);
cursor = this->data;
@@ -20,16 +21,14 @@ namespace coreutils {
MString::MString(char *data, size_t length) {
this->length = length;
bufferSize = (this->length % 256) + 256;
this->data = (char *)malloc(bufferSize);
setSize(length);
memcpy(this->data, data, length);
cursor = this->data;
}
MString::MString(const char *data, size_t length) {
this->length = length;
bufferSize = (this->length % 256) + 256;
this->data = (char *)malloc(bufferSize);
setSize(length);
memcpy(this->data, data, length);
cursor = this->data;
}
@@ -44,8 +43,7 @@ namespace coreutils {
}
MString::MString(std::string data) {
bufferSize = (data.length() % 256) + 256;
this->data = (char *)malloc(bufferSize);
setSize(data.length());
memcpy(this->data, (char *)data.c_str(), data.length());
length = data.length();
cursor = this->data;
@@ -53,22 +51,26 @@ namespace coreutils {
MString::~MString() {
if(data)
free(data);
free(data);
}
int MString::write(char ch) {
if(bufferSize == 0) {
bufferSize = 256;
data = (char *)malloc(bufferSize);
cursor = data;
length = 0;
} else if(bufferSize < (length + 1)) {
bufferSize += 256;
data = (char *)realloc(data, bufferSize);
cursor = data;
}
setSize(bufferSize + 1);
data[length++] = ch;
return 1;
}
int MString::write(ZString &value) {
setSize(bufferSize + value.getLength());
memcpy(data, value.getData(), value.getLength());
length += value.getLength();
return value.getLength();
}
void MString::setSize(int size) {
bufferSize = (size % 256) + 256;
data = (char *)realloc(data, bufferSize);
length = size;
}
}