]>
Commit | Line | Data |
---|---|---|
285b36d6 BK |
1 | // Debugging string implementation -*- C++ -*- |
2 | ||
561e7a36 | 3 | // Copyright (C) 2003, 2005 |
285b36d6 BK |
4 | // Free Software Foundation, Inc. |
5 | // | |
6 | // This file is part of the GNU ISO C++ Library. This library is free | |
7 | // software; you can redistribute it and/or modify it under the | |
8 | // terms of the GNU General Public License as published by the | |
9 | // Free Software Foundation; either version 2, or (at your option) | |
10 | // any later version. | |
11 | ||
12 | // This library is distributed in the hope that it will be useful, | |
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | // GNU General Public License for more details. | |
16 | ||
17 | // You should have received a copy of the GNU General Public License along | |
18 | // with this library; see the file COPYING. If not, write to the Free | |
83f51799 | 19 | // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, |
285b36d6 BK |
20 | // USA. |
21 | ||
22 | // As a special exception, you may use this file as part of a free software | |
23 | // library without restriction. Specifically, if other files instantiate | |
24 | // templates or use macros or inline functions from this file, or you compile | |
25 | // this file and link it with other files to produce an executable, this | |
26 | // file does not by itself cause the resulting executable to be covered by | |
27 | // the GNU General Public License. This exception does not however | |
28 | // invalidate any other reasons why the executable file might be covered by | |
29 | // the GNU General Public License. | |
30 | ||
31 | #ifndef _GLIBCXX_DEBUG_STRING | |
32 | #define _GLIBCXX_DEBUG_STRING 1 | |
33 | ||
34 | #include <string> | |
35 | #include <debug/safe_sequence.h> | |
36 | #include <debug/safe_iterator.h> | |
37 | ||
3cbc7af0 BK |
38 | namespace std |
39 | { | |
285b36d6 BK |
40 | namespace __gnu_debug |
41 | { | |
3cbc7af0 | 42 | template<typename _CharT, typename _Traits = std::char_traits<_CharT>, |
561e7a36 | 43 | typename _Allocator = std::allocator<_CharT> > |
526da49c | 44 | class basic_string |
285b36d6 BK |
45 | : public std::basic_string<_CharT, _Traits, _Allocator>, |
46 | public __gnu_debug::_Safe_sequence<basic_string<_CharT, _Traits, | |
47 | _Allocator> > | |
48 | { | |
49 | typedef std::basic_string<_CharT, _Traits, _Allocator> _Base; | |
50 | typedef __gnu_debug::_Safe_sequence<basic_string> _Safe_base; | |
51 | ||
52 | public: | |
53 | // types: | |
526da49c BI |
54 | typedef _Traits traits_type; |
55 | typedef typename _Traits::char_type value_type; | |
56 | typedef _Allocator allocator_type; | |
17e2915c PC |
57 | typedef typename _Base::size_type size_type; |
58 | typedef typename _Base::difference_type difference_type; | |
59 | typedef typename _Base::reference reference; | |
60 | typedef typename _Base::const_reference const_reference; | |
61 | typedef typename _Base::pointer pointer; | |
62 | typedef typename _Base::const_pointer const_pointer; | |
285b36d6 BK |
63 | |
64 | typedef __gnu_debug::_Safe_iterator<typename _Base::iterator, basic_string> | |
65 | iterator; | |
526da49c | 66 | typedef __gnu_debug::_Safe_iterator<typename _Base::const_iterator, |
285b36d6 BK |
67 | basic_string> const_iterator; |
68 | ||
69 | typedef std::reverse_iterator<iterator> reverse_iterator; | |
70 | typedef std::reverse_iterator<const_iterator> const_reverse_iterator; | |
71 | ||
72 | using _Base::npos; | |
73 | ||
74 | // 21.3.1 construct/copy/destroy: | |
75 | explicit basic_string(const _Allocator& __a = _Allocator()) | |
76 | : _Base(__a) | |
77 | { } | |
78 | ||
79 | // Provides conversion from a release-mode string to a debug-mode string | |
80 | basic_string(const _Base& __base) : _Base(__base), _Safe_base() { } | |
81 | ||
82 | // _GLIBCXX_RESOLVE_LIB_DEFECTS | |
526da49c | 83 | // 42. string ctors specify wrong default allocator |
285b36d6 BK |
84 | basic_string(const basic_string& __str) |
85 | : _Base(__str, 0, _Base::npos, __str.get_allocator()), _Safe_base() | |
86 | { } | |
87 | ||
88 | // _GLIBCXX_RESOLVE_LIB_DEFECTS | |
526da49c | 89 | // 42. string ctors specify wrong default allocator |
285b36d6 BK |
90 | basic_string(const basic_string& __str, size_type __pos, |
91 | size_type __n = _Base::npos, | |
92 | const _Allocator& __a = _Allocator()) | |
93 | : _Base(__str, __pos, __n, __a) | |
94 | { } | |
95 | ||
96 | basic_string(const _CharT* __s, size_type __n, | |
97 | const _Allocator& __a = _Allocator()) | |
98 | : _Base(__gnu_debug::__check_string(__s, __n), __n, __a) | |
99 | { } | |
100 | ||
101 | basic_string(const _CharT* __s, const _Allocator& __a = _Allocator()) | |
102 | : _Base(__gnu_debug::__check_string(__s), __a) | |
103 | { this->assign(__s); } | |
104 | ||
105 | basic_string(size_type __n, _CharT __c, | |
106 | const _Allocator& __a = _Allocator()) | |
107 | : _Base(__n, __c, __a) | |
108 | { } | |
109 | ||
110 | template<typename _InputIterator> | |
111 | basic_string(_InputIterator __begin, _InputIterator __end, | |
112 | const _Allocator& __a = _Allocator()) | |
113 | : _Base(__gnu_debug::__check_valid_range(__begin, __end), __end, __a) | |
114 | { } | |
115 | ||
116 | ~basic_string() { } | |
117 | ||
526da49c | 118 | basic_string& |
285b36d6 BK |
119 | operator=(const basic_string& __str) |
120 | { | |
121 | *static_cast<_Base*>(this) = __str; | |
122 | this->_M_invalidate_all(); | |
123 | return *this; | |
124 | } | |
125 | ||
526da49c | 126 | basic_string& |
285b36d6 BK |
127 | operator=(const _CharT* __s) |
128 | { | |
129 | __glibcxx_check_string(__s); | |
130 | *static_cast<_Base*>(this) = __s; | |
131 | this->_M_invalidate_all(); | |
132 | return *this; | |
133 | } | |
134 | ||
526da49c | 135 | basic_string& |
285b36d6 BK |
136 | operator=(_CharT __c) |
137 | { | |
138 | *static_cast<_Base*>(this) = __c; | |
139 | this->_M_invalidate_all(); | |
140 | return *this; | |
141 | } | |
142 | ||
143 | // 21.3.2 iterators: | |
526da49c BI |
144 | iterator |
145 | begin() | |
285b36d6 BK |
146 | { return iterator(_Base::begin(), this); } |
147 | ||
526da49c BI |
148 | const_iterator |
149 | begin() const | |
285b36d6 BK |
150 | { return const_iterator(_Base::begin(), this); } |
151 | ||
526da49c BI |
152 | iterator |
153 | end() | |
285b36d6 BK |
154 | { return iterator(_Base::end(), this); } |
155 | ||
526da49c | 156 | const_iterator |
285b36d6 BK |
157 | end() const |
158 | { return const_iterator(_Base::end(), this); } | |
159 | ||
526da49c BI |
160 | reverse_iterator |
161 | rbegin() | |
285b36d6 BK |
162 | { return reverse_iterator(end()); } |
163 | ||
526da49c | 164 | const_reverse_iterator |
285b36d6 BK |
165 | rbegin() const |
166 | { return const_reverse_iterator(end()); } | |
167 | ||
168 | reverse_iterator | |
169 | rend() | |
170 | { return reverse_iterator(begin()); } | |
171 | ||
526da49c BI |
172 | const_reverse_iterator |
173 | rend() const | |
285b36d6 BK |
174 | { return const_reverse_iterator(begin()); } |
175 | ||
176 | // 21.3.3 capacity: | |
177 | using _Base::size; | |
178 | using _Base::length; | |
179 | using _Base::max_size; | |
180 | ||
526da49c | 181 | void |
285b36d6 BK |
182 | resize(size_type __n, _CharT __c) |
183 | { | |
184 | _Base::resize(__n, __c); | |
185 | this->_M_invalidate_all(); | |
186 | } | |
187 | ||
526da49c | 188 | void |
285b36d6 BK |
189 | resize(size_type __n) |
190 | { this->resize(__n, _CharT()); } | |
191 | ||
192 | using _Base::capacity; | |
193 | using _Base::reserve; | |
194 | ||
526da49c | 195 | void |
285b36d6 BK |
196 | clear() |
197 | { | |
198 | _Base::clear(); | |
199 | this->_M_invalidate_all(); | |
200 | } | |
201 | ||
202 | using _Base::empty; | |
203 | ||
204 | // 21.3.4 element access: | |
526da49c | 205 | const_reference |
285b36d6 BK |
206 | operator[](size_type __pos) const |
207 | { | |
208 | _GLIBCXX_DEBUG_VERIFY(__pos <= this->size(), | |
3cbc7af0 | 209 | _M_message(__gnu_debug::__msg_subscript_oob) |
285b36d6 BK |
210 | ._M_sequence(*this, "this") |
211 | ._M_integer(__pos, "__pos") | |
212 | ._M_integer(this->size(), "size")); | |
213 | return _M_base()[__pos]; | |
214 | } | |
215 | ||
526da49c | 216 | reference |
285b36d6 BK |
217 | operator[](size_type __pos) |
218 | { | |
561e7a36 | 219 | #ifdef _GLIBCXX_DEBUG_PEDANTIC |
285b36d6 | 220 | __glibcxx_check_subscript(__pos); |
561e7a36 PC |
221 | #else |
222 | // as an extension v3 allows s[s.size()] when s is non-const. | |
223 | _GLIBCXX_DEBUG_VERIFY(__pos <= this->size(), | |
3cbc7af0 | 224 | _M_message(__gnu_debug::__msg_subscript_oob) |
561e7a36 PC |
225 | ._M_sequence(*this, "this") |
226 | ._M_integer(__pos, "__pos") | |
227 | ._M_integer(this->size(), "size")); | |
228 | #endif | |
285b36d6 BK |
229 | return _M_base()[__pos]; |
230 | } | |
231 | ||
232 | using _Base::at; | |
233 | ||
234 | // 21.3.5 modifiers: | |
526da49c | 235 | basic_string& |
285b36d6 BK |
236 | operator+=(const basic_string& __str) |
237 | { | |
238 | _M_base() += __str; | |
239 | this->_M_invalidate_all(); | |
240 | return *this; | |
241 | } | |
242 | ||
526da49c | 243 | basic_string& |
285b36d6 BK |
244 | operator+=(const _CharT* __s) |
245 | { | |
246 | __glibcxx_check_string(__s); | |
247 | _M_base() += __s; | |
248 | this->_M_invalidate_all(); | |
249 | return *this; | |
250 | } | |
251 | ||
526da49c | 252 | basic_string& |
285b36d6 BK |
253 | operator+=(_CharT __c) |
254 | { | |
255 | _M_base() += __c; | |
256 | this->_M_invalidate_all(); | |
257 | return *this; | |
258 | } | |
259 | ||
526da49c | 260 | basic_string& |
285b36d6 BK |
261 | append(const basic_string& __str) |
262 | { | |
263 | _Base::append(__str); | |
264 | this->_M_invalidate_all(); | |
265 | return *this; | |
266 | } | |
267 | ||
526da49c | 268 | basic_string& |
285b36d6 BK |
269 | append(const basic_string& __str, size_type __pos, size_type __n) |
270 | { | |
271 | _Base::append(__str, __pos, __n); | |
272 | this->_M_invalidate_all(); | |
273 | return *this; | |
274 | } | |
275 | ||
526da49c | 276 | basic_string& |
285b36d6 BK |
277 | append(const _CharT* __s, size_type __n) |
278 | { | |
279 | __glibcxx_check_string_len(__s, __n); | |
280 | _Base::append(__s, __n); | |
281 | this->_M_invalidate_all(); | |
282 | return *this; | |
283 | } | |
284 | ||
526da49c | 285 | basic_string& |
285b36d6 BK |
286 | append(const _CharT* __s) |
287 | { | |
288 | __glibcxx_check_string(__s); | |
289 | _Base::append(__s); | |
290 | this->_M_invalidate_all(); | |
291 | return *this; | |
292 | } | |
293 | ||
526da49c | 294 | basic_string& |
285b36d6 BK |
295 | append(size_type __n, _CharT __c) |
296 | { | |
297 | _Base::append(__n, __c); | |
298 | this->_M_invalidate_all(); | |
299 | return *this; | |
300 | } | |
301 | ||
302 | template<typename _InputIterator> | |
526da49c | 303 | basic_string& |
285b36d6 BK |
304 | append(_InputIterator __first, _InputIterator __last) |
305 | { | |
306 | __glibcxx_check_valid_range(__first, __last); | |
307 | _Base::append(__first, __last); | |
308 | this->_M_invalidate_all(); | |
309 | return *this; | |
310 | } | |
311 | ||
312 | // _GLIBCXX_RESOLVE_LIB_DEFECTS | |
526da49c BI |
313 | // 7. string clause minor problems |
314 | void | |
285b36d6 BK |
315 | push_back(_CharT __c) |
316 | { | |
317 | _Base::push_back(__c); | |
318 | this->_M_invalidate_all(); | |
319 | } | |
320 | ||
526da49c | 321 | basic_string& |
285b36d6 BK |
322 | assign(const basic_string& __x) |
323 | { | |
324 | _Base::assign(__x); | |
325 | this->_M_invalidate_all(); | |
326 | return *this; | |
327 | } | |
328 | ||
526da49c | 329 | basic_string& |
285b36d6 BK |
330 | assign(const basic_string& __str, size_type __pos, size_type __n) |
331 | { | |
332 | _Base::assign(__str, __pos, __n); | |
333 | this->_M_invalidate_all(); | |
334 | return *this; | |
335 | } | |
336 | ||
526da49c | 337 | basic_string& |
285b36d6 BK |
338 | assign(const _CharT* __s, size_type __n) |
339 | { | |
340 | __glibcxx_check_string_len(__s, __n); | |
341 | _Base::assign(__s, __n); | |
342 | this->_M_invalidate_all(); | |
343 | return *this; | |
344 | } | |
345 | ||
526da49c | 346 | basic_string& |
285b36d6 BK |
347 | assign(const _CharT* __s) |
348 | { | |
349 | __glibcxx_check_string(__s); | |
350 | _Base::assign(__s); | |
351 | this->_M_invalidate_all(); | |
352 | return *this; | |
353 | } | |
354 | ||
526da49c | 355 | basic_string& |
285b36d6 BK |
356 | assign(size_type __n, _CharT __c) |
357 | { | |
358 | _Base::assign(__n, __c); | |
359 | this->_M_invalidate_all(); | |
526da49c | 360 | return *this; |
285b36d6 BK |
361 | } |
362 | ||
363 | template<typename _InputIterator> | |
526da49c | 364 | basic_string& |
285b36d6 BK |
365 | assign(_InputIterator __first, _InputIterator __last) |
366 | { | |
367 | __glibcxx_check_valid_range(__first, __last); | |
368 | _Base::assign(__first, __last); | |
369 | this->_M_invalidate_all(); | |
526da49c | 370 | return *this; |
285b36d6 BK |
371 | } |
372 | ||
526da49c | 373 | basic_string& |
285b36d6 BK |
374 | insert(size_type __pos1, const basic_string& __str) |
375 | { | |
376 | _Base::insert(__pos1, __str); | |
377 | this->_M_invalidate_all(); | |
378 | return *this; | |
379 | } | |
380 | ||
526da49c | 381 | basic_string& |
285b36d6 BK |
382 | insert(size_type __pos1, const basic_string& __str, |
383 | size_type __pos2, size_type __n) | |
384 | { | |
385 | _Base::insert(__pos1, __str, __pos2, __n); | |
386 | this->_M_invalidate_all(); | |
387 | return *this; | |
388 | } | |
389 | ||
526da49c | 390 | basic_string& |
285b36d6 BK |
391 | insert(size_type __pos, const _CharT* __s, size_type __n) |
392 | { | |
393 | __glibcxx_check_string(__s); | |
394 | _Base::insert(__pos, __s, __n); | |
395 | this->_M_invalidate_all(); | |
396 | return *this; | |
397 | } | |
398 | ||
526da49c | 399 | basic_string& |
285b36d6 BK |
400 | insert(size_type __pos, const _CharT* __s) |
401 | { | |
402 | __glibcxx_check_string(__s); | |
403 | _Base::insert(__pos, __s); | |
404 | this->_M_invalidate_all(); | |
526da49c | 405 | return *this; |
285b36d6 BK |
406 | } |
407 | ||
526da49c | 408 | basic_string& |
285b36d6 BK |
409 | insert(size_type __pos, size_type __n, _CharT __c) |
410 | { | |
411 | _Base::insert(__pos, __n, __c); | |
412 | this->_M_invalidate_all(); | |
413 | return *this; | |
414 | } | |
415 | ||
526da49c | 416 | iterator |
285b36d6 BK |
417 | insert(iterator __p, _CharT __c) |
418 | { | |
419 | __glibcxx_check_insert(__p); | |
420 | typename _Base::iterator __res = _Base::insert(__p.base(), __c); | |
421 | this->_M_invalidate_all(); | |
422 | return iterator(__res, this); | |
423 | } | |
424 | ||
526da49c | 425 | void |
285b36d6 BK |
426 | insert(iterator __p, size_type __n, _CharT __c) |
427 | { | |
428 | __glibcxx_check_insert(__p); | |
429 | _Base::insert(__p.base(), __n, __c); | |
430 | this->_M_invalidate_all(); | |
431 | } | |
432 | ||
433 | template<typename _InputIterator> | |
526da49c | 434 | void |
285b36d6 BK |
435 | insert(iterator __p, _InputIterator __first, _InputIterator __last) |
436 | { | |
437 | __glibcxx_check_insert_range(__p, __first, __last); | |
438 | _Base::insert(__p.base(), __first, __last); | |
439 | this->_M_invalidate_all(); | |
440 | } | |
441 | ||
526da49c | 442 | basic_string& |
285b36d6 BK |
443 | erase(size_type __pos = 0, size_type __n = _Base::npos) |
444 | { | |
445 | _Base::erase(__pos, __n); | |
446 | this->_M_invalidate_all(); | |
447 | return *this; | |
448 | } | |
449 | ||
526da49c | 450 | iterator |
285b36d6 BK |
451 | erase(iterator __position) |
452 | { | |
453 | __glibcxx_check_erase(__position); | |
454 | typename _Base::iterator __res = _Base::erase(__position.base()); | |
455 | this->_M_invalidate_all(); | |
456 | return iterator(__res, this); | |
457 | } | |
458 | ||
526da49c | 459 | iterator |
285b36d6 BK |
460 | erase(iterator __first, iterator __last) |
461 | { | |
462 | // _GLIBCXX_RESOLVE_LIB_DEFECTS | |
463 | // 151. can't currently clear() empty container | |
464 | __glibcxx_check_erase_range(__first, __last); | |
465 | typename _Base::iterator __res = _Base::erase(__first.base(), | |
466 | __last.base()); | |
467 | this->_M_invalidate_all(); | |
468 | return iterator(__res, this); | |
469 | } | |
470 | ||
526da49c | 471 | basic_string& |
285b36d6 BK |
472 | replace(size_type __pos1, size_type __n1, const basic_string& __str) |
473 | { | |
474 | _Base::replace(__pos1, __n1, __str); | |
475 | this->_M_invalidate_all(); | |
476 | return *this; | |
477 | } | |
478 | ||
526da49c | 479 | basic_string& |
285b36d6 BK |
480 | replace(size_type __pos1, size_type __n1, const basic_string& __str, |
481 | size_type __pos2, size_type __n2) | |
482 | { | |
483 | _Base::replace(__pos1, __n1, __str, __pos2, __n2); | |
484 | this->_M_invalidate_all(); | |
485 | return *this; | |
486 | } | |
487 | ||
526da49c BI |
488 | basic_string& |
489 | replace(size_type __pos, size_type __n1, const _CharT* __s, | |
285b36d6 BK |
490 | size_type __n2) |
491 | { | |
492 | __glibcxx_check_string_len(__s, __n2); | |
493 | _Base::replace(__pos, __n1, __s, __n2); | |
494 | this->_M_invalidate_all(); | |
495 | return *this; | |
496 | } | |
497 | ||
526da49c | 498 | basic_string& |
285b36d6 BK |
499 | replace(size_type __pos, size_type __n1, const _CharT* __s) |
500 | { | |
501 | __glibcxx_check_string(__s); | |
502 | _Base::replace(__pos, __n1, __s); | |
503 | this->_M_invalidate_all(); | |
504 | return *this; | |
505 | } | |
506 | ||
526da49c | 507 | basic_string& |
285b36d6 BK |
508 | replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c) |
509 | { | |
510 | _Base::replace(__pos, __n1, __n2, __c); | |
511 | this->_M_invalidate_all(); | |
512 | return *this; | |
513 | } | |
514 | ||
526da49c | 515 | basic_string& |
285b36d6 BK |
516 | replace(iterator __i1, iterator __i2, const basic_string& __str) |
517 | { | |
518 | __glibcxx_check_erase_range(__i1, __i2); | |
519 | _Base::replace(__i1.base(), __i2.base(), __str); | |
520 | this->_M_invalidate_all(); | |
521 | return *this; | |
522 | } | |
526da49c BI |
523 | |
524 | basic_string& | |
285b36d6 BK |
525 | replace(iterator __i1, iterator __i2, const _CharT* __s, size_type __n) |
526 | { | |
527 | __glibcxx_check_erase_range(__i1, __i2); | |
528 | __glibcxx_check_string_len(__s, __n); | |
529 | _Base::replace(__i1.base(), __i2.base(), __s, __n); | |
530 | this->_M_invalidate_all(); | |
531 | return *this; | |
532 | } | |
533 | ||
526da49c | 534 | basic_string& |
285b36d6 BK |
535 | replace(iterator __i1, iterator __i2, const _CharT* __s) |
536 | { | |
537 | __glibcxx_check_erase_range(__i1, __i2); | |
538 | __glibcxx_check_string(__s); | |
539 | _Base::replace(__i1.base(), __i2.base(), __s); | |
540 | this->_M_invalidate_all(); | |
541 | return *this; | |
542 | } | |
543 | ||
526da49c | 544 | basic_string& |
285b36d6 BK |
545 | replace(iterator __i1, iterator __i2, size_type __n, _CharT __c) |
546 | { | |
547 | __glibcxx_check_erase_range(__i1, __i2); | |
548 | _Base::replace(__i1.base(), __i2.base(), __n, __c); | |
549 | this->_M_invalidate_all(); | |
550 | return *this; | |
551 | } | |
552 | ||
553 | template<typename _InputIterator> | |
526da49c | 554 | basic_string& |
285b36d6 BK |
555 | replace(iterator __i1, iterator __i2, |
556 | _InputIterator __j1, _InputIterator __j2) | |
557 | { | |
558 | __glibcxx_check_erase_range(__i1, __i2); | |
559 | __glibcxx_check_valid_range(__j1, __j2); | |
560 | _Base::replace(__i1.base(), __i2.base(), __j1, __j2); | |
561 | this->_M_invalidate_all(); | |
562 | return *this; | |
563 | } | |
564 | ||
526da49c | 565 | size_type |
285b36d6 BK |
566 | copy(_CharT* __s, size_type __n, size_type __pos = 0) const |
567 | { | |
568 | __glibcxx_check_string_len(__s, __n); | |
569 | return _Base::copy(__s, __n, __pos); | |
570 | } | |
571 | ||
526da49c | 572 | void |
285b36d6 BK |
573 | swap(basic_string<_CharT,_Traits,_Allocator>& __x) |
574 | { | |
575 | _Base::swap(__x); | |
576 | this->_M_swap(__x); | |
577 | this->_M_invalidate_all(); | |
578 | __x._M_invalidate_all(); | |
579 | } | |
580 | ||
581 | // 21.3.6 string operations: | |
526da49c | 582 | const _CharT* |
285b36d6 BK |
583 | c_str() const |
584 | { | |
585 | const _CharT* __res = _Base::c_str(); | |
586 | this->_M_invalidate_all(); | |
587 | return __res; | |
588 | } | |
589 | ||
526da49c | 590 | const _CharT* |
285b36d6 BK |
591 | data() const |
592 | { | |
593 | const _CharT* __res = _Base::data(); | |
594 | this->_M_invalidate_all(); | |
595 | return __res; | |
596 | } | |
597 | ||
598 | using _Base::get_allocator; | |
599 | ||
526da49c | 600 | size_type |
285b36d6 BK |
601 | find(const basic_string& __str, size_type __pos = 0) const |
602 | { return _Base::find(__str, __pos); } | |
603 | ||
526da49c | 604 | size_type |
285b36d6 BK |
605 | find(const _CharT* __s, size_type __pos, size_type __n) const |
606 | { | |
607 | __glibcxx_check_string(__s); | |
608 | return _Base::find(__s, __pos, __n); | |
609 | } | |
610 | ||
526da49c | 611 | size_type |
285b36d6 BK |
612 | find(const _CharT* __s, size_type __pos = 0) const |
613 | { | |
614 | __glibcxx_check_string(__s); | |
615 | return _Base::find(__s, __pos); | |
616 | } | |
617 | ||
526da49c | 618 | size_type |
285b36d6 BK |
619 | find(_CharT __c, size_type __pos = 0) const |
620 | { return _Base::find(__c, __pos); } | |
621 | ||
526da49c | 622 | size_type |
285b36d6 BK |
623 | rfind(const basic_string& __str, size_type __pos = _Base::npos) const |
624 | { return _Base::rfind(__str, __pos); } | |
625 | ||
526da49c | 626 | size_type |
285b36d6 | 627 | rfind(const _CharT* __s, size_type __pos, size_type __n) const |
526da49c | 628 | { |
285b36d6 BK |
629 | __glibcxx_check_string_len(__s, __n); |
630 | return _Base::rfind(__s, __pos, __n); | |
631 | } | |
632 | ||
526da49c | 633 | size_type |
285b36d6 BK |
634 | rfind(const _CharT* __s, size_type __pos = _Base::npos) const |
635 | { | |
636 | __glibcxx_check_string(__s); | |
637 | return _Base::rfind(__s, __pos); | |
638 | } | |
639 | ||
526da49c | 640 | size_type |
285b36d6 BK |
641 | rfind(_CharT __c, size_type __pos = _Base::npos) const |
642 | { return _Base::rfind(__c, __pos); } | |
526da49c BI |
643 | |
644 | size_type | |
285b36d6 BK |
645 | find_first_of(const basic_string& __str, size_type __pos = 0) const |
646 | { return _Base::find_first_of(__str, __pos); } | |
647 | ||
526da49c | 648 | size_type |
285b36d6 | 649 | find_first_of(const _CharT* __s, size_type __pos, size_type __n) const |
526da49c | 650 | { |
285b36d6 | 651 | __glibcxx_check_string(__s); |
526da49c | 652 | return _Base::find_first_of(__s, __pos, __n); |
285b36d6 BK |
653 | } |
654 | ||
526da49c | 655 | size_type |
285b36d6 | 656 | find_first_of(const _CharT* __s, size_type __pos = 0) const |
526da49c | 657 | { |
285b36d6 | 658 | __glibcxx_check_string(__s); |
526da49c | 659 | return _Base::find_first_of(__s, __pos); |
285b36d6 BK |
660 | } |
661 | ||
526da49c | 662 | size_type |
285b36d6 BK |
663 | find_first_of(_CharT __c, size_type __pos = 0) const |
664 | { return _Base::find_first_of(__c, __pos); } | |
665 | ||
526da49c | 666 | size_type |
285b36d6 BK |
667 | find_last_of(const basic_string& __str, size_type __pos = _Base::npos) const |
668 | { return _Base::find_last_of(__str, __pos); } | |
669 | ||
526da49c | 670 | size_type |
285b36d6 | 671 | find_last_of(const _CharT* __s, size_type __pos, size_type __n) const |
526da49c | 672 | { |
285b36d6 BK |
673 | __glibcxx_check_string(__s); |
674 | return _Base::find_last_of(__s, __pos, __n); | |
675 | } | |
676 | ||
526da49c | 677 | size_type |
285b36d6 | 678 | find_last_of(const _CharT* __s, size_type __pos = _Base::npos) const |
526da49c | 679 | { |
285b36d6 BK |
680 | __glibcxx_check_string(__s); |
681 | return _Base::find_last_of(__s, __pos); | |
682 | } | |
683 | ||
526da49c | 684 | size_type |
285b36d6 BK |
685 | find_last_of(_CharT __c, size_type __pos = _Base::npos) const |
686 | { return _Base::find_last_of(__c, __pos); } | |
687 | ||
526da49c | 688 | size_type |
285b36d6 BK |
689 | find_first_not_of(const basic_string& __str, size_type __pos = 0) const |
690 | { return _Base::find_first_not_of(__str, __pos); } | |
691 | ||
526da49c | 692 | size_type |
285b36d6 BK |
693 | find_first_not_of(const _CharT* __s, size_type __pos, size_type __n) const |
694 | { | |
695 | __glibcxx_check_string_len(__s, __n); | |
696 | return _Base::find_first_not_of(__s, __pos, __n); | |
697 | } | |
698 | ||
526da49c | 699 | size_type |
285b36d6 BK |
700 | find_first_not_of(const _CharT* __s, size_type __pos = 0) const |
701 | { | |
702 | __glibcxx_check_string(__s); | |
703 | return _Base::find_first_not_of(__s, __pos); | |
704 | } | |
705 | ||
526da49c | 706 | size_type |
285b36d6 BK |
707 | find_first_not_of(_CharT __c, size_type __pos = 0) const |
708 | { return _Base::find_first_not_of(__c, __pos); } | |
709 | ||
526da49c | 710 | size_type |
285b36d6 BK |
711 | find_last_not_of(const basic_string& __str, |
712 | size_type __pos = _Base::npos) const | |
713 | { return _Base::find_last_not_of(__str, __pos); } | |
714 | ||
526da49c | 715 | size_type |
285b36d6 BK |
716 | find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const |
717 | { | |
718 | __glibcxx_check_string(__s); | |
719 | return _Base::find_last_not_of(__s, __pos, __n); | |
720 | } | |
721 | ||
526da49c | 722 | size_type |
285b36d6 BK |
723 | find_last_not_of(const _CharT* __s, size_type __pos = _Base::npos) const |
724 | { | |
725 | __glibcxx_check_string(__s); | |
726 | return _Base::find_last_not_of(__s, __pos); | |
727 | } | |
728 | ||
526da49c | 729 | size_type |
285b36d6 BK |
730 | find_last_not_of(_CharT __c, size_type __pos = _Base::npos) const |
731 | { return _Base::find_last_not_of(__c, __pos); } | |
732 | ||
526da49c | 733 | basic_string |
285b36d6 BK |
734 | substr(size_type __pos = 0, size_type __n = _Base::npos) const |
735 | { return basic_string(_Base::substr(__pos, __n)); } | |
736 | ||
526da49c | 737 | int |
285b36d6 BK |
738 | compare(const basic_string& __str) const |
739 | { return _Base::compare(__str); } | |
740 | ||
526da49c | 741 | int |
285b36d6 BK |
742 | compare(size_type __pos1, size_type __n1, |
743 | const basic_string& __str) const | |
744 | { return _Base::compare(__pos1, __n1, __str); } | |
745 | ||
526da49c | 746 | int |
285b36d6 BK |
747 | compare(size_type __pos1, size_type __n1, const basic_string& __str, |
748 | size_type __pos2, size_type __n2) const | |
749 | { return _Base::compare(__pos1, __n1, __str, __pos2, __n2); } | |
750 | ||
526da49c | 751 | int |
285b36d6 BK |
752 | compare(const _CharT* __s) const |
753 | { | |
754 | __glibcxx_check_string(__s); | |
755 | return _Base::compare(__s); | |
756 | } | |
757 | ||
758 | // _GLIBCXX_RESOLVE_LIB_DEFECTS | |
759 | // 5. string::compare specification questionable | |
526da49c | 760 | int |
285b36d6 BK |
761 | compare(size_type __pos1, size_type __n1, const _CharT* __s) const |
762 | { | |
763 | __glibcxx_check_string(__s); | |
764 | return _Base::compare(__pos1, __n1, __s); | |
765 | } | |
766 | ||
767 | // _GLIBCXX_RESOLVE_LIB_DEFECTS | |
768 | // 5. string::compare specification questionable | |
526da49c | 769 | int |
285b36d6 BK |
770 | compare(size_type __pos1, size_type __n1,const _CharT* __s, |
771 | size_type __n2) const | |
772 | { | |
773 | __glibcxx_check_string_len(__s, __n2); | |
774 | return _Base::compare(__pos1, __n1, __s, __n2); | |
775 | } | |
776 | ||
526da49c | 777 | _Base& |
285b36d6 BK |
778 | _M_base() { return *this; } |
779 | ||
526da49c | 780 | const _Base& |
285b36d6 BK |
781 | _M_base() const { return *this; } |
782 | ||
783 | using _Safe_base::_M_invalidate_all; | |
784 | }; | |
785 | ||
786 | template<typename _CharT, typename _Traits, typename _Allocator> | |
787 | inline basic_string<_CharT,_Traits,_Allocator> | |
788 | operator+(const basic_string<_CharT,_Traits,_Allocator>& __lhs, | |
789 | const basic_string<_CharT,_Traits,_Allocator>& __rhs) | |
790 | { return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs; } | |
791 | ||
792 | template<typename _CharT, typename _Traits, typename _Allocator> | |
793 | inline basic_string<_CharT,_Traits,_Allocator> | |
794 | operator+(const _CharT* __lhs, | |
795 | const basic_string<_CharT,_Traits,_Allocator>& __rhs) | |
526da49c | 796 | { |
285b36d6 BK |
797 | __glibcxx_check_string(__lhs); |
798 | return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs; | |
799 | } | |
800 | ||
801 | template<typename _CharT, typename _Traits, typename _Allocator> | |
802 | inline basic_string<_CharT,_Traits,_Allocator> | |
526da49c | 803 | operator+(_CharT __lhs, |
285b36d6 BK |
804 | const basic_string<_CharT,_Traits,_Allocator>& __rhs) |
805 | { return basic_string<_CharT,_Traits,_Allocator>(1, __lhs) += __rhs; } | |
806 | ||
807 | template<typename _CharT, typename _Traits, typename _Allocator> | |
808 | inline basic_string<_CharT,_Traits,_Allocator> | |
809 | operator+(const basic_string<_CharT,_Traits,_Allocator>& __lhs, | |
810 | const _CharT* __rhs) | |
526da49c | 811 | { |
285b36d6 | 812 | __glibcxx_check_string(__rhs); |
526da49c | 813 | return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs; |
285b36d6 BK |
814 | } |
815 | ||
816 | template<typename _CharT, typename _Traits, typename _Allocator> | |
817 | inline basic_string<_CharT,_Traits,_Allocator> | |
818 | operator+(const basic_string<_CharT,_Traits,_Allocator>& __lhs, | |
819 | _CharT __rhs) | |
820 | { return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs; } | |
821 | ||
822 | template<typename _CharT, typename _Traits, typename _Allocator> | |
526da49c | 823 | inline bool |
285b36d6 BK |
824 | operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs, |
825 | const basic_string<_CharT,_Traits,_Allocator>& __rhs) | |
826 | { return __lhs._M_base() == __rhs._M_base(); } | |
526da49c | 827 | |
285b36d6 BK |
828 | template<typename _CharT, typename _Traits, typename _Allocator> |
829 | inline bool | |
830 | operator==(const _CharT* __lhs, | |
831 | const basic_string<_CharT,_Traits,_Allocator>& __rhs) | |
832 | { | |
833 | __glibcxx_check_string(__lhs); | |
834 | return __lhs == __rhs._M_base(); | |
835 | } | |
836 | ||
837 | template<typename _CharT, typename _Traits, typename _Allocator> | |
838 | inline bool | |
839 | operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs, | |
840 | const _CharT* __rhs) | |
841 | { | |
842 | __glibcxx_check_string(__rhs); | |
843 | return __lhs._M_base() == __rhs; | |
844 | } | |
845 | ||
846 | template<typename _CharT, typename _Traits, typename _Allocator> | |
526da49c | 847 | inline bool |
285b36d6 BK |
848 | operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs, |
849 | const basic_string<_CharT,_Traits,_Allocator>& __rhs) | |
850 | { return __lhs._M_base() != __rhs._M_base(); } | |
526da49c | 851 | |
285b36d6 BK |
852 | template<typename _CharT, typename _Traits, typename _Allocator> |
853 | inline bool | |
854 | operator!=(const _CharT* __lhs, | |
855 | const basic_string<_CharT,_Traits,_Allocator>& __rhs) | |
856 | { | |
857 | __glibcxx_check_string(__lhs); | |
858 | return __lhs != __rhs._M_base(); | |
859 | } | |
860 | ||
861 | template<typename _CharT, typename _Traits, typename _Allocator> | |
862 | inline bool | |
863 | operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs, | |
864 | const _CharT* __rhs) | |
865 | { | |
866 | __glibcxx_check_string(__rhs); | |
867 | return __lhs._M_base() != __rhs; | |
868 | } | |
869 | ||
870 | template<typename _CharT, typename _Traits, typename _Allocator> | |
526da49c | 871 | inline bool |
285b36d6 BK |
872 | operator<(const basic_string<_CharT,_Traits,_Allocator>& __lhs, |
873 | const basic_string<_CharT,_Traits,_Allocator>& __rhs) | |
874 | { return __lhs._M_base() < __rhs._M_base(); } | |
526da49c | 875 | |
285b36d6 BK |
876 | template<typename _CharT, typename _Traits, typename _Allocator> |
877 | inline bool | |
878 | operator<(const _CharT* __lhs, | |
879 | const basic_string<_CharT,_Traits,_Allocator>& __rhs) | |
880 | { | |
881 | __glibcxx_check_string(__lhs); | |
882 | return __lhs < __rhs._M_base(); | |
883 | } | |
884 | ||
885 | template<typename _CharT, typename _Traits, typename _Allocator> | |
886 | inline bool | |
887 | operator<(const basic_string<_CharT,_Traits,_Allocator>& __lhs, | |
888 | const _CharT* __rhs) | |
889 | { | |
890 | __glibcxx_check_string(__rhs); | |
891 | return __lhs._M_base() < __rhs; | |
892 | } | |
893 | ||
894 | template<typename _CharT, typename _Traits, typename _Allocator> | |
526da49c | 895 | inline bool |
285b36d6 BK |
896 | operator<=(const basic_string<_CharT,_Traits,_Allocator>& __lhs, |
897 | const basic_string<_CharT,_Traits,_Allocator>& __rhs) | |
898 | { return __lhs._M_base() <= __rhs._M_base(); } | |
526da49c | 899 | |
285b36d6 BK |
900 | template<typename _CharT, typename _Traits, typename _Allocator> |
901 | inline bool | |
902 | operator<=(const _CharT* __lhs, | |
903 | const basic_string<_CharT,_Traits,_Allocator>& __rhs) | |
904 | { | |
905 | __glibcxx_check_string(__lhs); | |
906 | return __lhs <= __rhs._M_base(); | |
907 | } | |
908 | ||
909 | template<typename _CharT, typename _Traits, typename _Allocator> | |
910 | inline bool | |
911 | operator<=(const basic_string<_CharT,_Traits,_Allocator>& __lhs, | |
912 | const _CharT* __rhs) | |
913 | { | |
914 | __glibcxx_check_string(__rhs); | |
915 | return __lhs._M_base() <= __rhs; | |
916 | } | |
526da49c | 917 | |
285b36d6 | 918 | template<typename _CharT, typename _Traits, typename _Allocator> |
526da49c | 919 | inline bool |
285b36d6 BK |
920 | operator>=(const basic_string<_CharT,_Traits,_Allocator>& __lhs, |
921 | const basic_string<_CharT,_Traits,_Allocator>& __rhs) | |
922 | { return __lhs._M_base() >= __rhs._M_base(); } | |
526da49c | 923 | |
285b36d6 BK |
924 | template<typename _CharT, typename _Traits, typename _Allocator> |
925 | inline bool | |
926 | operator>=(const _CharT* __lhs, | |
927 | const basic_string<_CharT,_Traits,_Allocator>& __rhs) | |
928 | { | |
929 | __glibcxx_check_string(__lhs); | |
930 | return __lhs >= __rhs._M_base(); | |
931 | } | |
526da49c | 932 | |
285b36d6 BK |
933 | template<typename _CharT, typename _Traits, typename _Allocator> |
934 | inline bool | |
935 | operator>=(const basic_string<_CharT,_Traits,_Allocator>& __lhs, | |
936 | const _CharT* __rhs) | |
937 | { | |
938 | __glibcxx_check_string(__rhs); | |
939 | return __lhs._M_base() >= __rhs; | |
940 | } | |
526da49c | 941 | |
285b36d6 | 942 | template<typename _CharT, typename _Traits, typename _Allocator> |
526da49c | 943 | inline bool |
285b36d6 BK |
944 | operator>(const basic_string<_CharT,_Traits,_Allocator>& __lhs, |
945 | const basic_string<_CharT,_Traits,_Allocator>& __rhs) | |
946 | { return __lhs._M_base() > __rhs._M_base(); } | |
526da49c | 947 | |
285b36d6 BK |
948 | template<typename _CharT, typename _Traits, typename _Allocator> |
949 | inline bool | |
950 | operator>(const _CharT* __lhs, | |
951 | const basic_string<_CharT,_Traits,_Allocator>& __rhs) | |
952 | { | |
953 | __glibcxx_check_string(__lhs); | |
954 | return __lhs > __rhs._M_base(); | |
955 | } | |
956 | ||
957 | template<typename _CharT, typename _Traits, typename _Allocator> | |
958 | inline bool | |
959 | operator>(const basic_string<_CharT,_Traits,_Allocator>& __lhs, | |
960 | const _CharT* __rhs) | |
961 | { | |
962 | __glibcxx_check_string(__rhs); | |
963 | return __lhs._M_base() > __rhs; | |
964 | } | |
965 | ||
966 | // 21.3.7.8: | |
967 | template<typename _CharT, typename _Traits, typename _Allocator> | |
526da49c | 968 | inline void |
285b36d6 BK |
969 | swap(basic_string<_CharT,_Traits,_Allocator>& __lhs, |
970 | basic_string<_CharT,_Traits,_Allocator>& __rhs) | |
971 | { __lhs.swap(__rhs); } | |
972 | ||
973 | template<typename _CharT, typename _Traits, typename _Allocator> | |
974 | std::basic_ostream<_CharT, _Traits>& | |
975 | operator<<(std::basic_ostream<_CharT, _Traits>& __os, | |
976 | const basic_string<_CharT, _Traits, _Allocator>& __str) | |
977 | { return __os << __str._M_base(); } | |
978 | ||
979 | template<typename _CharT, typename _Traits, typename _Allocator> | |
980 | std::basic_istream<_CharT,_Traits>& | |
981 | operator>>(std::basic_istream<_CharT,_Traits>& __is, | |
982 | basic_string<_CharT,_Traits,_Allocator>& __str) | |
983 | { | |
984 | std::basic_istream<_CharT,_Traits>& __res = __is >> __str._M_base(); | |
985 | __str._M_invalidate_all(); | |
986 | return __res; | |
987 | } | |
988 | ||
989 | template<typename _CharT, typename _Traits, typename _Allocator> | |
990 | std::basic_istream<_CharT,_Traits>& | |
991 | getline(std::basic_istream<_CharT,_Traits>& __is, | |
992 | basic_string<_CharT,_Traits,_Allocator>& __str, _CharT __delim) | |
993 | { | |
526da49c | 994 | std::basic_istream<_CharT,_Traits>& __res = getline(__is, |
285b36d6 BK |
995 | __str._M_base(), |
996 | __delim); | |
997 | __str._M_invalidate_all(); | |
998 | return __res; | |
999 | } | |
526da49c | 1000 | |
285b36d6 BK |
1001 | template<typename _CharT, typename _Traits, typename _Allocator> |
1002 | std::basic_istream<_CharT,_Traits>& | |
1003 | getline(std::basic_istream<_CharT,_Traits>& __is, | |
1004 | basic_string<_CharT,_Traits,_Allocator>& __str) | |
1005 | { | |
526da49c | 1006 | std::basic_istream<_CharT,_Traits>& __res = getline(__is, |
285b36d6 BK |
1007 | __str._M_base()); |
1008 | __str._M_invalidate_all(); | |
1009 | return __res; | |
1010 | } | |
561e7a36 PC |
1011 | |
1012 | typedef basic_string<char> string; | |
1013 | ||
1014 | #ifdef _GLIBCXX_USE_WCHAR_T | |
1015 | typedef basic_string<wchar_t> wstring; | |
1016 | #endif | |
1017 | ||
285b36d6 | 1018 | } // namespace __gnu_debug |
3cbc7af0 | 1019 | } // namespace std |
285b36d6 | 1020 | |
526da49c | 1021 | #endif |