Website Summary Files Commits Branches @commit @diff @stats
path: root / src / String
diff options
context:
space:
mode:
Commit90ce8dc2317c7afc6bf6c7e842f92a31678a4994 (patch)
Author
 Syndamia <kamen.d.mladenov@protonmail.com>
2022-04-25 17:07:06 +0300
Committer
 Syndamia <kamen.d.mladenov@protonmail.com>
2022-04-25 17:07:06 +0300
Filescac17522ecc4db660a6aa7a3966bcfcc74443da5 /src/String
FMI-OOP-P1_TicketSystem-90ce8dc2317c7afc6bf6c7e842f92a31678a4994.tar
FMI-OOP-P1_TicketSystem-90ce8dc2317c7afc6bf6c7e842f92a31678a4994.tar.gz
FMI-OOP-P1_TicketSystem-90ce8dc2317c7afc6bf6c7e842f92a31678a4994.zip
Parent2005589181c6aa547d57fdeb2d36cc5a928bb5a0 (diff)
Autocommit at 25.04.2022 @ 17:07
2 files changed, 47 insertions, 3 deletions
-rw-r--r--src/String/String.cpp49
-rw-r--r--src/String/String.h1
diff --git a/src/String/String.cpp b/src/String/String.cpp
index f94dce2..ee9c9df 100644
--- a/src/String/String.cpp
+++ b/src/String/String.cpp
@@ -8,6 +8,51 @@ void String::free() {
}
void String::copyFrom(const String& other) {
- this->str = new char[other.length];
- strcpy(this->str, other.str);
+ str = new char[other.length];
+ strcpy(str, other.str);
+ length = other.length;
+}
+
+void String::moveFrom(String&& other) {
+ str = other.str;
+ other.str = nullptr;
+ length = other.length;
+}
+
+/* Public */
+
+String::String(const char* str) {
+ length = strlen(str) + 1; // capture terminating zero
+ this->str = new char[length];
+ strcpy(this->str, str);
+}
+
+String::String() : String("") {}
+
+String::String(const String& other) {
+ copyFrom(other);
+}
+
+String& String::operator=(const String& other) {
+ if (this != &other) {
+ free();
+ copyFrom(other);
+ }
+ return *this;
+}
+
+String::~String() {
+ free();
+}
+
+String::String(String&& other) {
+ moveFrom(other);
+}
+
+String& String::operator=(const String& other) {
+ if (this != &other) {
+ free();
+ moveFrom(other);
+ }
+ return *this;
}
diff --git a/src/String/String.h b/src/String/String.h
index acf3650..408e193 100644
--- a/src/String/String.h
+++ b/src/String/String.h
@@ -3,7 +3,6 @@
class String {
char* str;
- unsigned count;
unsigned length;
void free();