Branch data Line data Source code
1 : : // Components for manipulating sequences of characters -*- C++ -*-
2 : :
3 : : // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
4 : : // 2006, 2007, 2008
5 : : // Free Software Foundation, Inc.
6 : : //
7 : : // This file is part of the GNU ISO C++ Library. This library is free
8 : : // software; you can redistribute it and/or modify it under the
9 : : // terms of the GNU General Public License as published by the
10 : : // Free Software Foundation; either version 2, or (at your option)
11 : : // any later version.
12 : :
13 : : // This library is distributed in the hope that it will be useful,
14 : : // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 : : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 : : // GNU General Public License for more details.
17 : :
18 : : // You should have received a copy of the GNU General Public License along
19 : : // with this library; see the file COPYING. If not, write to the Free
20 : : // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
21 : : // USA.
22 : :
23 : : // As a special exception, you may use this file as part of a free software
24 : : // library without restriction. Specifically, if other files instantiate
25 : : // templates or use macros or inline functions from this file, or you compile
26 : : // this file and link it with other files to produce an executable, this
27 : : // file does not by itself cause the resulting executable to be covered by
28 : : // the GNU General Public License. This exception does not however
29 : : // invalidate any other reasons why the executable file might be covered by
30 : : // the GNU General Public License.
31 : :
32 : : /** @file basic_string.h
33 : : * This is an internal header file, included by other library headers.
34 : : * You should not attempt to use it directly.
35 : : */
36 : :
37 : : //
38 : : // ISO C++ 14882: 21 Strings library
39 : : //
40 : :
41 : : #ifndef _BASIC_STRING_H
42 : : #define _BASIC_STRING_H 1
43 : :
44 : : #pragma GCC system_header
45 : :
46 : : #include <ext/atomicity.h>
47 : : #include <debug/debug.h>
48 : :
49 : : _GLIBCXX_BEGIN_NAMESPACE(std)
50 : :
51 : : /**
52 : : * @class basic_string basic_string.h <string>
53 : : * @brief Managing sequences of characters and character-like objects.
54 : : *
55 : : * @ingroup Containers
56 : : * @ingroup Sequences
57 : : *
58 : : * Meets the requirements of a <a href="tables.html#65">container</a>, a
59 : : * <a href="tables.html#66">reversible container</a>, and a
60 : : * <a href="tables.html#67">sequence</a>. Of the
61 : : * <a href="tables.html#68">optional sequence requirements</a>, only
62 : : * @c push_back, @c at, and array access are supported.
63 : : *
64 : : * @doctodo
65 : : *
66 : : *
67 : : * Documentation? What's that?
68 : : * Nathan Myers <ncm@cantrip.org>.
69 : : *
70 : : * A string looks like this:
71 : : *
72 : : * @code
73 : : * [_Rep]
74 : : * _M_length
75 : : * [basic_string<char_type>] _M_capacity
76 : : * _M_dataplus _M_refcount
77 : : * _M_p ----------------> unnamed array of char_type
78 : : * @endcode
79 : : *
80 : : * Where the _M_p points to the first character in the string, and
81 : : * you cast it to a pointer-to-_Rep and subtract 1 to get a
82 : : * pointer to the header.
83 : : *
84 : : * This approach has the enormous advantage that a string object
85 : : * requires only one allocation. All the ugliness is confined
86 : : * within a single pair of inline functions, which each compile to
87 : : * a single "add" instruction: _Rep::_M_data(), and
88 : : * string::_M_rep(); and the allocation function which gets a
89 : : * block of raw bytes and with room enough and constructs a _Rep
90 : : * object at the front.
91 : : *
92 : : * The reason you want _M_data pointing to the character array and
93 : : * not the _Rep is so that the debugger can see the string
94 : : * contents. (Probably we should add a non-inline member to get
95 : : * the _Rep for the debugger to use, so users can check the actual
96 : : * string length.)
97 : : *
98 : : * Note that the _Rep object is a POD so that you can have a
99 : : * static "empty string" _Rep object already "constructed" before
100 : : * static constructors have run. The reference-count encoding is
101 : : * chosen so that a 0 indicates one reference, so you never try to
102 : : * destroy the empty-string _Rep object.
103 : : *
104 : : * All but the last paragraph is considered pretty conventional
105 : : * for a C++ string implementation.
106 : : */
107 : : // 21.3 Template class basic_string
108 : : template<typename _CharT, typename _Traits, typename _Alloc>
109 : : class basic_string
110 : : {
111 : : typedef typename _Alloc::template rebind<_CharT>::other _CharT_alloc_type;
112 : :
113 : : // Types:
114 : : public:
115 : : typedef _Traits traits_type;
116 : : typedef typename _Traits::char_type value_type;
117 : : typedef _Alloc allocator_type;
118 : : typedef typename _CharT_alloc_type::size_type size_type;
119 : : typedef typename _CharT_alloc_type::difference_type difference_type;
120 : : typedef typename _CharT_alloc_type::reference reference;
121 : : typedef typename _CharT_alloc_type::const_reference const_reference;
122 : : typedef typename _CharT_alloc_type::pointer pointer;
123 : : typedef typename _CharT_alloc_type::const_pointer const_pointer;
124 : : typedef __gnu_cxx::__normal_iterator<pointer, basic_string> iterator;
125 : : typedef __gnu_cxx::__normal_iterator<const_pointer, basic_string>
126 : : const_iterator;
127 : : typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
128 : : typedef std::reverse_iterator<iterator> reverse_iterator;
129 : :
130 : : private:
131 : : // _Rep: string representation
132 : : // Invariants:
133 : : // 1. String really contains _M_length + 1 characters: due to 21.3.4
134 : : // must be kept null-terminated.
135 : : // 2. _M_capacity >= _M_length
136 : : // Allocated memory is always (_M_capacity + 1) * sizeof(_CharT).
137 : : // 3. _M_refcount has three states:
138 : : // -1: leaked, one reference, no ref-copies allowed, non-const.
139 : : // 0: one reference, non-const.
140 : : // n>0: n + 1 references, operations require a lock, const.
141 : : // 4. All fields==0 is an empty string, given the extra storage
142 : : // beyond-the-end for a null terminator; thus, the shared
143 : : // empty string representation needs no constructor.
144 : :
145 : : struct _Rep_base
146 : : {
147 : : size_type _M_length;
148 : : size_type _M_capacity;
149 : : _Atomic_word _M_refcount;
150 : : };
151 : :
152 : : struct _Rep : _Rep_base
153 : : {
154 : : // Types:
155 : : typedef typename _Alloc::template rebind<char>::other _Raw_bytes_alloc;
156 : :
157 : : // (Public) Data members:
158 : :
159 : : // The maximum number of individual char_type elements of an
160 : : // individual string is determined by _S_max_size. This is the
161 : : // value that will be returned by max_size(). (Whereas npos
162 : : // is the maximum number of bytes the allocator can allocate.)
163 : : // If one was to divvy up the theoretical largest size string,
164 : : // with a terminating character and m _CharT elements, it'd
165 : : // look like this:
166 : : // npos = sizeof(_Rep) + (m * sizeof(_CharT)) + sizeof(_CharT)
167 : : // Solving for m:
168 : : // m = ((npos - sizeof(_Rep))/sizeof(CharT)) - 1
169 : : // In addition, this implementation quarters this amount.
170 : : static const size_type _S_max_size;
171 : : static const _CharT _S_terminal;
172 : :
173 : : // The following storage is init'd to 0 by the linker, resulting
174 : : // (carefully) in an empty string with one reference.
175 : : static size_type _S_empty_rep_storage[];
176 : :
177 : : static _Rep&
178 : : _S_empty_rep()
179 : : {
180 : : // NB: Mild hack to avoid strict-aliasing warnings. Note that
181 : : // _S_empty_rep_storage is never modified and the punning should
182 : : // be reasonably safe in this case.
183 : 635702 : void* __p = reinterpret_cast<void*>(&_S_empty_rep_storage);
184 : 635702 : return *reinterpret_cast<_Rep*>(__p);
185 : : }
186 : :
187 : : bool
188 : : _M_is_leaked() const
189 : 104196 : { return this->_M_refcount < 0; }
190 : :
191 : : bool
192 : : _M_is_shared() const
193 : 140705 : { return this->_M_refcount > 0; }
194 : :
195 : : void
196 : : _M_set_leaked()
197 : 30792 : { this->_M_refcount = -1; }
198 : :
199 : : void
200 : : _M_set_sharable()
201 : 427291 : { this->_M_refcount = 0; }
202 : :
203 : : void
204 : : _M_set_length_and_sharable(size_type __n)
205 : : {
206 : : this->_M_set_sharable(); // One reference.
207 : 427291 : this->_M_length = __n;
208 : 427291 : traits_type::assign(this->_M_refdata()[__n], _S_terminal);
209 : : // grrr. (per 21.3.4)
210 : : // You cannot leave those LWG people alone for a second.
211 : : }
212 : :
213 : : _CharT*
214 : : _M_refdata() throw()
215 : 1666220 : { return reinterpret_cast<_CharT*>(this + 1); }
216 : :
217 : : _CharT*
218 : 73179 : _M_grab(const _Alloc& __alloc1, const _Alloc& __alloc2)
219 : : {
220 : : return (!_M_is_leaked() && __alloc1 == __alloc2)
221 [ + + ][ + - ]: 73179 : ? _M_refcopy() : _M_clone(__alloc1);
222 : : }
223 : :
224 : : // Create & Destroy
225 : : static _Rep*
226 : : _S_create(size_type, size_type, const _Alloc&);
227 : :
228 : : void
229 : 565077 : _M_dispose(const _Alloc& __a)
230 : : {
231 [ + + ]: 565077 : if (__gnu_cxx::__exchange_and_add_dispatch(&this->_M_refcount, -1) <= 0)
232 : : _M_destroy(__a);
233 : 565077 : } // XXX MT
234 : :
235 : : void
236 : : _M_destroy(const _Alloc&) throw();
237 : :
238 : : _CharT*
239 : 0 : _M_refcopy() throw()
240 : : {
241 : 708033 : __gnu_cxx::__atomic_add_dispatch(&this->_M_refcount, 1);
242 : 708033 : return _M_refdata();
243 : : } // XXX MT
244 : :
245 : : _CharT*
246 : : _M_clone(const _Alloc&, size_type __res = 0);
247 : : };
248 : :
249 : : // Use empty-base optimization: http://www.cantrip.org/emptyopt.html
250 : : struct _Alloc_hider : _Alloc
251 : 565070 : {
252 : : _Alloc_hider(_CharT* __dat, const _Alloc& __a)
253 : 1946970 : : _Alloc(__a), _M_p(__dat) { }
254 : :
255 : : _CharT* _M_p; // The actual data.
256 : : };
257 : :
258 : : public:
259 : : // Data Members (public):
260 : : // NB: This is an unsigned type, and thus represents the maximum
261 : : // size that the allocator can hold.
262 : : /// Value returned by various member functions when they fail.
263 : : static const size_type npos = static_cast<size_type>(-1);
264 : :
265 : : private:
266 : : // Data Members (private):
267 : : mutable _Alloc_hider _M_dataplus;
268 : :
269 : : _CharT*
270 : : _M_data() const
271 : 4924393 : { return _M_dataplus._M_p; }
272 : :
273 : : _CharT*
274 : : _M_data(_CharT* __p)
275 : 7 : { return (_M_dataplus._M_p = __p); }
276 : :
277 : : _Rep*
278 : : _M_rep() const
279 : 3222141 : { return &((reinterpret_cast<_Rep*> (_M_data()))[-1]); }
280 : :
281 : : // For the internal use we have functions similar to `begin'/`end'
282 : : // but they do not call _M_leak.
283 : : iterator
284 : : _M_ibegin() const
285 : : { return iterator(_M_data()); }
286 : :
287 : : iterator
288 : : _M_iend() const
289 : : { return iterator(_M_data() + this->size()); }
290 : :
291 : : void
292 : 31017 : _M_leak() // for use in begin() & non-const op[]
293 : : {
294 [ + + ]: 31017 : if (!_M_rep()->_M_is_leaked())
295 : 30792 : _M_leak_hard();
296 : 31017 : }
297 : :
298 : : size_type
299 : 28005 : _M_check(size_type __pos, const char* __s) const
300 : : {
301 [ - + ]: 28005 : if (__pos > this->size())
302 : 0 : __throw_out_of_range(__N(__s));
303 : 28005 : return __pos;
304 : : }
305 : :
306 : : void
307 : 0 : _M_check_length(size_type __n1, size_type __n2, const char* __s) const
308 : : {
309 [ # # ]: 0 : if (this->max_size() - (this->size() - __n1) < __n2)
310 : 0 : __throw_length_error(__N(__s));
311 : 0 : }
312 : :
313 : : // NB: _M_limit doesn't check for a bad __pos value.
314 : : size_type
315 : : _M_limit(size_type __pos, size_type __off) const
316 : : {
317 : 25459 : const bool __testoff = __off < this->size() - __pos;
318 [ + + ][ + - ]: 25459 : return __testoff ? __off : this->size() - __pos;
[ # # ][ + - ]
[ + + ]
319 : : }
320 : :
321 : : // True if _Rep and source do not overlap.
322 : : bool
323 : : _M_disjunct(const _CharT* __s) const
324 : : {
325 : : return (less<const _CharT*>()(__s, _M_data())
326 [ # # ][ # # ]: 0 : || less<const _CharT*>()(_M_data() + this->size(), __s));
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
327 : : }
328 : :
329 : : // When __n = 1 way faster than the general multichar
330 : : // traits_type::copy/move/assign.
331 : : static void
332 : : _M_copy(_CharT* __d, const _CharT* __s, size_type __n)
333 : : {
334 [ + + ][ + + ]: 390493 : if (__n == 1)
[ + + ][ + + ]
[ - + ][ - + ]
[ # # ][ - + ]
[ # # ][ # # ]
[ # # ]
335 : : traits_type::assign(*__d, *__s);
336 : : else
337 : : traits_type::copy(__d, __s, __n);
338 : : }
339 : :
340 : : static void
341 : : _M_move(_CharT* __d, const _CharT* __s, size_type __n)
342 : : {
343 [ # # ][ # # ]: 0 : if (__n == 1)
344 : : traits_type::assign(*__d, *__s);
345 : : else
346 : : traits_type::move(__d, __s, __n);
347 : : }
348 : :
349 : : static void
350 : : _M_assign(_CharT* __d, size_type __n, _CharT __c)
351 : : {
352 : : if (__n == 1)
353 : : traits_type::assign(*__d, __c);
354 : : else
355 : : traits_type::assign(__d, __n, __c);
356 : : }
357 : :
358 : : // _S_copy_chars is a separate template to permit specialization
359 : : // to optimize for the common case of pointers as iterators.
360 : : template<class _Iterator>
361 : : static void
362 : : _S_copy_chars(_CharT* __p, _Iterator __k1, _Iterator __k2)
363 : : {
364 : : for (; __k1 != __k2; ++__k1, ++__p)
365 : : traits_type::assign(*__p, *__k1); // These types are off.
366 : : }
367 : :
368 : : static void
369 : : _S_copy_chars(_CharT* __p, iterator __k1, iterator __k2)
370 : : { _S_copy_chars(__p, __k1.base(), __k2.base()); }
371 : :
372 : : static void
373 : : _S_copy_chars(_CharT* __p, const_iterator __k1, const_iterator __k2)
374 : : { _S_copy_chars(__p, __k1.base(), __k2.base()); }
375 : :
376 : : static void
377 : 251289 : _S_copy_chars(_CharT* __p, _CharT* __k1, _CharT* __k2)
378 : 251289 : { _M_copy(__p, __k1, __k2 - __k1); }
379 : :
380 : : static void
381 : 13322 : _S_copy_chars(_CharT* __p, const _CharT* __k1, const _CharT* __k2)
382 : 13322 : { _M_copy(__p, __k1, __k2 - __k1); }
383 : :
384 : : static int
385 : : _S_compare(size_type __n1, size_type __n2)
386 : : {
387 : 387953 : const difference_type __d = difference_type(__n1 - __n2);
388 : :
389 : : if (__d > __gnu_cxx::__numeric_traits<int>::__max)
390 : : return __gnu_cxx::__numeric_traits<int>::__max;
391 : : else if (__d < __gnu_cxx::__numeric_traits<int>::__min)
392 : : return __gnu_cxx::__numeric_traits<int>::__min;
393 : : else
394 : 387953 : return int(__d);
395 : : }
396 : :
397 : : void
398 : : _M_mutate(size_type __pos, size_type __len1, size_type __len2);
399 : :
400 : : void
401 : : _M_leak_hard();
402 : :
403 : : static _Rep&
404 : : _S_empty_rep()
405 : 635702 : { return _Rep::_S_empty_rep(); }
406 : :
407 : : public:
408 : : // Construct/copy/destroy:
409 : : // NB: We overload ctors in some cases instead of using default
410 : : // arguments, per 17.4.4.4 para. 2 item 2.
411 : :
412 : : /**
413 : : * @brief Default constructor creates an empty string.
414 : : */
415 : : inline
416 : : basic_string();
417 : :
418 : : /**
419 : : * @brief Construct an empty string using allocator @a a.
420 : : */
421 : : explicit
422 : : basic_string(const _Alloc& __a);
423 : :
424 : : // NB: per LWG issue 42, semantics different from IS:
425 : : /**
426 : : * @brief Construct string with copy of value of @a str.
427 : : * @param str Source string.
428 : : */
429 : : basic_string(const basic_string& __str);
430 : : /**
431 : : * @brief Construct string as copy of a substring.
432 : : * @param str Source string.
433 : : * @param pos Index of first character to copy from.
434 : : * @param n Number of characters to copy (default remainder).
435 : : */
436 : : basic_string(const basic_string& __str, size_type __pos,
437 : : size_type __n = npos);
438 : : /**
439 : : * @brief Construct string as copy of a substring.
440 : : * @param str Source string.
441 : : * @param pos Index of first character to copy from.
442 : : * @param n Number of characters to copy.
443 : : * @param a Allocator to use.
444 : : */
445 : : basic_string(const basic_string& __str, size_type __pos,
446 : : size_type __n, const _Alloc& __a);
447 : :
448 : : /**
449 : : * @brief Construct string initialized by a character array.
450 : : * @param s Source character array.
451 : : * @param n Number of characters to copy.
452 : : * @param a Allocator to use (default is default allocator).
453 : : *
454 : : * NB: @a s must have at least @a n characters, '\0' has no special
455 : : * meaning.
456 : : */
457 : : basic_string(const _CharT* __s, size_type __n,
458 : : const _Alloc& __a = _Alloc());
459 : : /**
460 : : * @brief Construct string as copy of a C string.
461 : : * @param s Source C string.
462 : : * @param a Allocator to use (default is default allocator).
463 : : */
464 : : basic_string(const _CharT* __s, const _Alloc& __a = _Alloc());
465 : : /**
466 : : * @brief Construct string as multiple characters.
467 : : * @param n Number of characters.
468 : : * @param c Character to use.
469 : : * @param a Allocator to use (default is default allocator).
470 : : */
471 : : basic_string(size_type __n, _CharT __c, const _Alloc& __a = _Alloc());
472 : :
473 : : /**
474 : : * @brief Construct string as copy of a range.
475 : : * @param beg Start of range.
476 : : * @param end End of range.
477 : : * @param a Allocator to use (default is default allocator).
478 : : */
479 : : template<class _InputIterator>
480 : : basic_string(_InputIterator __beg, _InputIterator __end,
481 : : const _Alloc& __a = _Alloc());
482 : :
483 : : /**
484 : : * @brief Destroy the string instance.
485 : : */
486 : 565070 : ~basic_string()
487 : 1130140 : { _M_rep()->_M_dispose(this->get_allocator()); }
488 : :
489 : : /**
490 : : * @brief Assign the value of @a str to this string.
491 : : * @param str Source string.
492 : : */
493 : : basic_string&
494 : : operator=(const basic_string& __str)
495 : 300723 : { return this->assign(__str); }
496 : :
497 : : /**
498 : : * @brief Copy contents of @a s into this string.
499 : : * @param s Source null-terminated string.
500 : : */
501 : : basic_string&
502 : : operator=(const _CharT* __s)
503 : 2870 : { return this->assign(__s); }
504 : :
505 : : /**
506 : : * @brief Set value to string of length 1.
507 : : * @param c Source character.
508 : : *
509 : : * Assigning to a character makes this string length 1 and
510 : : * (*this)[0] == @a c.
511 : : */
512 : : basic_string&
513 : : operator=(_CharT __c)
514 : : {
515 : : this->assign(1, __c);
516 : : return *this;
517 : : }
518 : :
519 : : // Iterators:
520 : : /**
521 : : * Returns a read/write iterator that points to the first character in
522 : : * the %string. Unshares the string.
523 : : */
524 : : iterator
525 : : begin()
526 : : {
527 : : _M_leak();
528 : : return iterator(_M_data());
529 : : }
530 : :
531 : : /**
532 : : * Returns a read-only (constant) iterator that points to the first
533 : : * character in the %string.
534 : : */
535 : : const_iterator
536 : : begin() const
537 : : { return const_iterator(_M_data()); }
538 : :
539 : : /**
540 : : * Returns a read/write iterator that points one past the last
541 : : * character in the %string. Unshares the string.
542 : : */
543 : : iterator
544 : : end()
545 : : {
546 : : _M_leak();
547 : : return iterator(_M_data() + this->size());
548 : : }
549 : :
550 : : /**
551 : : * Returns a read-only (constant) iterator that points one past the
552 : : * last character in the %string.
553 : : */
554 : : const_iterator
555 : : end() const
556 : : { return const_iterator(_M_data() + this->size()); }
557 : :
558 : : /**
559 : : * Returns a read/write reverse iterator that points to the last
560 : : * character in the %string. Iteration is done in reverse element
561 : : * order. Unshares the string.
562 : : */
563 : : reverse_iterator
564 : : rbegin()
565 : : { return reverse_iterator(this->end()); }
566 : :
567 : : /**
568 : : * Returns a read-only (constant) reverse iterator that points
569 : : * to the last character in the %string. Iteration is done in
570 : : * reverse element order.
571 : : */
572 : : const_reverse_iterator
573 : : rbegin() const
574 : : { return const_reverse_iterator(this->end()); }
575 : :
576 : : /**
577 : : * Returns a read/write reverse iterator that points to one before the
578 : : * first character in the %string. Iteration is done in reverse
579 : : * element order. Unshares the string.
580 : : */
581 : : reverse_iterator
582 : : rend()
583 : : { return reverse_iterator(this->begin()); }
584 : :
585 : : /**
586 : : * Returns a read-only (constant) reverse iterator that points
587 : : * to one before the first character in the %string. Iteration
588 : : * is done in reverse element order.
589 : : */
590 : : const_reverse_iterator
591 : : rend() const
592 : : { return const_reverse_iterator(this->begin()); }
593 : :
594 : : public:
595 : : // Capacity:
596 : : /// Returns the number of characters in the string, not including any
597 : : /// null-termination.
598 : : size_type
599 : : size() const
600 [ - + ][ # # ]: 2051084 : { return _M_rep()->_M_length; }
[ # # ][ - + ]
601 : :
602 : : /// Returns the number of characters in the string, not including any
603 : : /// null-termination.
604 : : size_type
605 : : length() const
606 : 6060 : { return _M_rep()->_M_length; }
607 : :
608 : : /// Returns the size() of the largest possible %string.
609 : : size_type
610 : : max_size() const
611 : 0 : { return _Rep::_S_max_size; }
612 : :
613 : : /**
614 : : * @brief Resizes the %string to the specified number of characters.
615 : : * @param n Number of characters the %string should contain.
616 : : * @param c Character to fill any new elements.
617 : : *
618 : : * This function will %resize the %string to the specified
619 : : * number of characters. If the number is smaller than the
620 : : * %string's current size the %string is truncated, otherwise
621 : : * the %string is extended and new elements are set to @a c.
622 : : */
623 : : void
624 : : resize(size_type __n, _CharT __c);
625 : :
626 : : /**
627 : : * @brief Resizes the %string to the specified number of characters.
628 : : * @param n Number of characters the %string should contain.
629 : : *
630 : : * This function will resize the %string to the specified length. If
631 : : * the new size is smaller than the %string's current size the %string
632 : : * is truncated, otherwise the %string is extended and new characters
633 : : * are default-constructed. For basic types such as char, this means
634 : : * setting them to 0.
635 : : */
636 : : void
637 : : resize(size_type __n)
638 : : { this->resize(__n, _CharT()); }
639 : :
640 : : /**
641 : : * Returns the total number of characters that the %string can hold
642 : : * before needing to allocate more memory.
643 : : */
644 : : size_type
645 : : capacity() const
646 : 161843 : { return _M_rep()->_M_capacity; }
647 : :
648 : : /**
649 : : * @brief Attempt to preallocate enough memory for specified number of
650 : : * characters.
651 : : * @param res_arg Number of characters required.
652 : : * @throw std::length_error If @a res_arg exceeds @c max_size().
653 : : *
654 : : * This function attempts to reserve enough memory for the
655 : : * %string to hold the specified number of characters. If the
656 : : * number requested is more than max_size(), length_error is
657 : : * thrown.
658 : : *
659 : : * The advantage of this function is that if optimal code is a
660 : : * necessity and the user can determine the string length that will be
661 : : * required, the user can reserve the memory in %advance, and thus
662 : : * prevent a possible reallocation of memory and copying of %string
663 : : * data.
664 : : */
665 : : void
666 : : reserve(size_type __res_arg = 0);
667 : :
668 : : /**
669 : : * Erases the string, making it empty.
670 : : */
671 : : void
672 : : clear()
673 : : { _M_mutate(0, this->size(), 0); }
674 : :
675 : : /**
676 : : * Returns true if the %string is empty. Equivalent to *this == "".
677 : : */
678 : : bool
679 : : empty() const
680 : 3163 : { return this->size() == 0; }
681 : :
682 : : // Element access:
683 : : /**
684 : : * @brief Subscript access to the data contained in the %string.
685 : : * @param pos The index of the character to access.
686 : : * @return Read-only (constant) reference to the character.
687 : : *
688 : : * This operator allows for easy, array-style, data access.
689 : : * Note that data access with this operator is unchecked and
690 : : * out_of_range lookups are not defined. (For checked lookups
691 : : * see at().)
692 : : */
693 : : const_reference
694 : : operator[] (size_type __pos) const
695 : : {
696 : : _GLIBCXX_DEBUG_ASSERT(__pos <= size());
697 : 122561 : return _M_data()[__pos];
698 : : }
699 : :
700 : : /**
701 : : * @brief Subscript access to the data contained in the %string.
702 : : * @param pos The index of the character to access.
703 : : * @return Read/write reference to the character.
704 : : *
705 : : * This operator allows for easy, array-style, data access.
706 : : * Note that data access with this operator is unchecked and
707 : : * out_of_range lookups are not defined. (For checked lookups
708 : : * see at().) Unshares the string.
709 : : */
710 : : reference
711 : : operator[](size_type __pos)
712 : : {
713 : : // allow pos == size() as v3 extension:
714 : : _GLIBCXX_DEBUG_ASSERT(__pos <= size());
715 : : // but be strict in pedantic mode:
716 : : _GLIBCXX_DEBUG_PEDASSERT(__pos < size());
717 : 30976 : _M_leak();
718 : 31017 : return _M_data()[__pos];
719 : : }
720 : :
721 : : /**
722 : : * @brief Provides access to the data contained in the %string.
723 : : * @param n The index of the character to access.
724 : : * @return Read-only (const) reference to the character.
725 : : * @throw std::out_of_range If @a n is an invalid index.
726 : : *
727 : : * This function provides for safer data access. The parameter is
728 : : * first checked that it is in the range of the string. The function
729 : : * throws out_of_range if the check fails.
730 : : */
731 : : const_reference
732 : : at(size_type __n) const
733 : : {
734 : : if (__n >= this->size())
735 : : __throw_out_of_range(__N("basic_string::at"));
736 : : return _M_data()[__n];
737 : : }
738 : :
739 : : /**
740 : : * @brief Provides access to the data contained in the %string.
741 : : * @param n The index of the character to access.
742 : : * @return Read/write reference to the character.
743 : : * @throw std::out_of_range If @a n is an invalid index.
744 : : *
745 : : * This function provides for safer data access. The parameter is
746 : : * first checked that it is in the range of the string. The function
747 : : * throws out_of_range if the check fails. Success results in
748 : : * unsharing the string.
749 : : */
750 : : reference
751 : : at(size_type __n)
752 : : {
753 : : if (__n >= size())
754 : : __throw_out_of_range(__N("basic_string::at"));
755 : : _M_leak();
756 : : return _M_data()[__n];
757 : : }
758 : :
759 : : // Modifiers:
760 : : /**
761 : : * @brief Append a string to this string.
762 : : * @param str The string to append.
763 : : * @return Reference to this string.
764 : : */
765 : : basic_string&
766 : : operator+=(const basic_string& __str)
767 : 126448 : { return this->append(__str); }
768 : :
769 : : /**
770 : : * @brief Append a C string.
771 : : * @param s The C string to append.
772 : : * @return Reference to this string.
773 : : */
774 : : basic_string&
775 : : operator+=(const _CharT* __s)
776 : 7334 : { return this->append(__s); }
777 : :
778 : : /**
779 : : * @brief Append a character.
780 : : * @param c The character to append.
781 : : * @return Reference to this string.
782 : : */
783 : : basic_string&
784 : : operator+=(_CharT __c)
785 : : {
786 : 36798 : this->push_back(__c);
787 : 36798 : return *this;
788 : : }
789 : :
790 : : /**
791 : : * @brief Append a string to this string.
792 : : * @param str The string to append.
793 : : * @return Reference to this string.
794 : : */
795 : : basic_string&
796 : : append(const basic_string& __str);
797 : :
798 : : /**
799 : : * @brief Append a substring.
800 : : * @param str The string to append.
801 : : * @param pos Index of the first character of str to append.
802 : : * @param n The number of characters to append.
803 : : * @return Reference to this string.
804 : : * @throw std::out_of_range if @a pos is not a valid index.
805 : : *
806 : : * This function appends @a n characters from @a str starting at @a pos
807 : : * to this string. If @a n is is larger than the number of available
808 : : * characters in @a str, the remainder of @a str is appended.
809 : : */
810 : : basic_string&
811 : : append(const basic_string& __str, size_type __pos, size_type __n);
812 : :
813 : : /**
814 : : * @brief Append a C substring.
815 : : * @param s The C string to append.
816 : : * @param n The number of characters to append.
817 : : * @return Reference to this string.
818 : : */
819 : : basic_string&
820 : : append(const _CharT* __s, size_type __n);
821 : :
822 : : /**
823 : : * @brief Append a C string.
824 : : * @param s The C string to append.
825 : : * @return Reference to this string.
826 : : */
827 : : basic_string&
828 : 8978 : append(const _CharT* __s)
829 : : {
830 : : __glibcxx_requires_string(__s);
831 : 8978 : return this->append(__s, traits_type::length(__s));
832 : : }
833 : :
834 : : /**
835 : : * @brief Append multiple characters.
836 : : * @param n The number of characters to append.
837 : : * @param c The character to use.
838 : : * @return Reference to this string.
839 : : *
840 : : * Appends n copies of c to this string.
841 : : */
842 : : basic_string&
843 : : append(size_type __n, _CharT __c);
844 : :
845 : : /**
846 : : * @brief Append a range of characters.
847 : : * @param first Iterator referencing the first character to append.
848 : : * @param last Iterator marking the end of the range.
849 : : * @return Reference to this string.
850 : : *
851 : : * Appends characters in the range [first,last) to this string.
852 : : */
853 : : template<class _InputIterator>
854 : : basic_string&
855 : : append(_InputIterator __first, _InputIterator __last)
856 : : { return this->replace(_M_iend(), _M_iend(), __first, __last); }
857 : :
858 : : /**
859 : : * @brief Append a single character.
860 : : * @param c Character to append.
861 : : */
862 : : void
863 : 36798 : push_back(_CharT __c)
864 : : {
865 : 36798 : const size_type __len = 1 + this->size();
866 [ + + ][ - + ]: 36798 : if (__len > this->capacity() || _M_rep()->_M_is_shared())
[ + + ]
867 : 17901 : this->reserve(__len);
868 : 36798 : traits_type::assign(_M_data()[this->size()], __c);
869 : : _M_rep()->_M_set_length_and_sharable(__len);
870 : 36798 : }
871 : :
872 : : /**
873 : : * @brief Set value to contents of another string.
874 : : * @param str Source string to use.
875 : : * @return Reference to this string.
876 : : */
877 : : basic_string&
878 : : assign(const basic_string& __str);
879 : :
880 : : /**
881 : : * @brief Set value to a substring of a string.
882 : : * @param str The string to use.
883 : : * @param pos Index of the first character of str.
884 : : * @param n Number of characters to use.
885 : : * @return Reference to this string.
886 : : * @throw std::out_of_range if @a pos is not a valid index.
887 : : *
888 : : * This function sets this string to the substring of @a str consisting
889 : : * of @a n characters at @a pos. If @a n is is larger than the number
890 : : * of available characters in @a str, the remainder of @a str is used.
891 : : */
892 : : basic_string&
893 : : assign(const basic_string& __str, size_type __pos, size_type __n)
894 : : { return this->assign(__str._M_data()
895 : : + __str._M_check(__pos, "basic_string::assign"),
896 : : __str._M_limit(__pos, __n)); }
897 : :
898 : : /**
899 : : * @brief Set value to a C substring.
900 : : * @param s The C string to use.
901 : : * @param n Number of characters to use.
902 : : * @return Reference to this string.
903 : : *
904 : : * This function sets the value of this string to the first @a n
905 : : * characters of @a s. If @a n is is larger than the number of
906 : : * available characters in @a s, the remainder of @a s is used.
907 : : */
908 : : basic_string&
909 : : assign(const _CharT* __s, size_type __n);
910 : :
911 : : /**
912 : : * @brief Set value to contents of a C string.
913 : : * @param s The C string to use.
914 : : * @return Reference to this string.
915 : : *
916 : : * This function sets the value of this string to the value of @a s.
917 : : * The data is copied, so there is no dependence on @a s once the
918 : : * function returns.
919 : : */
920 : : basic_string&
921 : 3951 : assign(const _CharT* __s)
922 : : {
923 : : __glibcxx_requires_string(__s);
924 : 3951 : return this->assign(__s, traits_type::length(__s));
925 : : }
926 : :
927 : : /**
928 : : * @brief Set value to multiple characters.
929 : : * @param n Length of the resulting string.
930 : : * @param c The character to use.
931 : : * @return Reference to this string.
932 : : *
933 : : * This function sets the value of this string to @a n copies of
934 : : * character @a c.
935 : : */
936 : : basic_string&
937 : : assign(size_type __n, _CharT __c)
938 : : { return _M_replace_aux(size_type(0), this->size(), __n, __c); }
939 : :
940 : : /**
941 : : * @brief Set value to a range of characters.
942 : : * @param first Iterator referencing the first character to append.
943 : : * @param last Iterator marking the end of the range.
944 : : * @return Reference to this string.
945 : : *
946 : : * Sets value of string to characters in the range [first,last).
947 : : */
948 : : template<class _InputIterator>
949 : : basic_string&
950 : : assign(_InputIterator __first, _InputIterator __last)
951 : : { return this->replace(_M_ibegin(), _M_iend(), __first, __last); }
952 : :
953 : : /**
954 : : * @brief Insert multiple characters.
955 : : * @param p Iterator referencing location in string to insert at.
956 : : * @param n Number of characters to insert
957 : : * @param c The character to insert.
958 : : * @throw std::length_error If new length exceeds @c max_size().
959 : : *
960 : : * Inserts @a n copies of character @a c starting at the position
961 : : * referenced by iterator @a p. If adding characters causes the length
962 : : * to exceed max_size(), length_error is thrown. The value of the
963 : : * string doesn't change if an error is thrown.
964 : : */
965 : : void
966 : : insert(iterator __p, size_type __n, _CharT __c)
967 : : { this->replace(__p, __p, __n, __c); }
968 : :
969 : : /**
970 : : * @brief Insert a range of characters.
971 : : * @param p Iterator referencing location in string to insert at.
972 : : * @param beg Start of range.
973 : : * @param end End of range.
974 : : * @throw std::length_error If new length exceeds @c max_size().
975 : : *
976 : : * Inserts characters in range [beg,end). If adding characters causes
977 : : * the length to exceed max_size(), length_error is thrown. The value
978 : : * of the string doesn't change if an error is thrown.
979 : : */
980 : : template<class _InputIterator>
981 : : void
982 : : insert(iterator __p, _InputIterator __beg, _InputIterator __end)
983 : : { this->replace(__p, __p, __beg, __end); }
984 : :
985 : : /**
986 : : * @brief Insert value of a string.
987 : : * @param pos1 Iterator referencing location in string to insert at.
988 : : * @param str The string to insert.
989 : : * @return Reference to this string.
990 : : * @throw std::length_error If new length exceeds @c max_size().
991 : : *
992 : : * Inserts value of @a str starting at @a pos1. If adding characters
993 : : * causes the length to exceed max_size(), length_error is thrown. The
994 : : * value of the string doesn't change if an error is thrown.
995 : : */
996 : : basic_string&
997 : : insert(size_type __pos1, const basic_string& __str)
998 : : { return this->insert(__pos1, __str, size_type(0), __str.size()); }
999 : :
1000 : : /**
1001 : : * @brief Insert a substring.
1002 : : * @param pos1 Iterator referencing location in string to insert at.
1003 : : * @param str The string to insert.
1004 : : * @param pos2 Start of characters in str to insert.
1005 : : * @param n Number of characters to insert.
1006 : : * @return Reference to this string.
1007 : : * @throw std::length_error If new length exceeds @c max_size().
1008 : : * @throw std::out_of_range If @a pos1 > size() or
1009 : : * @a pos2 > @a str.size().
1010 : : *
1011 : : * Starting at @a pos1, insert @a n character of @a str beginning with
1012 : : * @a pos2. If adding characters causes the length to exceed
1013 : : * max_size(), length_error is thrown. If @a pos1 is beyond the end of
1014 : : * this string or @a pos2 is beyond the end of @a str, out_of_range is
1015 : : * thrown. The value of the string doesn't change if an error is
1016 : : * thrown.
1017 : : */
1018 : : basic_string&
1019 : : insert(size_type __pos1, const basic_string& __str,
1020 : : size_type __pos2, size_type __n)
1021 : : { return this->insert(__pos1, __str._M_data()
1022 : : + __str._M_check(__pos2, "basic_string::insert"),
1023 : : __str._M_limit(__pos2, __n)); }
1024 : :
1025 : : /**
1026 : : * @brief Insert a C substring.
1027 : : * @param pos Iterator referencing location in string to insert at.
1028 : : * @param s The C string to insert.
1029 : : * @param n The number of characters to insert.
1030 : : * @return Reference to this string.
1031 : : * @throw std::length_error If new length exceeds @c max_size().
1032 : : * @throw std::out_of_range If @a pos is beyond the end of this
1033 : : * string.
1034 : : *
1035 : : * Inserts the first @a n characters of @a s starting at @a pos. If
1036 : : * adding characters causes the length to exceed max_size(),
1037 : : * length_error is thrown. If @a pos is beyond end(), out_of_range is
1038 : : * thrown. The value of the string doesn't change if an error is
1039 : : * thrown.
1040 : : */
1041 : : basic_string&
1042 : : insert(size_type __pos, const _CharT* __s, size_type __n);
1043 : :
1044 : : /**
1045 : : * @brief Insert a C string.
1046 : : * @param pos Iterator referencing location in string to insert at.
1047 : : * @param s The C string to insert.
1048 : : * @return Reference to this string.
1049 : : * @throw std::length_error If new length exceeds @c max_size().
1050 : : * @throw std::out_of_range If @a pos is beyond the end of this
1051 : : * string.
1052 : : *
1053 : : * Inserts the first @a n characters of @a s starting at @a pos. If
1054 : : * adding characters causes the length to exceed max_size(),
1055 : : * length_error is thrown. If @a pos is beyond end(), out_of_range is
1056 : : * thrown. The value of the string doesn't change if an error is
1057 : : * thrown.
1058 : : */
1059 : : basic_string&
1060 : : insert(size_type __pos, const _CharT* __s)
1061 : : {
1062 : : __glibcxx_requires_string(__s);
1063 : : return this->insert(__pos, __s, traits_type::length(__s));
1064 : : }
1065 : :
1066 : : /**
1067 : : * @brief Insert multiple characters.
1068 : : * @param pos Index in string to insert at.
1069 : : * @param n Number of characters to insert
1070 : : * @param c The character to insert.
1071 : : * @return Reference to this string.
1072 : : * @throw std::length_error If new length exceeds @c max_size().
1073 : : * @throw std::out_of_range If @a pos is beyond the end of this
1074 : : * string.
1075 : : *
1076 : : * Inserts @a n copies of character @a c starting at index @a pos. If
1077 : : * adding characters causes the length to exceed max_size(),
1078 : : * length_error is thrown. If @a pos > length(), out_of_range is
1079 : : * thrown. The value of the string doesn't change if an error is
1080 : : * thrown.
1081 : : */
1082 : : basic_string&
1083 : : insert(size_type __pos, size_type __n, _CharT __c)
1084 : : { return _M_replace_aux(_M_check(__pos, "basic_string::insert"),
1085 : : size_type(0), __n, __c); }
1086 : :
1087 : : /**
1088 : : * @brief Insert one character.
1089 : : * @param p Iterator referencing position in string to insert at.
1090 : : * @param c The character to insert.
1091 : : * @return Iterator referencing newly inserted char.
1092 : : * @throw std::length_error If new length exceeds @c max_size().
1093 : : *
1094 : : * Inserts character @a c at position referenced by @a p. If adding
1095 : : * character causes the length to exceed max_size(), length_error is
1096 : : * thrown. If @a p is beyond end of string, out_of_range is thrown.
1097 : : * The value of the string doesn't change if an error is thrown.
1098 : : */
1099 : : iterator
1100 : : insert(iterator __p, _CharT __c)
1101 : : {
1102 : : _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend());
1103 : : const size_type __pos = __p - _M_ibegin();
1104 : : _M_replace_aux(__pos, size_type(0), size_type(1), __c);
1105 : : _M_rep()->_M_set_leaked();
1106 : : return iterator(_M_data() + __pos);
1107 : : }
1108 : :
1109 : : /**
1110 : : * @brief Remove characters.
1111 : : * @param pos Index of first character to remove (default 0).
1112 : : * @param n Number of characters to remove (default remainder).
1113 : : * @return Reference to this string.
1114 : : * @throw std::out_of_range If @a pos is beyond the end of this
1115 : : * string.
1116 : : *
1117 : : * Removes @a n characters from this string starting at @a pos. The
1118 : : * length of the string is reduced by @a n. If there are < @a n
1119 : : * characters to remove, the remainder of the string is truncated. If
1120 : : * @a p is beyond end of string, out_of_range is thrown. The value of
1121 : : * the string doesn't change if an error is thrown.
1122 : : */
1123 : : basic_string&
1124 : 24547 : erase(size_type __pos = 0, size_type __n = npos)
1125 : : {
1126 : 24547 : _M_mutate(_M_check(__pos, "basic_string::erase"),
1127 : : _M_limit(__pos, __n), size_type(0));
1128 : 24547 : return *this;
1129 : : }
1130 : :
1131 : : /**
1132 : : * @brief Remove one character.
1133 : : * @param position Iterator referencing the character to remove.
1134 : : * @return iterator referencing same location after removal.
1135 : : *
1136 : : * Removes the character at @a position from this string. The value
1137 : : * of the string doesn't change if an error is thrown.
1138 : : */
1139 : : iterator
1140 : : erase(iterator __position)
1141 : : {
1142 : : _GLIBCXX_DEBUG_PEDASSERT(__position >= _M_ibegin()
1143 : : && __position < _M_iend());
1144 : : const size_type __pos = __position - _M_ibegin();
1145 : : _M_mutate(__pos, size_type(1), size_type(0));
1146 : : _M_rep()->_M_set_leaked();
1147 : : return iterator(_M_data() + __pos);
1148 : : }
1149 : :
1150 : : /**
1151 : : * @brief Remove a range of characters.
1152 : : * @param first Iterator referencing the first character to remove.
1153 : : * @param last Iterator referencing the end of the range.
1154 : : * @return Iterator referencing location of first after removal.
1155 : : *
1156 : : * Removes the characters in the range [first,last) from this string.
1157 : : * The value of the string doesn't change if an error is thrown.
1158 : : */
1159 : : iterator
1160 : : erase(iterator __first, iterator __last)
1161 : : {
1162 : : _GLIBCXX_DEBUG_PEDASSERT(__first >= _M_ibegin() && __first <= __last
1163 : : && __last <= _M_iend());
1164 : : const size_type __pos = __first - _M_ibegin();
1165 : : _M_mutate(__pos, __last - __first, size_type(0));
1166 : : _M_rep()->_M_set_leaked();
1167 : : return iterator(_M_data() + __pos);
1168 : : }
1169 : :
1170 : : /**
1171 : : * @brief Replace characters with value from another string.
1172 : : * @param pos Index of first character to replace.
1173 : : * @param n Number of characters to be replaced.
1174 : : * @param str String to insert.
1175 : : * @return Reference to this string.
1176 : : * @throw std::out_of_range If @a pos is beyond the end of this
1177 : : * string.
1178 : : * @throw std::length_error If new length exceeds @c max_size().
1179 : : *
1180 : : * Removes the characters in the range [pos,pos+n) from this string.
1181 : : * In place, the value of @a str is inserted. If @a pos is beyond end
1182 : : * of string, out_of_range is thrown. If the length of the result
1183 : : * exceeds max_size(), length_error is thrown. The value of the string
1184 : : * doesn't change if an error is thrown.
1185 : : */
1186 : : basic_string&
1187 : 4 : replace(size_type __pos, size_type __n, const basic_string& __str)
1188 : 4 : { return this->replace(__pos, __n, __str._M_data(), __str.size()); }
1189 : :
1190 : : /**
1191 : : * @brief Replace characters with value from another string.
1192 : : * @param pos1 Index of first character to replace.
1193 : : * @param n1 Number of characters to be replaced.
1194 : : * @param str String to insert.
1195 : : * @param pos2 Index of first character of str to use.
1196 : : * @param n2 Number of characters from str to use.
1197 : : * @return Reference to this string.
1198 : : * @throw std::out_of_range If @a pos1 > size() or @a pos2 >
1199 : : * str.size().
1200 : : * @throw std::length_error If new length exceeds @c max_size().
1201 : : *
1202 : : * Removes the characters in the range [pos1,pos1 + n) from this
1203 : : * string. In place, the value of @a str is inserted. If @a pos is
1204 : : * beyond end of string, out_of_range is thrown. If the length of the
1205 : : * result exceeds max_size(), length_error is thrown. The value of the
1206 : : * string doesn't change if an error is thrown.
1207 : : */
1208 : : basic_string&
1209 : : replace(size_type __pos1, size_type __n1, const basic_string& __str,
1210 : : size_type __pos2, size_type __n2)
1211 : : { return this->replace(__pos1, __n1, __str._M_data()
1212 : : + __str._M_check(__pos2, "basic_string::replace"),
1213 : : __str._M_limit(__pos2, __n2)); }
1214 : :
1215 : : /**
1216 : : * @brief Replace characters with value of a C substring.
1217 : : * @param pos Index of first character to replace.
1218 : : * @param n1 Number of characters to be replaced.
1219 : : * @param s C string to insert.
1220 : : * @param n2 Number of characters from @a s to use.
1221 : : * @return Reference to this string.
1222 : : * @throw std::out_of_range If @a pos1 > size().
1223 : : * @throw std::length_error If new length exceeds @c max_size().
1224 : : *
1225 : : * Removes the characters in the range [pos,pos + n1) from this string.
1226 : : * In place, the first @a n2 characters of @a s are inserted, or all
1227 : : * of @a s if @a n2 is too large. If @a pos is beyond end of string,
1228 : : * out_of_range is thrown. If the length of result exceeds max_size(),
1229 : : * length_error is thrown. The value of the string doesn't change if
1230 : : * an error is thrown.
1231 : : */
1232 : : basic_string&
1233 : : replace(size_type __pos, size_type __n1, const _CharT* __s,
1234 : : size_type __n2);
1235 : :
1236 : : /**
1237 : : * @brief Replace characters with value of a C string.
1238 : : * @param pos Index of first character to replace.
1239 : : * @param n1 Number of characters to be replaced.
1240 : : * @param s C string to insert.
1241 : : * @return Reference to this string.
1242 : : * @throw std::out_of_range If @a pos > size().
1243 : : * @throw std::length_error If new length exceeds @c max_size().
1244 : : *
1245 : : * Removes the characters in the range [pos,pos + n1) from this string.
1246 : : * In place, the first @a n characters of @a s are inserted. If @a
1247 : : * pos is beyond end of string, out_of_range is thrown. If the length
1248 : : * of result exceeds max_size(), length_error is thrown. The value of
1249 : : * the string doesn't change if an error is thrown.
1250 : : */
1251 : : basic_string&
1252 : 0 : replace(size_type __pos, size_type __n1, const _CharT* __s)
1253 : : {
1254 : : __glibcxx_requires_string(__s);
1255 : 0 : return this->replace(__pos, __n1, __s, traits_type::length(__s));
1256 : : }
1257 : :
1258 : : /**
1259 : : * @brief Replace characters with multiple characters.
1260 : : * @param pos Index of first character to replace.
1261 : : * @param n1 Number of characters to be replaced.
1262 : : * @param n2 Number of characters to insert.
1263 : : * @param c Character to insert.
1264 : : * @return Reference to this string.
1265 : : * @throw std::out_of_range If @a pos > size().
1266 : : * @throw std::length_error If new length exceeds @c max_size().
1267 : : *
1268 : : * Removes the characters in the range [pos,pos + n1) from this string.
1269 : : * In place, @a n2 copies of @a c are inserted. If @a pos is beyond
1270 : : * end of string, out_of_range is thrown. If the length of result
1271 : : * exceeds max_size(), length_error is thrown. The value of the string
1272 : : * doesn't change if an error is thrown.
1273 : : */
1274 : : basic_string&
1275 : : replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
1276 : : { return _M_replace_aux(_M_check(__pos, "basic_string::replace"),
1277 : : _M_limit(__pos, __n1), __n2, __c); }
1278 : :
1279 : : /**
1280 : : * @brief Replace range of characters with string.
1281 : : * @param i1 Iterator referencing start of range to replace.
1282 : : * @param i2 Iterator referencing end of range to replace.
1283 : : * @param str String value to insert.
1284 : : * @return Reference to this string.
1285 : : * @throw std::length_error If new length exceeds @c max_size().
1286 : : *
1287 : : * Removes the characters in the range [i1,i2). In place, the value of
1288 : : * @a str is inserted. If the length of result exceeds max_size(),
1289 : : * length_error is thrown. The value of the string doesn't change if
1290 : : * an error is thrown.
1291 : : */
1292 : : basic_string&
1293 : : replace(iterator __i1, iterator __i2, const basic_string& __str)
1294 : : { return this->replace(__i1, __i2, __str._M_data(), __str.size()); }
1295 : :
1296 : : /**
1297 : : * @brief Replace range of characters with C substring.
1298 : : * @param i1 Iterator referencing start of range to replace.
1299 : : * @param i2 Iterator referencing end of range to replace.
1300 : : * @param s C string value to insert.
1301 : : * @param n Number of characters from s to insert.
1302 : : * @return Reference to this string.
1303 : : * @throw std::length_error If new length exceeds @c max_size().
1304 : : *
1305 : : * Removes the characters in the range [i1,i2). In place, the first @a
1306 : : * n characters of @a s are inserted. If the length of result exceeds
1307 : : * max_size(), length_error is thrown. The value of the string doesn't
1308 : : * change if an error is thrown.
1309 : : */
1310 : : basic_string&
1311 : : replace(iterator __i1, iterator __i2, const _CharT* __s, size_type __n)
1312 : : {
1313 : : _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1314 : : && __i2 <= _M_iend());
1315 : : return this->replace(__i1 - _M_ibegin(), __i2 - __i1, __s, __n);
1316 : : }
1317 : :
1318 : : /**
1319 : : * @brief Replace range of characters with C string.
1320 : : * @param i1 Iterator referencing start of range to replace.
1321 : : * @param i2 Iterator referencing end of range to replace.
1322 : : * @param s C string value to insert.
1323 : : * @return Reference to this string.
1324 : : * @throw std::length_error If new length exceeds @c max_size().
1325 : : *
1326 : : * Removes the characters in the range [i1,i2). In place, the
1327 : : * characters of @a s are inserted. If the length of result exceeds
1328 : : * max_size(), length_error is thrown. The value of the string doesn't
1329 : : * change if an error is thrown.
1330 : : */
1331 : : basic_string&
1332 : : replace(iterator __i1, iterator __i2, const _CharT* __s)
1333 : : {
1334 : : __glibcxx_requires_string(__s);
1335 : : return this->replace(__i1, __i2, __s, traits_type::length(__s));
1336 : : }
1337 : :
1338 : : /**
1339 : : * @brief Replace range of characters with multiple characters
1340 : : * @param i1 Iterator referencing start of range to replace.
1341 : : * @param i2 Iterator referencing end of range to replace.
1342 : : * @param n Number of characters to insert.
1343 : : * @param c Character to insert.
1344 : : * @return Reference to this string.
1345 : : * @throw std::length_error If new length exceeds @c max_size().
1346 : : *
1347 : : * Removes the characters in the range [i1,i2). In place, @a n copies
1348 : : * of @a c are inserted. If the length of result exceeds max_size(),
1349 : : * length_error is thrown. The value of the string doesn't change if
1350 : : * an error is thrown.
1351 : : */
1352 : : basic_string&
1353 : : replace(iterator __i1, iterator __i2, size_type __n, _CharT __c)
1354 : : {
1355 : : _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1356 : : && __i2 <= _M_iend());
1357 : : return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __c);
1358 : : }
1359 : :
1360 : : /**
1361 : : * @brief Replace range of characters with range.
1362 : : * @param i1 Iterator referencing start of range to replace.
1363 : : * @param i2 Iterator referencing end of range to replace.
1364 : : * @param k1 Iterator referencing start of range to insert.
1365 : : * @param k2 Iterator referencing end of range to insert.
1366 : : * @return Reference to this string.
1367 : : * @throw std::length_error If new length exceeds @c max_size().
1368 : : *
1369 : : * Removes the characters in the range [i1,i2). In place, characters
1370 : : * in the range [k1,k2) are inserted. If the length of result exceeds
1371 : : * max_size(), length_error is thrown. The value of the string doesn't
1372 : : * change if an error is thrown.
1373 : : */
1374 : : template<class _InputIterator>
1375 : : basic_string&
1376 : : replace(iterator __i1, iterator __i2,
1377 : : _InputIterator __k1, _InputIterator __k2)
1378 : : {
1379 : : _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1380 : : && __i2 <= _M_iend());
1381 : : __glibcxx_requires_valid_range(__k1, __k2);
1382 : : typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1383 : : return _M_replace_dispatch(__i1, __i2, __k1, __k2, _Integral());
1384 : : }
1385 : :
1386 : : // Specializations for the common case of pointer and iterator:
1387 : : // useful to avoid the overhead of temporary buffering in _M_replace.
1388 : : basic_string&
1389 : : replace(iterator __i1, iterator __i2, _CharT* __k1, _CharT* __k2)
1390 : : {
1391 : : _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1392 : : && __i2 <= _M_iend());
1393 : : __glibcxx_requires_valid_range(__k1, __k2);
1394 : : return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1395 : : __k1, __k2 - __k1);
1396 : : }
1397 : :
1398 : : basic_string&
1399 : : replace(iterator __i1, iterator __i2,
1400 : : const _CharT* __k1, const _CharT* __k2)
1401 : : {
1402 : : _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1403 : : && __i2 <= _M_iend());
1404 : : __glibcxx_requires_valid_range(__k1, __k2);
1405 : : return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1406 : : __k1, __k2 - __k1);
1407 : : }
1408 : :
1409 : : basic_string&
1410 : : replace(iterator __i1, iterator __i2, iterator __k1, iterator __k2)
1411 : : {
1412 : : _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1413 : : && __i2 <= _M_iend());
1414 : : __glibcxx_requires_valid_range(__k1, __k2);
1415 : : return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1416 : : __k1.base(), __k2 - __k1);
1417 : : }
1418 : :
1419 : : basic_string&
1420 : : replace(iterator __i1, iterator __i2,
1421 : : const_iterator __k1, const_iterator __k2)
1422 : : {
1423 : : _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1424 : : && __i2 <= _M_iend());
1425 : : __glibcxx_requires_valid_range(__k1, __k2);
1426 : : return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1427 : : __k1.base(), __k2 - __k1);
1428 : : }
1429 : :
1430 : : private:
1431 : : template<class _Integer>
1432 : : basic_string&
1433 : : _M_replace_dispatch(iterator __i1, iterator __i2, _Integer __n,
1434 : : _Integer __val, __true_type)
1435 : : { return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __val); }
1436 : :
1437 : : template<class _InputIterator>
1438 : : basic_string&
1439 : : _M_replace_dispatch(iterator __i1, iterator __i2, _InputIterator __k1,
1440 : : _InputIterator __k2, __false_type);
1441 : :
1442 : : basic_string&
1443 : : _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2,
1444 : : _CharT __c);
1445 : :
1446 : : basic_string&
1447 : : _M_replace_safe(size_type __pos1, size_type __n1, const _CharT* __s,
1448 : : size_type __n2);
1449 : :
1450 : : // _S_construct_aux is used to implement the 21.3.1 para 15 which
1451 : : // requires special behaviour if _InIter is an integral type
1452 : : template<class _InIterator>
1453 : : static _CharT*
1454 : : _S_construct_aux(_InIterator __beg, _InIterator __end,
1455 : : const _Alloc& __a, __false_type)
1456 : : {
1457 : : typedef typename iterator_traits<_InIterator>::iterator_category _Tag;
1458 : 537610 : return _S_construct(__beg, __end, __a, _Tag());
1459 : : }
1460 : :
1461 : : // _GLIBCXX_RESOLVE_LIB_DEFECTS
1462 : : // 438. Ambiguity in the "do the right thing" clause
1463 : : template<class _Integer>
1464 : : static _CharT*
1465 : : _S_construct_aux(_Integer __beg, _Integer __end,
1466 : : const _Alloc& __a, __true_type)
1467 : : { return _S_construct(static_cast<size_type>(__beg), __end, __a); }
1468 : :
1469 : : template<class _InIterator>
1470 : : static _CharT*
1471 : 18422 : _S_construct(_InIterator __beg, _InIterator __end, const _Alloc& __a)
1472 : : {
1473 : : typedef typename std::__is_integer<_InIterator>::__type _Integral;
1474 : 519188 : return _S_construct_aux(__beg, __end, __a, _Integral());
1475 : : }
1476 : :
1477 : : // For Input Iterators, used in istreambuf_iterators, etc.
1478 : : template<class _InIterator>
1479 : : static _CharT*
1480 : : _S_construct(_InIterator __beg, _InIterator __end, const _Alloc& __a,
1481 : : input_iterator_tag);
1482 : :
1483 : : // For forward_iterators up to random_access_iterators, used for
1484 : : // string::iterator, _CharT*, etc.
1485 : : template<class _FwdIterator>
1486 : : static _CharT*
1487 : : _S_construct(_FwdIterator __beg, _FwdIterator __end, const _Alloc& __a,
1488 : : forward_iterator_tag);
1489 : :
1490 : : static _CharT*
1491 : : _S_construct(size_type __req, _CharT __c, const _Alloc& __a);
1492 : :
1493 : : public:
1494 : :
1495 : : /**
1496 : : * @brief Copy substring into C string.
1497 : : * @param s C string to copy value into.
1498 : : * @param n Number of characters to copy.
1499 : : * @param pos Index of first character to copy.
1500 : : * @return Number of characters actually copied
1501 : : * @throw std::out_of_range If pos > size().
1502 : : *
1503 : : * Copies up to @a n characters starting at @a pos into the C string @a
1504 : : * s. If @a pos is greater than size(), out_of_range is thrown.
1505 : : */
1506 : : size_type
1507 : : copy(_CharT* __s, size_type __n, size_type __pos = 0) const;
1508 : :
1509 : : /**
1510 : : * @brief Swap contents with another string.
1511 : : * @param s String to swap with.
1512 : : *
1513 : : * Exchanges the contents of this string with that of @a s in constant
1514 : : * time.
1515 : : */
1516 : : void
1517 : : swap(basic_string& __s);
1518 : :
1519 : : // String operations:
1520 : : /**
1521 : : * @brief Return const pointer to null-terminated contents.
1522 : : *
1523 : : * This is a handle to internal data. Do not modify or dire things may
1524 : : * happen.
1525 : : */
1526 : : const _CharT*
1527 : : c_str() const
1528 : 74997 : { return _M_data(); }
1529 : :
1530 : : /**
1531 : : * @brief Return const pointer to contents.
1532 : : *
1533 : : * This is a handle to internal data. Do not modify or dire things may
1534 : : * happen.
1535 : : */
1536 : : const _CharT*
1537 : : data() const
1538 : 1056449 : { return _M_data(); }
1539 : :
1540 : : /**
1541 : : * @brief Return copy of allocator used to construct this string.
1542 : : */
1543 : : allocator_type
1544 : : get_allocator() const
1545 : 784600 : { return _M_dataplus; }
1546 : :
1547 : : /**
1548 : : * @brief Find position of a C substring.
1549 : : * @param s C string to locate.
1550 : : * @param pos Index of character to search from.
1551 : : * @param n Number of characters from @a s to search for.
1552 : : * @return Index of start of first occurrence.
1553 : : *
1554 : : * Starting from @a pos, searches forward for the first @a n characters
1555 : : * in @a s within this string. If found, returns the index where it
1556 : : * begins. If not found, returns npos.
1557 : : */
1558 : : size_type
1559 : : find(const _CharT* __s, size_type __pos, size_type __n) const;
1560 : :
1561 : : /**
1562 : : * @brief Find position of a string.
1563 : : * @param str String to locate.
1564 : : * @param pos Index of character to search from (default 0).
1565 : : * @return Index of start of first occurrence.
1566 : : *
1567 : : * Starting from @a pos, searches forward for value of @a str within
1568 : : * this string. If found, returns the index where it begins. If not
1569 : : * found, returns npos.
1570 : : */
1571 : : size_type
1572 : 6 : find(const basic_string& __str, size_type __pos = 0) const
1573 : 6 : { return this->find(__str.data(), __pos, __str.size()); }
1574 : :
1575 : : /**
1576 : : * @brief Find position of a C string.
1577 : : * @param s C string to locate.
1578 : : * @param pos Index of character to search from (default 0).
1579 : : * @return Index of start of first occurrence.
1580 : : *
1581 : : * Starting from @a pos, searches forward for the value of @a s within
1582 : : * this string. If found, returns the index where it begins. If not
1583 : : * found, returns npos.
1584 : : */
1585 : : size_type
1586 : 243 : find(const _CharT* __s, size_type __pos = 0) const
1587 : : {
1588 : : __glibcxx_requires_string(__s);
1589 : 243 : return this->find(__s, __pos, traits_type::length(__s));
1590 : : }
1591 : :
1592 : : /**
1593 : : * @brief Find position of a character.
1594 : : * @param c Character to locate.
1595 : : * @param pos Index of character to search from (default 0).
1596 : : * @return Index of first occurrence.
1597 : : *
1598 : : * Starting from @a pos, searches forward for @a c within this string.
1599 : : * If found, returns the index where it was found. If not found,
1600 : : * returns npos.
1601 : : */
1602 : : size_type
1603 : : find(_CharT __c, size_type __pos = 0) const;
1604 : :
1605 : : /**
1606 : : * @brief Find last position of a string.
1607 : : * @param str String to locate.
1608 : : * @param pos Index of character to search back from (default end).
1609 : : * @return Index of start of last occurrence.
1610 : : *
1611 : : * Starting from @a pos, searches backward for value of @a str within
1612 : : * this string. If found, returns the index where it begins. If not
1613 : : * found, returns npos.
1614 : : */
1615 : : size_type
1616 : : rfind(const basic_string& __str, size_type __pos = npos) const
1617 : : { return this->rfind(__str.data(), __pos, __str.size()); }
1618 : :
1619 : : /**
1620 : : * @brief Find last position of a C substring.
1621 : : * @param s C string to locate.
1622 : : * @param pos Index of character to search back from.
1623 : : * @param n Number of characters from s to search for.
1624 : : * @return Index of start of last occurrence.
1625 : : *
1626 : : * Starting from @a pos, searches backward for the first @a n
1627 : : * characters in @a s within this string. If found, returns the index
1628 : : * where it begins. If not found, returns npos.
1629 : : */
1630 : : size_type
1631 : : rfind(const _CharT* __s, size_type __pos, size_type __n) const;
1632 : :
1633 : : /**
1634 : : * @brief Find last position of a C string.
1635 : : * @param s C string to locate.
1636 : : * @param pos Index of character to start search at (default end).
1637 : : * @return Index of start of last occurrence.
1638 : : *
1639 : : * Starting from @a pos, searches backward for the value of @a s within
1640 : : * this string. If found, returns the index where it begins. If not
1641 : : * found, returns npos.
1642 : : */
1643 : : size_type
1644 : 0 : rfind(const _CharT* __s, size_type __pos = npos) const
1645 : : {
1646 : : __glibcxx_requires_string(__s);
1647 : 0 : return this->rfind(__s, __pos, traits_type::length(__s));
1648 : : }
1649 : :
1650 : : /**
1651 : : * @brief Find last position of a character.
1652 : : * @param c Character to locate.
1653 : : * @param pos Index of character to search back from (default end).
1654 : : * @return Index of last occurrence.
1655 : : *
1656 : : * Starting from @a pos, searches backward for @a c within this string.
1657 : : * If found, returns the index where it was found. If not found,
1658 : : * returns npos.
1659 : : */
1660 : : size_type
1661 : : rfind(_CharT __c, size_type __pos = npos) const;
1662 : :
1663 : : /**
1664 : : * @brief Find position of a character of string.
1665 : : * @param str String containing characters to locate.
1666 : : * @param pos Index of character to search from (default 0).
1667 : : * @return Index of first occurrence.
1668 : : *
1669 : : * Starting from @a pos, searches forward for one of the characters of
1670 : : * @a str within this string. If found, returns the index where it was
1671 : : * found. If not found, returns npos.
1672 : : */
1673 : : size_type
1674 : : find_first_of(const basic_string& __str, size_type __pos = 0) const
1675 : : { return this->find_first_of(__str.data(), __pos, __str.size()); }
1676 : :
1677 : : /**
1678 : : * @brief Find position of a character of C substring.
1679 : : * @param s String containing characters to locate.
1680 : : * @param pos Index of character to search from.
1681 : : * @param n Number of characters from s to search for.
1682 : : * @return Index of first occurrence.
1683 : : *
1684 : : * Starting from @a pos, searches forward for one of the first @a n
1685 : : * characters of @a s within this string. If found, returns the index
1686 : : * where it was found. If not found, returns npos.
1687 : : */
1688 : : size_type
1689 : : find_first_of(const _CharT* __s, size_type __pos, size_type __n) const;
1690 : :
1691 : : /**
1692 : : * @brief Find position of a character of C string.
1693 : : * @param s String containing characters to locate.
1694 : : * @param pos Index of character to search from (default 0).
1695 : : * @return Index of first occurrence.
1696 : : *
1697 : : * Starting from @a pos, searches forward for one of the characters of
1698 : : * @a s within this string. If found, returns the index where it was
1699 : : * found. If not found, returns npos.
1700 : : */
1701 : : size_type
1702 : 4 : find_first_of(const _CharT* __s, size_type __pos = 0) const
1703 : : {
1704 : : __glibcxx_requires_string(__s);
1705 : 4 : return this->find_first_of(__s, __pos, traits_type::length(__s));
1706 : : }
1707 : :
1708 : : /**
1709 : : * @brief Find position of a character.
1710 : : * @param c Character to locate.
1711 : : * @param pos Index of character to search from (default 0).
1712 : : * @return Index of first occurrence.
1713 : : *
1714 : : * Starting from @a pos, searches forward for the character @a c within
1715 : : * this string. If found, returns the index where it was found. If
1716 : : * not found, returns npos.
1717 : : *
1718 : : * Note: equivalent to find(c, pos).
1719 : : */
1720 : : size_type
1721 : : find_first_of(_CharT __c, size_type __pos = 0) const
1722 : : { return this->find(__c, __pos); }
1723 : :
1724 : : /**
1725 : : * @brief Find last position of a character of string.
1726 : : * @param str String containing characters to locate.
1727 : : * @param pos Index of character to search back from (default end).
1728 : : * @return Index of last occurrence.
1729 : : *
1730 : : * Starting from @a pos, searches backward for one of the characters of
1731 : : * @a str within this string. If found, returns the index where it was
1732 : : * found. If not found, returns npos.
1733 : : */
1734 : : size_type
1735 : : find_last_of(const basic_string& __str, size_type __pos = npos) const
1736 : : { return this->find_last_of(__str.data(), __pos, __str.size()); }
1737 : :
1738 : : /**
1739 : : * @brief Find last position of a character of C substring.
1740 : : * @param s C string containing characters to locate.
1741 : : * @param pos Index of character to search back from.
1742 : : * @param n Number of characters from s to search for.
1743 : : * @return Index of last occurrence.
1744 : : *
1745 : : * Starting from @a pos, searches backward for one of the first @a n
1746 : : * characters of @a s within this string. If found, returns the index
1747 : : * where it was found. If not found, returns npos.
1748 : : */
1749 : : size_type
1750 : : find_last_of(const _CharT* __s, size_type __pos, size_type __n) const;
1751 : :
1752 : : /**
1753 : : * @brief Find last position of a character of C string.
1754 : : * @param s C string containing characters to locate.
1755 : : * @param pos Index of character to search back from (default end).
1756 : : * @return Index of last occurrence.
1757 : : *
1758 : : * Starting from @a pos, searches backward for one of the characters of
1759 : : * @a s within this string. If found, returns the index where it was
1760 : : * found. If not found, returns npos.
1761 : : */
1762 : : size_type
1763 : : find_last_of(const _CharT* __s, size_type __pos = npos) const
1764 : : {
1765 : : __glibcxx_requires_string(__s);
1766 : : return this->find_last_of(__s, __pos, traits_type::length(__s));
1767 : : }
1768 : :
1769 : : /**
1770 : : * @brief Find last position of a character.
1771 : : * @param c Character to locate.
1772 : : * @param pos Index of character to search back from (default end).
1773 : : * @return Index of last occurrence.
1774 : : *
1775 : : * Starting from @a pos, searches backward for @a c within this string.
1776 : : * If found, returns the index where it was found. If not found,
1777 : : * returns npos.
1778 : : *
1779 : : * Note: equivalent to rfind(c, pos).
1780 : : */
1781 : : size_type
1782 : : find_last_of(_CharT __c, size_type __pos = npos) const
1783 : 0 : { return this->rfind(__c, __pos); }
1784 : :
1785 : : /**
1786 : : * @brief Find position of a character not in string.
1787 : : * @param str String containing characters to avoid.
1788 : : * @param pos Index of character to search from (default 0).
1789 : : * @return Index of first occurrence.
1790 : : *
1791 : : * Starting from @a pos, searches forward for a character not contained
1792 : : * in @a str within this string. If found, returns the index where it
1793 : : * was found. If not found, returns npos.
1794 : : */
1795 : : size_type
1796 : : find_first_not_of(const basic_string& __str, size_type __pos = 0) const
1797 : : { return this->find_first_not_of(__str.data(), __pos, __str.size()); }
1798 : :
1799 : : /**
1800 : : * @brief Find position of a character not in C substring.
1801 : : * @param s C string containing characters to avoid.
1802 : : * @param pos Index of character to search from.
1803 : : * @param n Number of characters from s to consider.
1804 : : * @return Index of first occurrence.
1805 : : *
1806 : : * Starting from @a pos, searches forward for a character not contained
1807 : : * in the first @a n characters of @a s within this string. If found,
1808 : : * returns the index where it was found. If not found, returns npos.
1809 : : */
1810 : : size_type
1811 : : find_first_not_of(const _CharT* __s, size_type __pos,
1812 : : size_type __n) const;
1813 : :
1814 : : /**
1815 : : * @brief Find position of a character not in C string.
1816 : : * @param s C string containing characters to avoid.
1817 : : * @param pos Index of character to search from (default 0).
1818 : : * @return Index of first occurrence.
1819 : : *
1820 : : * Starting from @a pos, searches forward for a character not contained
1821 : : * in @a s within this string. If found, returns the index where it
1822 : : * was found. If not found, returns npos.
1823 : : */
1824 : : size_type
1825 : 1810 : find_first_not_of(const _CharT* __s, size_type __pos = 0) const
1826 : : {
1827 : : __glibcxx_requires_string(__s);
1828 : 1810 : return this->find_first_not_of(__s, __pos, traits_type::length(__s));
1829 : : }
1830 : :
1831 : : /**
1832 : : * @brief Find position of a different character.
1833 : : * @param c Character to avoid.
1834 : : * @param pos Index of character to search from (default 0).
1835 : : * @return Index of first occurrence.
1836 : : *
1837 : : * Starting from @a pos, searches forward for a character other than @a c
1838 : : * within this string. If found, returns the index where it was found.
1839 : : * If not found, returns npos.
1840 : : */
1841 : : size_type
1842 : : find_first_not_of(_CharT __c, size_type __pos = 0) const;
1843 : :
1844 : : /**
1845 : : * @brief Find last position of a character not in string.
1846 : : * @param str String containing characters to avoid.
1847 : : * @param pos Index of character to search back from (default end).
1848 : : * @return Index of last occurrence.
1849 : : *
1850 : : * Starting from @a pos, searches backward for a character not
1851 : : * contained in @a str within this string. If found, returns the index
1852 : : * where it was found. If not found, returns npos.
1853 : : */
1854 : : size_type
1855 : : find_last_not_of(const basic_string& __str, size_type __pos = npos) const
1856 : : { return this->find_last_not_of(__str.data(), __pos, __str.size()); }
1857 : :
1858 : : /**
1859 : : * @brief Find last position of a character not in C substring.
1860 : : * @param s C string containing characters to avoid.
1861 : : * @param pos Index of character to search back from.
1862 : : * @param n Number of characters from s to consider.
1863 : : * @return Index of last occurrence.
1864 : : *
1865 : : * Starting from @a pos, searches backward for a character not
1866 : : * contained in the first @a n characters of @a s within this string.
1867 : : * If found, returns the index where it was found. If not found,
1868 : : * returns npos.
1869 : : */
1870 : : size_type
1871 : : find_last_not_of(const _CharT* __s, size_type __pos,
1872 : : size_type __n) const;
1873 : : /**
1874 : : * @brief Find last position of a character not in C string.
1875 : : * @param s C string containing characters to avoid.
1876 : : * @param pos Index of character to search back from (default end).
1877 : : * @return Index of last occurrence.
1878 : : *
1879 : : * Starting from @a pos, searches backward for a character not
1880 : : * contained in @a s within this string. If found, returns the index
1881 : : * where it was found. If not found, returns npos.
1882 : : */
1883 : : size_type
1884 : : find_last_not_of(const _CharT* __s, size_type __pos = npos) const
1885 : : {
1886 : : __glibcxx_requires_string(__s);
1887 : : return this->find_last_not_of(__s, __pos, traits_type::length(__s));
1888 : : }
1889 : :
1890 : : /**
1891 : : * @brief Find last position of a different character.
1892 : : * @param c Character to avoid.
1893 : : * @param pos Index of character to search back from (default end).
1894 : : * @return Index of last occurrence.
1895 : : *
1896 : : * Starting from @a pos, searches backward for a character other than
1897 : : * @a c within this string. If found, returns the index where it was
1898 : : * found. If not found, returns npos.
1899 : : */
1900 : : size_type
1901 : : find_last_not_of(_CharT __c, size_type __pos = npos) const;
1902 : :
1903 : : /**
1904 : : * @brief Get a substring.
1905 : : * @param pos Index of first character (default 0).
1906 : : * @param n Number of characters in substring (default remainder).
1907 : : * @return The new string.
1908 : : * @throw std::out_of_range If pos > size().
1909 : : *
1910 : : * Construct and return a new string using the @a n characters starting
1911 : : * at @a pos. If the string is too short, use the remainder of the
1912 : : * characters. If @a pos is beyond the end of the string, out_of_range
1913 : : * is thrown.
1914 : : */
1915 : : basic_string
1916 : 2546 : substr(size_type __pos = 0, size_type __n = npos) const
1917 : : { return basic_string(*this,
1918 : 2546 : _M_check(__pos, "basic_string::substr"), __n); }
1919 : :
1920 : : /**
1921 : : * @brief Compare to a string.
1922 : : * @param str String to compare against.
1923 : : * @return Integer < 0, 0, or > 0.
1924 : : *
1925 : : * Returns an integer < 0 if this string is ordered before @a str, 0 if
1926 : : * their values are equivalent, or > 0 if this string is ordered after
1927 : : * @a str. Determines the effective length rlen of the strings to
1928 : : * compare as the smallest of size() and str.size(). The function
1929 : : * then compares the two strings by calling traits::compare(data(),
1930 : : * str.data(),rlen). If the result of the comparison is nonzero returns
1931 : : * it, otherwise the shorter one is ordered first.
1932 : : */
1933 : : int
1934 : 14837 : compare(const basic_string& __str) const
1935 : : {
1936 : 14837 : const size_type __size = this->size();
1937 : 14837 : const size_type __osize = __str.size();
1938 : 14837 : const size_type __len = std::min(__size, __osize);
1939 : :
1940 : 14837 : int __r = traits_type::compare(_M_data(), __str.data(), __len);
1941 [ + + ]: 14837 : if (!__r)
1942 : 4854 : __r = _S_compare(__size, __osize);
1943 : 14837 : return __r;
1944 : : }
1945 : :
1946 : : /**
1947 : : * @brief Compare substring to a string.
1948 : : * @param pos Index of first character of substring.
1949 : : * @param n Number of characters in substring.
1950 : : * @param str String to compare against.
1951 : : * @return Integer < 0, 0, or > 0.
1952 : : *
1953 : : * Form the substring of this string from the @a n characters starting
1954 : : * at @a pos. Returns an integer < 0 if the substring is ordered
1955 : : * before @a str, 0 if their values are equivalent, or > 0 if the
1956 : : * substring is ordered after @a str. Determines the effective length
1957 : : * rlen of the strings to compare as the smallest of the length of the
1958 : : * substring and @a str.size(). The function then compares the two
1959 : : * strings by calling traits::compare(substring.data(),str.data(),rlen).
1960 : : * If the result of the comparison is nonzero returns it, otherwise the
1961 : : * shorter one is ordered first.
1962 : : */
1963 : : int
1964 : : compare(size_type __pos, size_type __n, const basic_string& __str) const;
1965 : :
1966 : : /**
1967 : : * @brief Compare substring to a substring.
1968 : : * @param pos1 Index of first character of substring.
1969 : : * @param n1 Number of characters in substring.
1970 : : * @param str String to compare against.
1971 : : * @param pos2 Index of first character of substring of str.
1972 : : * @param n2 Number of characters in substring of str.
1973 : : * @return Integer < 0, 0, or > 0.
1974 : : *
1975 : : * Form the substring of this string from the @a n1 characters starting
1976 : : * at @a pos1. Form the substring of @a str from the @a n2 characters
1977 : : * starting at @a pos2. Returns an integer < 0 if this substring is
1978 : : * ordered before the substring of @a str, 0 if their values are
1979 : : * equivalent, or > 0 if this substring is ordered after the substring
1980 : : * of @a str. Determines the effective length rlen of the strings
1981 : : * to compare as the smallest of the lengths of the substrings. The
1982 : : * function then compares the two strings by calling
1983 : : * traits::compare(substring.data(),str.substr(pos2,n2).data(),rlen).
1984 : : * If the result of the comparison is nonzero returns it, otherwise the
1985 : : * shorter one is ordered first.
1986 : : */
1987 : : int
1988 : : compare(size_type __pos1, size_type __n1, const basic_string& __str,
1989 : : size_type __pos2, size_type __n2) const;
1990 : :
1991 : : /**
1992 : : * @brief Compare to a C string.
1993 : : * @param s C string to compare against.
1994 : : * @return Integer < 0, 0, or > 0.
1995 : : *
1996 : : * Returns an integer < 0 if this string is ordered before @a s, 0 if
1997 : : * their values are equivalent, or > 0 if this string is ordered after
1998 : : * @a s. Determines the effective length rlen of the strings to
1999 : : * compare as the smallest of size() and the length of a string
2000 : : * constructed from @a s. The function then compares the two strings
2001 : : * by calling traits::compare(data(),s,rlen). If the result of the
2002 : : * comparison is nonzero returns it, otherwise the shorter one is
2003 : : * ordered first.
2004 : : */
2005 : : int
2006 : : compare(const _CharT* __s) const;
2007 : :
2008 : : // _GLIBCXX_RESOLVE_LIB_DEFECTS
2009 : : // 5 String::compare specification questionable
2010 : : /**
2011 : : * @brief Compare substring to a C string.
2012 : : * @param pos Index of first character of substring.
2013 : : * @param n1 Number of characters in substring.
2014 : : * @param s C string to compare against.
2015 : : * @return Integer < 0, 0, or > 0.
2016 : : *
2017 : : * Form the substring of this string from the @a n1 characters starting
2018 : : * at @a pos. Returns an integer < 0 if the substring is ordered
2019 : : * before @a s, 0 if their values are equivalent, or > 0 if the
2020 : : * substring is ordered after @a s. Determines the effective length
2021 : : * rlen of the strings to compare as the smallest of the length of the
2022 : : * substring and the length of a string constructed from @a s. The
2023 : : * function then compares the two string by calling
2024 : : * traits::compare(substring.data(),s,rlen). If the result of the
2025 : : * comparison is nonzero returns it, otherwise the shorter one is
2026 : : * ordered first.
2027 : : */
2028 : : int
2029 : : compare(size_type __pos, size_type __n1, const _CharT* __s) const;
2030 : :
2031 : : /**
2032 : : * @brief Compare substring against a character array.
2033 : : * @param pos1 Index of first character of substring.
2034 : : * @param n1 Number of characters in substring.
2035 : : * @param s character array to compare against.
2036 : : * @param n2 Number of characters of s.
2037 : : * @return Integer < 0, 0, or > 0.
2038 : : *
2039 : : * Form the substring of this string from the @a n1 characters starting
2040 : : * at @a pos1. Form a string from the first @a n2 characters of @a s.
2041 : : * Returns an integer < 0 if this substring is ordered before the string
2042 : : * from @a s, 0 if their values are equivalent, or > 0 if this substring
2043 : : * is ordered after the string from @a s. Determines the effective
2044 : : * length rlen of the strings to compare as the smallest of the length
2045 : : * of the substring and @a n2. The function then compares the two
2046 : : * strings by calling traits::compare(substring.data(),s,rlen). If the
2047 : : * result of the comparison is nonzero returns it, otherwise the shorter
2048 : : * one is ordered first.
2049 : : *
2050 : : * NB: s must have at least n2 characters, '\0' has no special
2051 : : * meaning.
2052 : : */
2053 : : int
2054 : : compare(size_type __pos, size_type __n1, const _CharT* __s,
2055 : : size_type __n2) const;
2056 : : };
2057 : :
2058 : : template<typename _CharT, typename _Traits, typename _Alloc>
2059 : : inline basic_string<_CharT, _Traits, _Alloc>::
2060 : 631508 : basic_string()
2061 : 631508 : : _M_dataplus(_S_empty_rep()._M_refcopy(), _Alloc()) { }
2062 : :
2063 : : // operator+
2064 : : /**
2065 : : * @brief Concatenate two strings.
2066 : : * @param lhs First string.
2067 : : * @param rhs Last string.
2068 : : * @return New string with value of @a lhs followed by @a rhs.
2069 : : */
2070 : : template<typename _CharT, typename _Traits, typename _Alloc>
2071 : : basic_string<_CharT, _Traits, _Alloc>
2072 : : operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2073 : 170 : const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2074 : : {
2075 : 170 : basic_string<_CharT, _Traits, _Alloc> __str(__lhs);
2076 : 170 : __str.append(__rhs);
2077 : 170 : return __str;
2078 : : }
2079 : :
2080 : : /**
2081 : : * @brief Concatenate C string and string.
2082 : : * @param lhs First string.
2083 : : * @param rhs Last string.
2084 : : * @return New string with value of @a lhs followed by @a rhs.
2085 : : */
2086 : : template<typename _CharT, typename _Traits, typename _Alloc>
2087 : : basic_string<_CharT,_Traits,_Alloc>
2088 : : operator+(const _CharT* __lhs,
2089 : : const basic_string<_CharT,_Traits,_Alloc>& __rhs);
2090 : :
2091 : : /**
2092 : : * @brief Concatenate character and string.
2093 : : * @param lhs First string.
2094 : : * @param rhs Last string.
2095 : : * @return New string with @a lhs followed by @a rhs.
2096 : : */
2097 : : template<typename _CharT, typename _Traits, typename _Alloc>
2098 : : basic_string<_CharT,_Traits,_Alloc>
2099 : : operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Alloc>& __rhs);
2100 : :
2101 : : /**
2102 : : * @brief Concatenate string and C string.
2103 : : * @param lhs First string.
2104 : : * @param rhs Last string.
2105 : : * @return New string with @a lhs followed by @a rhs.
2106 : : */
2107 : : template<typename _CharT, typename _Traits, typename _Alloc>
2108 : : inline basic_string<_CharT, _Traits, _Alloc>
2109 : : operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2110 : 1643 : const _CharT* __rhs)
2111 : : {
2112 : 1644 : basic_string<_CharT, _Traits, _Alloc> __str(__lhs);
2113 : 1644 : __str.append(__rhs);
2114 : 1643 : return __str;
2115 : : }
2116 : :
2117 : : /**
2118 : : * @brief Concatenate string and character.
2119 : : * @param lhs First string.
2120 : : * @param rhs Last string.
2121 : : * @return New string with @a lhs followed by @a rhs.
2122 : : */
2123 : : template<typename _CharT, typename _Traits, typename _Alloc>
2124 : : inline basic_string<_CharT, _Traits, _Alloc>
2125 : : operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, _CharT __rhs)
2126 : : {
2127 : : typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
2128 : : typedef typename __string_type::size_type __size_type;
2129 : : __string_type __str(__lhs);
2130 : : __str.append(__size_type(1), __rhs);
2131 : : return __str;
2132 : : }
2133 : :
2134 : : // operator ==
2135 : : /**
2136 : : * @brief Test equivalence of two strings.
2137 : : * @param lhs First string.
2138 : : * @param rhs Second string.
2139 : : * @return True if @a lhs.compare(@a rhs) == 0. False otherwise.
2140 : : */
2141 : : template<typename _CharT, typename _Traits, typename _Alloc>
2142 : : inline bool
2143 : : operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2144 : : const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2145 : : { return __lhs.compare(__rhs) == 0; }
2146 : :
2147 : : template<typename _CharT>
2148 : : inline
2149 : : typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value, bool>::__type
2150 : : operator==(const basic_string<_CharT>& __lhs,
2151 : 1435 : const basic_string<_CharT>& __rhs)
2152 : : { return (__lhs.size() == __rhs.size()
2153 : : && !std::char_traits<_CharT>::compare(__lhs.data(), __rhs.data(),
2154 [ + + + + ]: 12216 : __lhs.size())); }
[ + - + - ]
[ + - + - ]
[ + + + - ]
[ + + + -
+ + + + ]
[ + + + + ]
2155 : :
2156 : : /**
2157 : : * @brief Test equivalence of C string and string.
2158 : : * @param lhs C string.
2159 : : * @param rhs String.
2160 : : * @return True if @a rhs.compare(@a lhs) == 0. False otherwise.
2161 : : */
2162 : : template<typename _CharT, typename _Traits, typename _Alloc>
2163 : : inline bool
2164 : : operator==(const _CharT* __lhs,
2165 : : const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2166 : : { return __rhs.compare(__lhs) == 0; }
2167 : :
2168 : : /**
2169 : : * @brief Test equivalence of string and C string.
2170 : : * @param lhs String.
2171 : : * @param rhs C string.
2172 : : * @return True if @a lhs.compare(@a rhs) == 0. False otherwise.
2173 : : */
2174 : : template<typename _CharT, typename _Traits, typename _Alloc>
2175 : : inline bool
2176 : : operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2177 : 30 : const _CharT* __rhs)
2178 : 401685 : { return __lhs.compare(__rhs) == 0; }
2179 : :
2180 : : // operator !=
2181 : : /**
2182 : : * @brief Test difference of two strings.
2183 : : * @param lhs First string.
2184 : : * @param rhs Second string.
2185 : : * @return True if @a lhs.compare(@a rhs) != 0. False otherwise.
2186 : : */
2187 : : template<typename _CharT, typename _Traits, typename _Alloc>
2188 : : inline bool
2189 : : operator!=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2190 : : const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2191 : 6 : { return !(__lhs == __rhs); }
2192 : :
2193 : : /**
2194 : : * @brief Test difference of C string and string.
2195 : : * @param lhs C string.
2196 : : * @param rhs String.
2197 : : * @return True if @a rhs.compare(@a lhs) != 0. False otherwise.
2198 : : */
2199 : : template<typename _CharT, typename _Traits, typename _Alloc>
2200 : : inline bool
2201 : : operator!=(const _CharT* __lhs,
2202 : : const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2203 : : { return !(__lhs == __rhs); }
2204 : :
2205 : : /**
2206 : : * @brief Test difference of string and C string.
2207 : : * @param lhs String.
2208 : : * @param rhs C string.
2209 : : * @return True if @a lhs.compare(@a rhs) != 0. False otherwise.
2210 : : */
2211 : : template<typename _CharT, typename _Traits, typename _Alloc>
2212 : : inline bool
2213 : : operator!=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2214 : : const _CharT* __rhs)
2215 : 81 : { return !(__lhs == __rhs); }
2216 : :
2217 : : // operator <
2218 : : /**
2219 : : * @brief Test if string precedes string.
2220 : : * @param lhs First string.
2221 : : * @param rhs Second string.
2222 : : * @return True if @a lhs precedes @a rhs. False otherwise.
2223 : : */
2224 : : template<typename _CharT, typename _Traits, typename _Alloc>
2225 : : inline bool
2226 : : operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2227 : : const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2228 : 15073 : { return __lhs.compare(__rhs) < 0; }
2229 : :
2230 : : /**
2231 : : * @brief Test if string precedes C string.
2232 : : * @param lhs String.
2233 : : * @param rhs C string.
2234 : : * @return True if @a lhs precedes @a rhs. False otherwise.
2235 : : */
2236 : : template<typename _CharT, typename _Traits, typename _Alloc>
2237 : : inline bool
2238 : : operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2239 : : const _CharT* __rhs)
2240 : : { return __lhs.compare(__rhs) < 0; }
2241 : :
2242 : : /**
2243 : : * @brief Test if C string precedes string.
2244 : : * @param lhs C string.
2245 : : * @param rhs String.
2246 : : * @return True if @a lhs precedes @a rhs. False otherwise.
2247 : : */
2248 : : template<typename _CharT, typename _Traits, typename _Alloc>
2249 : : inline bool
2250 : : operator<(const _CharT* __lhs,
2251 : : const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2252 : : { return __rhs.compare(__lhs) > 0; }
2253 : :
2254 : : // operator >
2255 : : /**
2256 : : * @brief Test if string follows string.
2257 : : * @param lhs First string.
2258 : : * @param rhs Second string.
2259 : : * @return True if @a lhs follows @a rhs. False otherwise.
2260 : : */
2261 : : template<typename _CharT, typename _Traits, typename _Alloc>
2262 : : inline bool
2263 : : operator>(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2264 : : const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2265 : : { return __lhs.compare(__rhs) > 0; }
2266 : :
2267 : : /**
2268 : : * @brief Test if string follows C string.
2269 : : * @param lhs String.
2270 : : * @param rhs C string.
2271 : : * @return True if @a lhs follows @a rhs. False otherwise.
2272 : : */
2273 : : template<typename _CharT, typename _Traits, typename _Alloc>
2274 : : inline bool
2275 : : operator>(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2276 : : const _CharT* __rhs)
2277 : : { return __lhs.compare(__rhs) > 0; }
2278 : :
2279 : : /**
2280 : : * @brief Test if C string follows string.
2281 : : * @param lhs C string.
2282 : : * @param rhs String.
2283 : : * @return True if @a lhs follows @a rhs. False otherwise.
2284 : : */
2285 : : template<typename _CharT, typename _Traits, typename _Alloc>
2286 : : inline bool
2287 : : operator>(const _CharT* __lhs,
2288 : : const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2289 : : { return __rhs.compare(__lhs) < 0; }
2290 : :
2291 : : // operator <=
2292 : : /**
2293 : : * @brief Test if string doesn't follow string.
2294 : : * @param lhs First string.
2295 : : * @param rhs Second string.
2296 : : * @return True if @a lhs doesn't follow @a rhs. False otherwise.
2297 : : */
2298 : : template<typename _CharT, typename _Traits, typename _Alloc>
2299 : : inline bool
2300 : : operator<=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2301 : : const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2302 : : { return __lhs.compare(__rhs) <= 0; }
2303 : :
2304 : : /**
2305 : : * @brief Test if string doesn't follow C string.
2306 : : * @param lhs String.
2307 : : * @param rhs C string.
2308 : : * @return True if @a lhs doesn't follow @a rhs. False otherwise.
2309 : : */
2310 : : template<typename _CharT, typename _Traits, typename _Alloc>
2311 : : inline bool
2312 : : operator<=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2313 : : const _CharT* __rhs)
2314 : : { return __lhs.compare(__rhs) <= 0; }
2315 : :
2316 : : /**
2317 : : * @brief Test if C string doesn't follow string.
2318 : : * @param lhs C string.
2319 : : * @param rhs String.
2320 : : * @return True if @a lhs doesn't follow @a rhs. False otherwise.
2321 : : */
2322 : : template<typename _CharT, typename _Traits, typename _Alloc>
2323 : : inline bool
2324 : : operator<=(const _CharT* __lhs,
2325 : : const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2326 : : { return __rhs.compare(__lhs) >= 0; }
2327 : :
2328 : : // operator >=
2329 : : /**
2330 : : * @brief Test if string doesn't precede string.
2331 : : * @param lhs First string.
2332 : : * @param rhs Second string.
2333 : : * @return True if @a lhs doesn't precede @a rhs. False otherwise.
2334 : : */
2335 : : template<typename _CharT, typename _Traits, typename _Alloc>
2336 : : inline bool
2337 : : operator>=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2338 : : const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2339 : : { return __lhs.compare(__rhs) >= 0; }
2340 : :
2341 : : /**
2342 : : * @brief Test if string doesn't precede C string.
2343 : : * @param lhs String.
2344 : : * @param rhs C string.
2345 : : * @return True if @a lhs doesn't precede @a rhs. False otherwise.
2346 : : */
2347 : : template<typename _CharT, typename _Traits, typename _Alloc>
2348 : : inline bool
2349 : : operator>=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
2350 : : const _CharT* __rhs)
2351 : : { return __lhs.compare(__rhs) >= 0; }
2352 : :
2353 : : /**
2354 : : * @brief Test if C string doesn't precede string.
2355 : : * @param lhs C string.
2356 : : * @param rhs String.
2357 : : * @return True if @a lhs doesn't precede @a rhs. False otherwise.
2358 : : */
2359 : : template<typename _CharT, typename _Traits, typename _Alloc>
2360 : : inline bool
2361 : : operator>=(const _CharT* __lhs,
2362 : : const basic_string<_CharT, _Traits, _Alloc>& __rhs)
2363 : : { return __rhs.compare(__lhs) <= 0; }
2364 : :
2365 : : /**
2366 : : * @brief Swap contents of two strings.
2367 : : * @param lhs First string.
2368 : : * @param rhs Second string.
2369 : : *
2370 : : * Exchanges the contents of @a lhs and @a rhs in constant time.
2371 : : */
2372 : : template<typename _CharT, typename _Traits, typename _Alloc>
2373 : : inline void
2374 : : swap(basic_string<_CharT, _Traits, _Alloc>& __lhs,
2375 : : basic_string<_CharT, _Traits, _Alloc>& __rhs)
2376 : : { __lhs.swap(__rhs); }
2377 : :
2378 : : /**
2379 : : * @brief Read stream into a string.
2380 : : * @param is Input stream.
2381 : : * @param str Buffer to store into.
2382 : : * @return Reference to the input stream.
2383 : : *
2384 : : * Stores characters from @a is into @a str until whitespace is found, the
2385 : : * end of the stream is encountered, or str.max_size() is reached. If
2386 : : * is.width() is non-zero, that is the limit on the number of characters
2387 : : * stored into @a str. Any previous contents of @a str are erased.
2388 : : */
2389 : : template<typename _CharT, typename _Traits, typename _Alloc>
2390 : : basic_istream<_CharT, _Traits>&
2391 : : operator>>(basic_istream<_CharT, _Traits>& __is,
2392 : : basic_string<_CharT, _Traits, _Alloc>& __str);
2393 : :
2394 : : template<>
2395 : : basic_istream<char>&
2396 : : operator>>(basic_istream<char>& __is, basic_string<char>& __str);
2397 : :
2398 : : /**
2399 : : * @brief Write string to a stream.
2400 : : * @param os Output stream.
2401 : : * @param str String to write out.
2402 : : * @return Reference to the output stream.
2403 : : *
2404 : : * Output characters of @a str into os following the same rules as for
2405 : : * writing a C string.
2406 : : */
2407 : : template<typename _CharT, typename _Traits, typename _Alloc>
2408 : : inline basic_ostream<_CharT, _Traits>&
2409 : : operator<<(basic_ostream<_CharT, _Traits>& __os,
2410 : 1033386 : const basic_string<_CharT, _Traits, _Alloc>& __str)
2411 : : {
2412 : : // _GLIBCXX_RESOLVE_LIB_DEFECTS
2413 : : // 586. string inserter not a formatted function
2414 : 1033386 : return __ostream_insert(__os, __str.data(), __str.size());
2415 : : }
2416 : :
2417 : : /**
2418 : : * @brief Read a line from stream into a string.
2419 : : * @param is Input stream.
2420 : : * @param str Buffer to store into.
2421 : : * @param delim Character marking end of line.
2422 : : * @return Reference to the input stream.
2423 : : *
2424 : : * Stores characters from @a is into @a str until @a delim is found, the
2425 : : * end of the stream is encountered, or str.max_size() is reached. If
2426 : : * is.width() is non-zero, that is the limit on the number of characters
2427 : : * stored into @a str. Any previous contents of @a str are erased. If @a
2428 : : * delim was encountered, it is extracted but not stored into @a str.
2429 : : */
2430 : : template<typename _CharT, typename _Traits, typename _Alloc>
2431 : : basic_istream<_CharT, _Traits>&
2432 : : getline(basic_istream<_CharT, _Traits>& __is,
2433 : : basic_string<_CharT, _Traits, _Alloc>& __str, _CharT __delim);
2434 : :
2435 : : /**
2436 : : * @brief Read a line from stream into a string.
2437 : : * @param is Input stream.
2438 : : * @param str Buffer to store into.
2439 : : * @return Reference to the input stream.
2440 : : *
2441 : : * Stores characters from is into @a str until '\n' is found, the end of
2442 : : * the stream is encountered, or str.max_size() is reached. If is.width()
2443 : : * is non-zero, that is the limit on the number of characters stored into
2444 : : * @a str. Any previous contents of @a str are erased. If end of line was
2445 : : * encountered, it is extracted but not stored into @a str.
2446 : : */
2447 : : template<typename _CharT, typename _Traits, typename _Alloc>
2448 : : inline basic_istream<_CharT, _Traits>&
2449 : : getline(basic_istream<_CharT, _Traits>& __is,
2450 : : basic_string<_CharT, _Traits, _Alloc>& __str)
2451 : : { return getline(__is, __str, __is.widen('\n')); }
2452 : :
2453 : : template<>
2454 : : basic_istream<char>&
2455 : : getline(basic_istream<char>& __in, basic_string<char>& __str,
2456 : : char __delim);
2457 : :
2458 : : #ifdef _GLIBCXX_USE_WCHAR_T
2459 : : template<>
2460 : : basic_istream<wchar_t>&
2461 : : getline(basic_istream<wchar_t>& __in, basic_string<wchar_t>& __str,
2462 : : wchar_t __delim);
2463 : : #endif
2464 : :
2465 : : _GLIBCXX_END_NAMESPACE
2466 : :
2467 : : #endif /* _BASIC_STRING_H */
|