-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstring.cpp
144 lines (116 loc) · 2.43 KB
/
string.cpp
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include "object.hpp"
#include "string.hpp"
using namespace CFC;
using namespace CFC::Primitives;
long unsigned int CFC::Primitives::String::instances = 0;
std::ostream &operator<<(std::ostream &cout, const String &s){
cout << s._get_data();
return cout;
}
std::istream &operator>>(std::istream &cin, String &s){
cin >> s._get_data();
return cin;
}
String::String():Object(){
instances++;
}
String::String(const String &s):Object(){
_data = s._data;
instances++;
}
String::String(const std::string &s):Object(){
_data = s;
instances++;
}
String::String(const char *s):Object(){
_data = *s;
instances++;
}
String::~String(){
instances--;
}
size_t String::length(){
return _data.length();
}
size_t String::size(){
return _data.size();
}
String::operator std::string(){
std::string s;
s = _get_data();
return s;
}
String::operator std::string() const{
std::string s;
s = _get_data();
return s;
}
String::operator char(){
char s;
s = _get_data()[0];
return s;
}
String::operator char() const{
char s;
s = _data[0];
return s;
}
String::operator char*(){
char *s;
s = new char [_data.length()+1];
assert (s != 0);
strcpy (s, _data.c_str());
return s;
}
String::operator char*() const{
char *s;
s = new char [_data.length()+1];
assert (s != 0);
strcpy (s, _data.c_str());
return s;
}
const String &String::operator=(const String &s){
_data = s._data;
return *this;
}
const String &String::operator+(const String &s){
String *t = new String;
t->_data = _data + s._data;
return *t;
}
const String &String::operator+=(const String &s){
_data = _data + s._data;
return *this;
}
bool String::operator!() const{
return (bool)(_data.size() == 0);
}
bool String::operator==(const String &s) const{
return (bool) (_data == s._data);
}
bool String::operator!=(const String &s) const{
return (bool) (_data != s._data);
}
bool String::operator<(const String &s) const{
return (bool) (_data < s._data);
}
bool String::operator>(const String &s) const{
return (bool) (_data > s._data);
}
bool String::operator>=(const String &s) const{
return (bool) (_data >= s._data);
}
bool String::operator<=(const String &s) const{
return (bool) (_data <= s._data);
}
char &String::operator[](int i){
char *c = new char [1];
*c = _data[i];
return *c;
}
std::string &String::_get_data(){
return _data;
}
const std::string &String::_get_data() const{
return _data;
}