Website Summary Files Commits Branches @commit @diff @stats
path: root / Week09 / Exercise03 / String.h
diff options
context:
space:
mode:
Commitb38346eebca9a007971af02fb3bb9472c5e16d0c (patch)
Author
 Syndamia <kamen@syndamia.com>
2026-04-26 21:43:31 +0300
Committer
 Syndamia <kamen@syndamia.com>
2026-04-26 21:43:31 +0300
Files575a64089a17be271aec84683f426252d8f5d1f9 /Week09/Exercise03/String.h
oop-2025-solutions-b38346eebca9a007971af02fb3bb9472c5e16d0c.tar
oop-2025-solutions-b38346eebca9a007971af02fb3bb9472c5e16d0c.tar.gz
oop-2025-solutions-b38346eebca9a007971af02fb3bb9472c5e16d0c.zip
Parent7d98b664c9e459a08f2e6e6fa5b636686dfed554 (diff)
feat(Week09): Add solutions
1 files changed, 61 insertions, 0 deletions
-rw-r--r--Week09/Exercise03/String.h61
diff --git a/Week09/Exercise03/String.h b/Week09/Exercise03/String.h
new file mode 100644
index 0000000..674813c
--- /dev/null
+++ b/Week09/Exercise03/String.h
@@ -0,0 +1,61 @@
+#ifndef _STRING
+#define _STRING
+
+#include <ostream>
+
+class String {
+ char* str;
+ unsigned length;
+
+ void free();
+ void copyFrom(const String& other);
+
+public:
+ String();
+ ~String();
+ String(const String& other);
+ String& operator=(const String& other);
+
+ String(String&& other);
+ String& operator=(String&& other);
+
+ // Помощни член-функции, за да тестваме String
+ String(const char* str);
+ friend std::ostream& operator<<(std::ostream& ostr, const String& string);
+
+ // Каза ни са кои оператори трябва да бъдат имплементирани,
+ // но както помощни функции, можем да си имплементираме и други
+ // оператори
+ String& operator+=(const String& other);
+
+ char operator[](unsigned index) const;
+
+ const char* te() const {
+ return str;
+ }
+
+ struct IndexRange {
+ unsigned start;
+ unsigned end;
+
+ IndexRange(unsigned index);
+ IndexRange& operator,(const IndexRange& rhs);
+ };
+ String operator[](IndexRange range) const;
+
+ // Алтернативно, може да създадем селектори
+ // GetStr който връща str указателя и GetLength,
+ // и тези функции няма да е нужно да са приятелски
+ friend bool operator==(const String& lhs, const String& rhs);
+ friend bool operator!=(const String& lhs, const String& rhs);
+ friend bool operator<(const String& lhs, const String& rhs);
+ friend bool operator<=(const String& lhs, const String& rhs);
+ friend bool operator>(const String& lhs, const String& rhs);
+ friend bool operator>=(const String& lhs, const String& rhs);
+ friend bool operator<<(const String& lhs, const String& rhs);
+ friend bool operator>>(const String& lhs, const String& rhs);
+};
+
+String operator+(const String& lhs, const String& rhs);
+
+#endif /* _STRING */