Website Summary Files Commits Branches @commit @diff @stats
path: root / src / Generic / String / String.cpp
diff options
context:
space:
mode:
1 files changed, 13 insertions, 1 deletions
-rw-r--r--src/Generic/String/String.cpp14
diff --git a/src/Generic/String/String.cpp b/src/Generic/String/String.cpp
index 055f48e..b1e2889 100644
--- a/src/Generic/String/String.cpp
+++ b/src/Generic/String/String.cpp
@@ -18,13 +18,25 @@ void String::copyFrom(const String& other) {
String::String(const char* str) {
length = strlen(str) + 1; // capture terminating zero
this->str = new char[length];
- strcpy(this->str, str);
+ strncpy(this->str, str, length);
}
const char* String::get_cstr() const {
return str;
}
+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() : String("") {}
String::String(const String& other) {