diff options
Autocommit at 07.05.2022 @ 11:42
2 files changed, 3 insertions, 41 deletions
| -rw-r--r-- | src/Generic/String/String.cpp | 38 | ||||
| -rw-r--r-- | src/Generic/String/String.h | 6 |
diff --git a/src/Generic/String/String.cpp b/src/Generic/String/String.cpp index f327795..069a1df 100644 --- a/src/Generic/String/String.cpp +++ b/src/Generic/String/String.cpp @@ -3,64 +3,32 @@ /* Private */ -void String::resize() { - length *= 2; - char* newStr = new char[length]; - strncpy(newStr, str, count); - delete[] str; - str = newStr; -} - void String::free() { delete[] str; } void String::copyFrom(const String& other) { str = new char[other.length]; - strncpy(str, other.str, other.count); + strncpy(str, other.str, other.length); length = other.length; - count = other.count; } /* Public */ String::String(const char* str) { - count = length = strlen(str); + length = strlen(str); this->str = new char[length + 1]; // capture terminating zero - strncpy(this->str, str, count + 1); + strncpy(this->str, str, length + 1); } const char* String::get_cstr() const { return str; } -unsigned String::get_count() const { - return count; -} - unsigned String::get_length() const { return length; } -String& String::operator+=(const String& other) { - char* newStr = new char[length + other.length + 1]; - strncpy(newStr, str, length); - strncat(newStr, other.str, other.length + 1); - - delete[] str; - str = newStr; - length += other.length; - - return *this; -} - -String& String::operator+=(char other) { - if (count == length) resize(); - - str[count++] = other; - return *this; -} - String::String() : String("") {} String::String(const String& other) { diff --git a/src/Generic/String/String.h b/src/Generic/String/String.h index 3383fe9..9ef6795 100644 --- a/src/Generic/String/String.h +++ b/src/Generic/String/String.h @@ -3,22 +3,16 @@ class String { char* str; - unsigned count; unsigned length; - void resize(); void free(); void copyFrom(const String& other); public: String(const char* str); const char* get_cstr() const; - unsigned get_count() const; unsigned get_length() const; - String& operator+=(const String& other); - String& operator+=(char character); - String(); String(const String& other); String& operator=(const String& other); |
