Website Summary Files Commits Branches @commit @diff @stats
path: root / Week09 / Exercise03 / String.h
blob: 674813ce58314c97bcae68227bfbd0d3d6e5f3f8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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 */