Website Summary Files Commits Branches @commit @diff @stats
path: root / src / Generic / String / String.cpp
diff options
context:
space:
mode:
1 files changed, 15 insertions, 4 deletions
-rw-r--r--src/Generic/String/String.cpp19
diff --git a/src/Generic/String/String.cpp b/src/Generic/String/String.cpp
index 570a2c6..99c2e0c 100644
--- a/src/Generic/String/String.cpp
+++ b/src/Generic/String/String.cpp
@@ -3,6 +3,14 @@
/* Private */
+void String::resize() {
+ length *= 2;
+ char* newStr = new char[length];
+ strncpy(newStr, str, count);
+ delete[] str;
+ str = newStr;
+}
+
void String::free() {
delete[] str;
}
@@ -17,9 +25,9 @@ void String::copyFrom(const String& other) {
/* Public */
String::String(const char* str) {
- count = length = strlen(str) + 1; // capture terminating zero
- this->str = new char[length];
- strncpy(this->str, str, count);
+ count = length = strlen(str);
+ this->str = new char[length + 1]; // capture terminating zero
+ strncpy(this->str, str, count + 1);
}
const char* String::get_cstr() const {
@@ -39,7 +47,10 @@ String& String::operator+=(const String& other) {
}
String& String::operator+=(char other) {
- if ()
+ if (count == length) resize();
+
+ str[count++] = other;
+ return *this;
}
String::String() : String("") {}