-
Notifications
You must be signed in to change notification settings - Fork 0
/
mystring.h
71 lines (59 loc) · 1.49 KB
/
mystring.h
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
62
63
64
65
66
67
68
69
70
71
#pragma once
namespace mylib{
class string
{
public:
string();
string(int);
string(E::Value_Type);
string(E::Value_Type, int);
string(const string&);
inline string(string&& str){ data = str.data; length = str.length; str.data = nullptr; }
string(const char*);
string(const char*, int);
inline ~string() { if (data)delete[] data; }
string & operator=(const string &);
static string number(int n);
inline string & operator=(string && str)
{
if (&str == this) return *this;
if (data)
delete[] data;
data = str.data;
str.data = nullptr;
length = str.length;
return *this;
}
string & operator=(const char*);
inline char& operator[](int index) throw(std::invalid_argument)
{
if (index >= size() || index < 0)
throw std::invalid_argument("Invalid index");
return data[index];
}
inline operator char*()
{
return data;
}
inline operator const char*() const
{
return data;
}
string operator + (const string &) const;
E::Value_Type ToValueType() const;
bool operator==(const string&) const;
bool operator!=(const string&) const;
bool operator>(const string&) const;
bool operator<(const string&) const;
bool operator>=(const string&) const;
bool operator<=(const string&) const;
bool operator==(const char *) const;
int size() const;
string CheckName() const;
void refresh();
private:
int inner_size() const;
char* data;
int length;
};
}