Worked on ZString, MString and JString

This commit is contained in:
Brad Arant committed 2023-10-05 17:57:01 -07:00
1 parent b873bbf164
commit 8a9c1c3bd7
14 files changed
+146 -42

No files matched your search

+16 -23
View File
@@ -24,6 +24,12 @@ namespace coreutils {
cursor = this->data;
}
MString::MString(unsigned char *data, size_t length) {
setSize(length);
memcpy(this->data, data, length);
cursor = this->data;
}
MString::MString(const char *data, size_t length) {
setSize(length);
memcpy(this->data, data, length);
@@ -55,32 +61,19 @@ namespace coreutils {
cursor = this->data;
}
MString::MString(std::FILE *file) {
setSize(1000000);
this->length = fread(this->data, 1000000, 1000000, file);
cursor = this->data;
}
MString::~MString() {
if(data)
free(data);
}
// MString& MString::operator=(coreutils::ZString& 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=(coreutils::ZString& 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=(coreutils::ZString &value) {
// if(*this == value)
// return *this;
setSize(value.getLength());
memcpy(data, value.getData(), value.getLength());
length = value.getLength();
@@ -196,9 +189,9 @@ namespace coreutils {
int cursorOffset = cursor - data;
int newBufferSize = ((size / 256) + 1) * 256;
if(bufferSize != newBufferSize) {
bufferSize = newBufferSize;
data = (char *)realloc(data, bufferSize);
cursor = data + cursorOffset;
bufferSize = newBufferSize;
data = (char *)realloc(data, bufferSize);
cursor = data + cursorOffset;
}
length = size;
}