6
6
* $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0).
7
7
* (See accompanying file LICENSE)
8
8
* Authors: Guillaume Chatelet
9
+ * Manu Evans
9
10
* Source: $(DRUNTIMESRC core/stdcpp/string.d)
10
11
*/
11
12
@@ -32,6 +33,7 @@ pragma(lib, "stdc++");
32
33
// /////////////////////////////////////////////////////////////////////////////
33
34
34
35
import core.stdcpp.allocator ;
36
+ import core.stdc.stddef ;
35
37
36
38
extern (C++ , std):
37
39
@@ -45,293 +47,168 @@ struct char_traits(CharT) {}
45
47
* The basic_string is the generalization of class string for any character
46
48
* type.
47
49
*/
48
- struct basic_string (T, TRAITS = char_traits! T, ALLOC = allocator! T)
50
+ extern ( C++ , class) struct basic_string (T, Traits = char_traits! T, Alloc = allocator! T)
49
51
{
50
- enum size_t npos = size_t .max;
52
+ enum size_type npos = size_type .max;
51
53
52
54
alias value_type = T;
53
- alias traits_type = TRAITS ;
54
- alias allocator_type = ALLOC ;
55
+ alias traits_type = Traits ;
56
+ alias allocator_type = Alloc ;
55
57
alias reference = ref T;
56
58
alias const_reference = ref const (T);
57
59
alias pointer = T* ;
58
- alias const_pointer = const (T* ) ;
60
+ alias const_pointer = const (T) * ;
59
61
alias iterator = pointer;
60
62
alias const_iterator = const_pointer;
61
63
// alias reverse_iterator
62
64
// alias const_reverse_iterator
63
65
alias difference_type = ptrdiff_t ;
64
66
alias size_type = size_t ;
65
67
66
- // Ctor/dtor
67
- pragma (mangle, " _ZNSsC1Ev" )
68
- @disable this ();
69
-
70
- pragma (mangle, " _ZNSsC1ERKSs" )
71
- this (ref const this );
72
-
73
- pragma (mangle, " _ZNSsC1EPKcRKSaIcE" )
74
- this (const (T* ) _, ref const allocator_type _ = defaultAlloc);
75
-
76
- pragma (mangle, " _ZNSsD1Ev" )
68
+ // ctor/dtor
69
+ // pragma(mangle, "_ZNSsC1ERKSs")
70
+ // this(ref const(this));
71
+ this (const (T)* ptr, size_type count);
72
+ this (const (T)* ptr, size_type count, ref const (allocator_type) al = defaultAlloc);
73
+ this (const (T)* ptr);
74
+ this (const (T)* ptr, ref const (allocator_type) al = defaultAlloc);
75
+ extern (D ) this (const (T)[] dstr) { this (dstr.ptr, dstr.length); }
76
+ extern (D ) this (const (T)[] dstr, ref const (allocator_type) al = defaultAlloc) { this (dstr.ptr, dstr.length); }
77
77
~this ();
78
78
79
- pragma (mangle, " _ZNSsaSERKSs" )
80
- ref basic_string opAssign (ref const basic_string s);
79
+ ref basic_string opAssign (ref const (basic_string) s);
81
80
82
81
// Iterators
83
- pragma (mangle, " _ZNSs5beginEv" )
84
82
iterator begin () nothrow ;
83
+ const_iterator begin () const nothrow ;
84
+ const_iterator cbegin () const nothrow ;
85
85
86
- pragma (mangle, " _ZNKSs5beginEv" )
87
- const_iterator begin () nothrow const ;
88
-
89
- pragma (mangle, " _ZNKSs6cbeginEv" )
90
- const_iterator cbegin () nothrow const ;
91
-
92
- pragma (mangle, " _ZNSs3endEv" )
93
86
iterator end () nothrow ;
94
-
95
- pragma (mangle, " _ZNKSs3endEv" )
96
- const_iterator end () nothrow const ;
97
-
98
- pragma (mangle, " _ZNKSs4cendEv" )
99
- const_iterator cend () nothrow const ;
87
+ const_iterator end () const nothrow ;
88
+ const_iterator cend () const nothrow ;
100
89
101
90
// no reverse iterator for now.
102
91
103
92
// Capacity
104
- pragma (mangle, " _ZNKSs4sizeEv" )
105
- size_t size () nothrow const ;
106
-
107
- pragma (mangle, " _ZNKSs6lengthEv" )
108
- size_t length () nothrow const ;
109
-
110
- pragma (mangle, " _ZNKSs8max_sizeEv" )
111
- size_t max_size () nothrow const ;
93
+ size_type size () const nothrow ;
94
+ size_type length () const nothrow ;
95
+ size_type max_size () const nothrow ;
96
+ size_type capacity () const nothrow ;
112
97
113
- pragma (mangle, " _ZNKSs8capacityEv" )
114
- size_t capacity () nothrow const ;
98
+ bool empty () const nothrow ;
115
99
116
- pragma (mangle, " _ZNKSs5emptyEv" )
117
- bool empty () nothrow const ;
118
-
119
- pragma (mangle, " _ZNSs5clearEv" )
120
100
void clear () nothrow ;
121
-
122
- pragma (mangle, " _ZNSs6resizeEm" )
123
- void resize (size_t n);
124
-
125
- pragma (mangle, " _ZNSs6resizeEmc" )
126
- void resize (size_t n, T c);
127
-
128
- pragma (mangle, " _ZNSs7reserveEm" )
129
- void reserve (size_t n = 0 );
130
-
131
- pragma (mangle, " _ZNSs13shrink_to_fitEv" )
101
+ void resize (size_type n);
102
+ void resize (size_type n, T c);
103
+ void reserve (size_type n = 0 );
132
104
void shrink_to_fit ();
133
105
134
106
// Element access
135
- pragma (mangle, " _ZNSsixEm" )
136
- ref T opIndex (size_t i);
107
+ ref T opIndex (size_type i);
108
+ ref const (T) opIndex (size_type i) const ;
109
+ ref T at (size_type i);
110
+ ref const (T) at (size_type i) const ;
137
111
138
- pragma (mangle, " _ZNKSsixEm" )
139
- ref const (T) opIndex (size_t i) const ;
140
-
141
- pragma (mangle, " _ZNSs2atEm" )
142
- ref T at (size_t i);
143
-
144
- pragma (mangle, " _ZNKSs2atEm" )
145
- ref const (T) at (size_t i) const ;
146
-
147
- pragma (mangle, " _ZNSs4backEv" )
148
112
ref T back ();
149
-
150
- pragma (mangle, " _ZNKSs4backEv" )
151
113
ref const (T) back () const ;
152
-
153
- pragma (mangle, " _ZNSs5frontEv" )
154
114
ref T front ();
155
-
156
- pragma (mangle, " _ZNKSs5frontEv" )
157
115
ref const (T) front () const ;
158
116
159
- // Modifiers
160
- pragma (mangle, " _ZNSspLERKSs" )
161
- ref basic_string opOpAssign (string op)(ref const basic_string _) if (op == " +" );
162
-
163
- pragma (mangle, " _ZNSspLEPKc" )
164
- ref basic_string opOpAssign (string op)(const (T* ) _) if (op == " +" );
165
-
166
- pragma (mangle, " _ZNSspLEc" )
167
- ref basic_string opOpAssign (string op)(T _) if (op == " +" );
168
-
169
- pragma (mangle, " _ZNSs6appendEmc" )
170
- ref basic_string append (size_t n, char c);
171
-
172
- pragma (mangle, " _ZNSs6appendEPKc" )
173
- ref basic_string append (const char * s);
174
-
175
- pragma (mangle, " _ZNSs6appendEPKcm" )
176
- ref basic_string append (const char * s, size_t n);
177
-
178
- pragma (mangle, " _ZNSs6appendERKSs" )
179
- ref basic_string append (ref const basic_string str);
117
+ const (T)* c_str () const nothrow ;
118
+ T* data () nothrow ;
119
+ const (T)* data () const nothrow ;
180
120
181
- pragma (mangle, " _ZNSs6appendERKSsmm" )
182
- ref basic_string append (ref const basic_string str, size_t subpos, size_t sublen);
121
+ // Modifiers
122
+ ref basic_string opOpAssign (string op : " +" )(ref const (basic_string) s);
123
+ ref basic_string opOpAssign (string op : " +" )(const (T)* s);
124
+ ref basic_string opOpAssign (string op : " +" )(T s);
125
+ extern (D ) ref basic_string opOpAssign(string op : " ~" )(ref const (basic_string) s) { this += s; return this ; }
126
+ extern (D ) ref basic_string opOpAssign(string op : " ~" )(const (T)* s) { this += s; return this ; }
127
+ extern (D ) ref basic_string opOpAssign(string op : " ~" )(const (T)[] s) { auto t = basic_string(s.ptr, s.length); this += t; return this ; }
128
+ extern (D ) ref basic_string opOpAssign(string op : " ~" )(T s) { this += s; return this ; }
129
+
130
+ ref basic_string append (size_type n, T c);
131
+ ref basic_string append (const (T)* s);
132
+ ref basic_string append (const (T)* s, size_type n);
133
+ ref basic_string append (ref const (basic_string) str);
134
+ ref basic_string append (ref const (basic_string) str, size_type subpos, size_type sublen);
135
+ extern (D ) ref basic_string append(const (T)[] s) { append(s.ptr, s.length); return this ; }
183
136
184
- pragma (mangle, " _ZNSs9push_backEc" )
185
137
void push_back (T c);
186
138
187
- pragma (mangle, " _ZNSs6assignEmc" )
188
- ref basic_string assign (size_t n, char c);
189
-
190
- pragma (mangle, " _ZNSs6assignEPKc" )
191
- ref basic_string assign (const char * s);
192
-
193
- pragma (mangle, " _ZNSs6assignEPKcm" )
194
- ref basic_string assign (const char * s, size_t n);
195
-
196
- pragma (mangle, " _ZNSs6assignERKSs" )
197
- ref basic_string assign (ref const basic_string str);
198
-
199
- pragma (mangle, " _ZNSs6assignERKSsmm" )
200
- ref basic_string assign (ref const basic_string str, size_t subpos, size_t sublen);
201
-
202
- pragma (mangle, " _ZNSs6insertEmRKSs" )
203
- ref basic_string insert (size_t pos, ref const basic_string str);
204
-
205
- pragma (mangle, " _ZNSs6insertEmRKSsmm" )
206
- ref basic_string insert (size_t pos, ref const basic_string str, size_t subpos, size_t sublen);
207
-
208
- pragma (mangle, " _ZNSs6insertEmPKc" )
209
- ref basic_string insert (size_t pos, const char * s);
139
+ ref basic_string assign (size_type n, T c);
140
+ ref basic_string assign (const (T)* s);
141
+ ref basic_string assign (const (T)* s, size_type n);
142
+ ref basic_string assign (ref const (basic_string) str);
143
+ ref basic_string assign (ref const (basic_string) str, size_type subpos, size_type sublen);
144
+ extern (D ) ref basic_string assign(const (T)[] s) { assign(s.ptr, s.length); return this ; }
210
145
211
- pragma (mangle, " _ZNSs6insertEmPKcm" )
212
- ref basic_string insert (size_t pos, const char * s, size_t n);
146
+ ref basic_string insert (size_type pos, ref const (basic_string) str);
147
+ ref basic_string insert (size_type pos, ref const (basic_string) str, size_type subpos, size_type sublen);
148
+ ref basic_string insert (size_type pos, const (T)* s);
149
+ ref basic_string insert (size_type pos, const (T)* s, size_type n);
150
+ ref basic_string insert (size_type pos, size_type n, T c);
151
+ extern (D ) ref basic_string insert(size_type pos, const (T)[] s) { insert(pos, s.ptr, s.length); return this ; }
213
152
214
- pragma (mangle, " _ZNSs6insertEmmc" )
215
- ref basic_string insert (size_t pos, size_t n, char c);
216
-
217
- pragma (mangle, " _ZNSs5eraseEmm" )
218
- ref basic_string erase (size_t pos = 0 , size_t len = npos);
153
+ ref basic_string erase (size_type pos = 0 , size_type len = npos);
219
154
220
155
// replace
221
156
// swap
222
- pragma (mangle, " _ZNSs8pop_backEv" )
223
157
void pop_back ();
224
158
225
159
// String operations
226
- pragma (mangle, " _ZNKSs5c_strEv" )
227
- const (T* ) c_str () nothrow const ;
228
-
229
- pragma (mangle, " _ZNKSs4dataEv" )
230
- const (T* ) data () nothrow const ;
231
-
232
- pragma (mangle, " _ZNKSs4copyEPcmm" )
233
- size_t copy (T* s, size_t len, size_t pos = 0 ) const ;
234
-
235
- pragma (mangle, " _ZNKSs4findERKSsm" )
236
- size_t find (ref const basic_string str, size_t pos = 0 ) nothrow const ;
237
-
238
- pragma (mangle, " _ZNKSs4findEPKcm" )
239
- size_t find (const (T* ) s, size_t pos = 0 ) const ;
240
-
241
- pragma (mangle, " _ZNKSs4findEPKcmm" )
242
- size_t find (const (T* ) s, size_t pos, size_type n) const ;
243
-
244
- pragma (mangle, " _ZNKSs4findEcm" )
245
- size_t find (T c, size_t pos = 0 ) nothrow const ;
246
-
247
- pragma (mangle, " _ZNKSs5rfindERKSsm" )
248
- size_t rfind (ref const basic_string str, size_t pos = npos) nothrow const ;
249
-
250
- pragma (mangle, " _ZNKSs5rfindEPKcm" )
251
- size_t rfind (const (T* ) s, size_t pos = npos) const ;
252
-
253
- pragma (mangle, " _ZNKSs5rfindEPKcmm" )
254
- size_t rfind (const (T* ) s, size_t pos, size_t n) const ;
255
-
256
- pragma (mangle, " _ZNKSs5rfindEcm" )
257
- size_t rfind (T c, size_t pos = npos) nothrow const ;
258
-
259
- pragma (mangle, " _ZNKSs13find_first_ofERKSsm" )
260
- size_t find_first_of (ref const basic_string str, size_t pos = 0 ) nothrow const ;
261
-
262
- pragma (mangle, " _ZNKSs13find_first_ofEPKcm" )
263
- size_t find_first_of (const (T* ) s, size_t pos = 0 ) const ;
264
-
265
- pragma (mangle, " _ZNKSs13find_first_ofEPKcmm" )
266
- size_t find_first_of (const (T* ) s, size_t pos, size_t n) const ;
267
-
268
- pragma (mangle, " _ZNKSs13find_first_ofEcm" )
269
- size_t find_first_of (T c, size_t pos = 0 ) nothrow const ;
270
-
271
- pragma (mangle, " _ZNKSs12find_last_ofERKSsm" )
272
- size_t find_last_of (ref const basic_string str, size_t pos = npos) nothrow const ;
273
-
274
- pragma (mangle, " _ZNKSs12find_last_ofEPKcm" )
275
- size_t find_last_of (const (T* ) s, size_t pos = npos) const ;
276
-
277
- pragma (mangle, " _ZNKSs12find_last_ofEPKcmm" )
278
- size_t find_last_of (const (T* ) s, size_t pos, size_t n) const ;
279
-
280
- pragma (mangle, " _ZNKSs12find_last_ofEcm" )
281
- size_t find_last_of (T c, size_t pos = npos) nothrow const ;
282
-
283
- pragma (mangle, " _ZNKSs17find_first_not_ofERKSsm" )
284
- size_t find_first_not_of (ref const basic_string str, size_t pos = 0 ) nothrow const ;
285
-
286
- pragma (mangle, " _ZNKSs17find_first_not_ofEPKcm" )
287
- size_t find_first_not_of (const (T* ) s, size_t pos = 0 ) const ;
288
-
289
- pragma (mangle, " _ZNKSs17find_first_not_ofEPKcmm" )
290
- size_t find_first_not_of (const (T* ) s, size_t pos, size_t n) const ;
291
-
292
- pragma (mangle, " _ZNKSs17find_first_not_ofEcm" )
293
- size_t find_first_not_of (T c, size_t pos = 0 ) nothrow const ;
294
-
295
- pragma (mangle, " _ZNKSs16find_last_not_ofERKSsm" )
296
- size_t find_last_not_of (ref const basic_string str, size_t pos = npos) nothrow const ;
297
-
298
- pragma (mangle, " _ZNKSs16find_last_not_ofEPKcm" )
299
- size_t find_last_not_of (const (T* ) s, size_t pos = npos) const ;
300
-
301
- pragma (mangle, " _ZNKSs16find_last_not_ofEPKcmm" )
302
- size_t find_last_not_of (const (T* ) s, size_t pos, size_t n) const ;
303
-
304
- pragma (mangle, " _ZNKSs16find_last_not_ofEcm" )
305
- size_t find_last_not_of (T c, size_t pos = npos) nothrow const ;
306
-
307
- pragma (mangle, " _ZNKSs6substrEmm" )
308
- basic_string substr (size_t pos = 0 , size_t len = npos) const ;
309
-
310
- pragma (mangle, " _ZNKSs7compareERKSs" )
311
- int compare (ref const basic_string str) nothrow const ;
312
-
313
- pragma (mangle, " _ZNKSs7compareEmmRKSs" )
314
- int compare (size_t pos, size_t len, ref const basic_string str) const ;
315
-
316
- pragma (mangle, " _ZNKSs7compareEmmRKSsmm" )
317
- int compare (size_t pos, size_t len, ref const basic_string str, size_t subpos, size_t sublen) const ;
318
-
319
- pragma (mangle, " _ZNKSs7compareEPKc" )
320
- int compare (const (T* ) s) const ;
321
-
322
- pragma (mangle, " _ZNKSs7compareEmmPKc" )
323
- int compare (size_t pos, size_t len, const (T* ) s) const ;
324
-
325
- pragma (mangle, " _ZNKSs7compareEmmPKcm" )
326
- int compare (size_t pos, size_t len, const (T* ) s, size_t n) const ;
160
+ size_type copy (T* s, size_type len, size_type pos = 0 ) const ;
161
+
162
+ size_type find (ref const (basic_string) str, size_type pos = 0 ) const nothrow ;
163
+ size_type find (const (T)* s, size_type pos = 0 ) const ;
164
+ size_type find (const (T)* s, size_type pos, size_type n) const ;
165
+ size_type find (T c, size_type pos = 0 ) const nothrow ;
166
+
167
+ size_type rfind (ref const (basic_string) str, size_type pos = npos) const nothrow ;
168
+ size_type rfind (const (T)* s, size_type pos = npos) const ;
169
+ size_type rfind (const (T)* s, size_type pos, size_type n) const ;
170
+ size_type rfind (T c, size_type pos = npos) const nothrow ;
171
+
172
+ size_type find_first_of (ref const (basic_string) str, size_type pos = 0 ) const nothrow ;
173
+ size_type find_first_of (const (T)* s, size_type pos = 0 ) const ;
174
+ size_type find_first_of (const (T)* s, size_type pos, size_type n) const ;
175
+ size_type find_first_of (T c, size_type pos = 0 ) const nothrow ;
176
+
177
+ size_type find_last_of (ref const (basic_string) str, size_type pos = npos) const nothrow ;
178
+ size_type find_last_of (const (T)* s, size_type pos = npos) const ;
179
+ size_type find_last_of (const (T)* s, size_type pos, size_type n) const ;
180
+ size_type find_last_of (T c, size_type pos = npos) const nothrow ;
181
+
182
+ size_type find_first_not_of (ref const (basic_string) str, size_type pos = 0 ) const nothrow ;
183
+ size_type find_first_not_of (const (T)* s, size_type pos = 0 ) const ;
184
+ size_type find_first_not_of (const (T)* s, size_type pos, size_type n) const ;
185
+ size_type find_first_not_of (T c, size_type pos = 0 ) const nothrow ;
186
+
187
+ size_type find_last_not_of (ref const (basic_string) str, size_type pos = npos) const nothrow ;
188
+ size_type find_last_not_of (const (T)* s, size_type pos = npos) const ;
189
+ size_type find_last_not_of (const (T)* s, size_type pos, size_type n) const ;
190
+ size_type find_last_not_of (T c, size_type pos = npos) const nothrow ;
191
+
192
+ basic_string substr (size_type pos = 0 , size_type len = npos) const ;
193
+
194
+ int compare (ref const (basic_string) str) const nothrow ;
195
+ int compare (size_type pos, size_type len, ref const (basic_string) str) const ;
196
+ int compare (size_type pos, size_type len, ref const (basic_string) str, size_type subpos, size_type sublen) const ;
197
+ int compare (const (T)* s) const ;
198
+ int compare (size_type pos, size_type len, const (T)* s) const ;
199
+ int compare (size_type pos, size_type len, const (T)* s, size_type n) const ;
327
200
328
201
// D helpers
329
- const (T[]) asArray () const { return c_str()[0 .. size()]; }
202
+ alias as_array this ;
203
+ extern (D ) T[] as_array() { return data()[0 .. size()]; }
204
+ extern (D ) const (T)[] as_array() const { return data()[0 .. size()]; }
330
205
331
206
private :
332
207
void [8 ] _ = void ; // to match sizeof(std::string) and pad the object correctly.
333
208
__gshared static immutable allocator! T defaultAlloc;
334
209
}
335
210
336
211
alias basic_string! char std_string;
337
- alias basic_string! wchar std_wstring;
212
+ alias basic_string! wchar_t std_wstring;
213
+ alias basic_string! wchar std_u16string;
214
+ alias basic_string! dchar std_u32string;
0 commit comments