-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy pathstring
More file actions
333 lines (302 loc) · 14.9 KB
/
string
File metadata and controls
333 lines (302 loc) · 14.9 KB
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
#ifndef _GHLIBCPP_STRING
#define _GHLIBCPP_STRING
#include "cwchar"
#include "memory.h"
#include "initializer_list"
#include "ios.h"
#include "iosfwd.h"
#include "iterator.h"
#include "stddef.h"
#include "memory.h"
#include "empty.h"
namespace std {
template <class charT> struct char_traits {
typedef charT char_type;
typedef int int_type;
typedef streamoff off_type;
typedef streampos pos_type;
typedef mbstate_t state_type;
static void assign(char_type &c1, const char_type &c2);
static bool eq(const char_type &c1, const char_type &c2);
static bool lt(const char_type &c1, const char_type &c2);
static int compare(const char_type *s1, const char_type *s2, size_t n);
static size_t length(const char_type *s);
static const char_type *find(const char_type *s, size_t n,
const char_type &a);
static char_type *move(char_type *s1, const char_type *s2, size_t n);
static char_type *copy(char_type *s1, const char_type *s2, size_t n);
static char_type *assign(char_type *s, size_t n, char_type a);
static int_type not_eof(const int_type &c);
static char_type to_char_type(const int_type &c);
static int_type to_int_type(const char_type &c);
static bool eq_int_type(const int_type &c1, const int_type &c2);
static int_type eof();
};
// Specialization for char
template <> struct char_traits<char> {
typedef char char_type;
typedef int int_type;
typedef streamoff off_type;
typedef streampos pos_type;
typedef mbstate_t state_type;
static void assign(char_type &c1, const char_type &c2);
static bool eq(const char_type &c1, const char_type &c2);
static bool lt(const char_type &c1, const char_type &c2);
static int compare(const char_type *s1, const char_type *s2, size_t n);
static size_t length(const char_type *s);
static const char_type *find(const char_type *s, size_t n,
const char_type &a);
static char_type *move(char_type *s1, const char_type *s2, size_t n);
static char_type *copy(char_type *s1, const char_type *s2, size_t n);
static char_type *assign(char_type *s, size_t n, char_type a);
static int_type not_eof(const int_type &c);
static char_type to_char_type(const int_type &c);
static int_type to_int_type(const char_type &c);
static bool eq_int_type(const int_type &c1, const int_type &c2);
static int_type eof();
};
// Specialization for wchar_t
template <> struct char_traits<wchar_t> {
typedef wchar_t char_type;
typedef wint_t int_type;
typedef streamoff off_type;
typedef wstreampos pos_type;
typedef mbstate_t state_type;
static void assign(char_type &c1, const char_type &c2);
static bool eq(const char_type &c1, const char_type &c2);
static bool lt(const char_type &c1, const char_type &c2);
static int compare(const char_type *s1, const char_type *s2, size_t n);
static size_t length(const char_type *s);
static const char_type *find(const char_type *s, size_t n,
const char_type &a);
static char_type *move(char_type *s1, const char_type *s2, size_t n);
static char_type *copy(char_type *s1, const char_type *s2, size_t n);
static char_type *assign(char_type *s, size_t n, char_type a);
static int_type not_eof(const int_type &c);
static char_type to_char_type(const int_type &c);
static int_type to_int_type(const char_type &c);
static bool eq_int_type(const int_type &c1, const int_type &c2);
static int_type eof();
};
template <class charT, class traits = char_traits<charT>,
class Allocator = allocator<charT>>
class basic_string {
public:
using value_type = charT;
using reference = value_type &;
using const_reference = const value_type &;
typedef typename Allocator::size_type size_type;
static const size_type npos = -1;
basic_string() : basic_string(Allocator()) {}
explicit basic_string(const Allocator &a);
basic_string(const basic_string &str);
basic_string(basic_string &&str) noexcept;
basic_string(const charT *s, size_type n, const Allocator &a = Allocator());
basic_string(const charT *s, const Allocator &a = Allocator());
basic_string(size_type n, charT c, const Allocator &a = Allocator());
template <class InputIterator>
basic_string(InputIterator begin, InputIterator end,
const Allocator &a = Allocator());
~basic_string();
basic_string &operator=(const basic_string &str);
basic_string &operator=(basic_string &&str) noexcept;
basic_string &operator=(const charT *s);
basic_string &operator=(charT c);
basic_string &operator=(initializer_list<charT>);
const charT *c_str() const;
charT *data() noexcept;
size_type size() const noexcept;
size_type length() const noexcept;
typedef __iterator<charT> iterator;
typedef __iterator<const charT> __const_iterator;
typedef __const_iterator const_iterator;
iterator begin();
iterator end();
const_iterator begin() const;
const_iterator end() const;
const_iterator cbegin() const;
const_iterator cend() const;
const charT &front() const;
charT &front();
const charT &back() const;
charT &back();
const_reference operator[](size_type pos) const;
reference operator[](size_type pos);
const_reference at(size_type n) const;
reference at(size_type n);
basic_string &operator+=(const basic_string &str);
basic_string &operator+=(const charT *s);
basic_string &operator+=(charT c);
basic_string &operator+=(initializer_list<charT>);
basic_string &append(const basic_string &str);
basic_string &append(const basic_string &str, size_type pos,
size_type n = npos);
basic_string &append(const charT *s, size_type n);
basic_string &append(const charT *s);
basic_string &append(size_type n, charT c);
template <class InputIterator>
basic_string &append(InputIterator first, InputIterator last);
basic_string &append(initializer_list<charT>);
void push_back(charT c);
basic_string &assign(const basic_string &str);
basic_string &assign(basic_string &&str) noexcept;
basic_string &assign(const basic_string &str, size_type pos,
size_type n = npos);
basic_string &assign(const charT *s, size_type n);
basic_string &assign(const charT *s);
basic_string &assign(size_type n, charT c);
template <class InputIterator>
basic_string &assign(InputIterator first, InputIterator last);
basic_string &assign(initializer_list<charT>);
basic_string &insert(size_type pos1, const basic_string &str);
basic_string &insert(size_type pos1, const basic_string &str, size_type pos2,
size_type n = npos);
basic_string &insert(size_type pos, const charT *s, size_type n);
basic_string &insert(size_type pos, const charT *s);
basic_string &insert(size_type pos, size_type n, charT c);
iterator insert(const_iterator p, charT c);
iterator insert(const_iterator p, size_type n, charT c);
template <class InputIterator>
iterator insert(const_iterator p, InputIterator first, InputIterator last);
iterator insert(const_iterator p, initializer_list<charT>);
basic_string &erase(size_type pos = 0, size_type n = npos);
iterator erase(const_iterator p);
iterator erase(const_iterator first, const_iterator last);
basic_string &replace(size_type pos1, size_type n1, const basic_string &str);
basic_string &replace(size_type pos1, size_type n1, const basic_string &str,
size_type pos2, size_type n2 = npos);
basic_string &replace(size_type pos, size_type n1, const charT *s,
size_type n2);
basic_string &replace(size_type pos, size_type n1, const charT *s);
basic_string &replace(size_type pos, size_type n1, size_type n2, charT c);
basic_string &replace(__const_iterator i1, __const_iterator i2,
const basic_string &str);
basic_string &replace(__const_iterator i1, __const_iterator i2,
const charT *s, size_type n);
basic_string &replace(__const_iterator i1, __const_iterator i2,
const charT *s);
basic_string &replace(__const_iterator i1, __const_iterator i2, size_type n,
charT c);
template <class InputIterator>
basic_string &replace(__const_iterator i1, __const_iterator i2,
InputIterator j1, InputIterator j2);
basic_string &replace(__const_iterator, __const_iterator,
initializer_list<charT>);
size_type copy(charT *s, size_type n, size_type pos = 0) const;
void clear() noexcept;
void swap(basic_string &s) noexcept;
size_type find(const basic_string &str, size_type pos = 0) const noexcept;
size_type find(const charT *s, size_type pos, size_type n) const;
size_type find(const charT *s, size_type pos = 0) const;
size_type find(charT c, size_type pos = 0) const;
size_type rfind(const basic_string &str, size_type pos = npos) const noexcept;
size_type rfind(const charT *s, size_type pos, size_type n) const;
size_type rfind(const charT *s, size_type pos = npos) const;
size_type rfind(charT c, size_type pos = npos) const;
size_type find_first_of(const basic_string &str,
size_type pos = 0) const noexcept;
size_type find_first_of(const charT *s, size_type pos, size_type n) const;
size_type find_first_of(const charT *s, size_type pos = 0) const;
size_type find_first_of(charT c, size_type pos = 0) const;
size_type find_last_of(const basic_string &str,
size_type pos = npos) const noexcept;
size_type find_last_of(const charT *s, size_type pos, size_type n) const;
size_type find_last_of(const charT *s, size_type pos = npos) const;
size_type find_last_of(charT c, size_type pos = npos) const;
size_type find_first_not_of(const basic_string &str,
size_type pos = 0) const noexcept;
size_type find_first_not_of(const charT *s, size_type pos, size_type n) const;
size_type find_first_not_of(const charT *s, size_type pos = 0) const;
size_type find_first_not_of(charT c, size_type pos = 0) const;
size_type find_last_not_of(const basic_string &str,
size_type pos = npos) const noexcept;
size_type find_last_not_of(const charT *s, size_type pos, size_type n) const;
size_type find_last_not_of(const charT *s, size_type pos = npos) const;
size_type find_last_not_of(charT c, size_type pos = npos) const;
basic_string substr(size_type pos = 0, size_type n = npos) const;
int compare(const basic_string &str) const noexcept;
int compare(size_type pos1, size_type n1, const basic_string &str) const;
int compare(size_type pos1, size_type n1, const basic_string &str,
size_type pos2, size_type n2 = npos) const;
int compare(const charT *s) const;
int compare(size_type pos1, size_type n1, const charT *s) const;
int compare(size_type pos1, size_type n1, const charT *s, size_type n2) const;
bool empty() const noexcept;
void reserve(size_type new_cap = 0);
};
template <class charT, class traits, class Allocator>
basic_string<charT, traits, Allocator>
operator+(const basic_string<charT, traits, Allocator> &lhs,
const basic_string<charT, traits, Allocator> &rhs);
template <class charT, class traits, class Allocator>
basic_string<charT, traits, Allocator>
operator+(const basic_string<charT, traits, Allocator> &lhs, const charT *rhs);
template <class charT, class traits, class Allocator>
basic_string<charT, traits, Allocator>
operator+(const charT *lhs, const basic_string<charT, traits, Allocator> &rhs);
template <class charT, class traits, class Allocator>
bool operator==(const basic_string<charT, traits, Allocator> &lhs,
const basic_string<charT, traits, Allocator> &rhs) noexcept;
template <class charT, class traits, class Allocator>
bool operator==(const charT *lhs,
const basic_string<charT, traits, Allocator> &rhs);
template <class charT, class traits, class Allocator>
bool operator==(const basic_string<charT, traits, Allocator> &lhs,
const charT *rhs);
template <class charT, class traits, class Allocator>
bool operator!=(const basic_string<charT, traits, Allocator> &lhs,
const basic_string<charT, traits, Allocator> &rhs) noexcept;
template <class charT, class traits, class Allocator>
bool operator!=(const charT *lhs,
const basic_string<charT, traits, Allocator> &rhs);
template <class charT, class traits, class Allocator>
bool operator!=(const basic_string<charT, traits, Allocator> &lhs,
const charT *rhs);
template <class charT, class traits, class Allocator>
bool operator<(const basic_string<charT, traits, Allocator> &lhs,
const basic_string<charT, traits, Allocator> &rhs) noexcept;
template <class charT, class traits, class Allocator>
bool operator<(const basic_string<charT, traits, Allocator> &lhs,
const charT *rhs);
template <class charT, class traits, class Allocator>
bool operator<(const charT *lhs,
const basic_string<charT, traits, Allocator> &rhs);
template <class charT, class traits, class Allocator>
bool operator>(const basic_string<charT, traits, Allocator> &lhs,
const basic_string<charT, traits, Allocator> &rhs) noexcept;
template <class charT, class traits, class Allocator>
bool operator>(const basic_string<charT, traits, Allocator> &lhs,
const charT *rhs);
template <class charT, class traits, class Allocator>
bool operator>(const charT *lhs,
const basic_string<charT, traits, Allocator> &rhs);
template <class charT, class traits, class Allocator>
bool operator<=(const basic_string<charT, traits, Allocator> &lhs,
const basic_string<charT, traits, Allocator> &rhs) noexcept;
template <class charT, class traits, class Allocator>
bool operator<=(const basic_string<charT, traits, Allocator> &lhs,
const charT *rhs);
template <class charT, class traits, class Allocator>
bool operator<=(const charT *lhs,
const basic_string<charT, traits, Allocator> &rhs);
template <class charT, class traits, class Allocator>
bool operator>=(const basic_string<charT, traits, Allocator> &lhs,
const basic_string<charT, traits, Allocator> &rhs) noexcept;
template <class charT, class traits, class Allocator>
bool operator>=(const basic_string<charT, traits, Allocator> &lhs,
const charT *rhs);
template <class charT, class traits, class Allocator>
bool operator>=(const charT *lhs,
const basic_string<charT, traits, Allocator> &rhs);
typedef basic_string<char> string;
int stoi(const string &str, size_t *idx = 0, int base = 10);
long stol(const string &str, size_t *idx = 0, int base = 10);
unsigned long stoul(const string &str, size_t *idx = 0, int base = 10);
long long stoll(const string &str, size_t *idx = 0, int base = 10);
unsigned long long stoull(const string &str, size_t *idx = 0, int base = 10);
float stof(const string &str, size_t *idx = 0);
double stod(const string &str, size_t *idx = 0);
long double stold(const string &str, size_t *idx = 0);
std::string to_string(int value);
} // namespace std
#endif // _GHLIBCPP_STRING