libstdc++

vstring.h
Go to the documentation of this file.
1 // Versatile string -*- C++ -*-
2
3 // Copyright (C) 2005-2013 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
9 // any later version.
10
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
19
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
24
25 /** @file ext/vstring.h
26 * This file is a GNU extension to the Standard C++ Library.
27 */
28
29 #ifndef _VSTRING_H
30 #define _VSTRING_H 1
31
32 #pragma GCC system_header
33
34 #if __cplusplus >= 201103L
35 #include <initializer_list>
36 #endif
37
38 #include <ext/vstring_util.h>
39 #include <ext/rc_string_base.h>
40 #include <ext/sso_string_base.h>
41
42 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
43 {
44 _GLIBCXX_BEGIN_NAMESPACE_VERSION
45
46 /**
47 * @class __versa_string vstring.h
48 * @brief Template class __versa_string.
49 * @ingroup extensions
50 *
51 * Data structure managing sequences of characters and
52 * character-like objects.
53 */
54 template<typename _CharT, typename _Traits, typename _Alloc,
55 template <typename, typename, typename> class _Base>
56 class __versa_string
57 : private _Base<_CharT, _Traits, _Alloc>
58 {
59 typedef _Base<_CharT, _Traits, _Alloc> __vstring_base;
60 typedef typename __vstring_base::_CharT_alloc_type _CharT_alloc_type;
61
62 // Types:
63 public:
64 typedef _Traits traits_type;
65 typedef typename _Traits::char_type value_type;
66 typedef _Alloc allocator_type;
67 typedef typename _CharT_alloc_type::size_type size_type;
68 typedef typename _CharT_alloc_type::difference_type difference_type;
69 typedef value_type& reference;
70 typedef const value_type& const_reference;
71 typedef typename _CharT_alloc_type::pointer pointer;
72 typedef typename _CharT_alloc_type::const_pointer const_pointer;
73 typedef __gnu_cxx::__normal_iterator<pointer, __versa_string> iterator;
74 typedef __gnu_cxx::__normal_iterator<const_pointer, __versa_string>
75 const_iterator;
76 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
77 typedef std::reverse_iterator<iterator> reverse_iterator;
78
79 // Data Member (public):
80 /// Value returned by various member functions when they fail.
81 static const size_type npos = static_cast<size_type>(-1);
82
83 private:
84 size_type
85 _M_check(size_type __pos, const char* __s) const
86 {
87 if (__pos > this->size())
88 std::__throw_out_of_range(__N(__s));
89 return __pos;
90 }
91
92 void
93 _M_check_length(size_type __n1, size_type __n2, const char* __s) const
94 {
95 if (this->max_size() - (this->size() - __n1) < __n2)
96 std::__throw_length_error(__N(__s));
97 }
98
99 // NB: _M_limit doesn't check for a bad __pos value.
100 size_type
101 _M_limit(size_type __pos, size_type __off) const
102 {
103 const bool __testoff = __off < this->size() - __pos;
104 return __testoff ? __off : this->size() - __pos;
105 }
106
107 // True if _Rep and source do not overlap.
108 bool
109 _M_disjunct(const _CharT* __s) const
110 {
111 return (std::less<const _CharT*>()(__s, this->_M_data())
112 || std::less<const _CharT*>()(this->_M_data()
113 + this->size(), __s));
114 }
115
116 // For the internal use we have functions similar to `begin'/`end'
117 // but they do not call _M_leak.
118 iterator
119 _M_ibegin() const
120 { return iterator(this->_M_data()); }
121
122 iterator
123 _M_iend() const
124 { return iterator(this->_M_data() + this->_M_length()); }
125
126 public:
127 // Construct/copy/destroy:
128 // NB: We overload ctors in some cases instead of using default
129 // arguments, per 17.4.4.4 para. 2 item 2.
130
131 /**
132 * @brief Default constructor creates an empty string.
133 */
134 __versa_string()
135 : __vstring_base() { }
136
137 /**
138 * @brief Construct an empty string using allocator @a a.
139 */
140 explicit
141 __versa_string(const _Alloc& __a)
142 : __vstring_base(__a) { }
143
144 // NB: per LWG issue 42, semantics different from IS:
145 /**
146 * @brief Construct string with copy of value of @a __str.
147 * @param __str Source string.
148 */
149 __versa_string(const __versa_string& __str)
150 : __vstring_base(__str) { }
151
152 #if __cplusplus >= 201103L
153 /**
154 * @brief String move constructor.
155 * @param __str Source string.
156 *
157 * The newly-constructed %string contains the exact contents of
158 * @a __str. The contents of @a __str are a valid, but unspecified
159 * string.
160 */
161 __versa_string(__versa_string&& __str) noexcept
162 : __vstring_base(std::move(__str)) { }
163
164 /**
165 * @brief Construct string from an initializer list.
166 * @param __l std::initializer_list of characters.
167 * @param __a Allocator to use (default is default allocator).
168 */
169 __versa_string(std::initializer_list<_CharT> __l,
170 const _Alloc& __a = _Alloc())
171 : __vstring_base(__l.begin(), __l.end(), __a) { }
172 #endif
173
174 /**
175 * @brief Construct string as copy of a substring.
176 * @param __str Source string.
177 * @param __pos Index of first character to copy from.
178 * @param __n Number of characters to copy (default remainder).
179 */
180 __versa_string(const __versa_string& __str, size_type __pos,
181 size_type __n = npos)
182 : __vstring_base(__str._M_data()
183 + __str._M_check(__pos,
184 "__versa_string::__versa_string"),
185 __str._M_data() + __str._M_limit(__pos, __n)
186 + __pos, _Alloc()) { }
187
188 /**
189 * @brief Construct string as copy of a substring.
190 * @param __str Source string.
191 * @param __pos Index of first character to copy from.
192 * @param __n Number of characters to copy.
193 * @param __a Allocator to use.
194 */
195 __versa_string(const __versa_string& __str, size_type __pos,
196 size_type __n, const _Alloc& __a)
197 : __vstring_base(__str._M_data()
198 + __str._M_check(__pos,
199 "__versa_string::__versa_string"),
200 __str._M_data() + __str._M_limit(__pos, __n)
201 + __pos, __a) { }
202
203 /**
204 * @brief Construct string initialized by a character array.
205 * @param __s Source character array.
206 * @param __n Number of characters to copy.
207 * @param __a Allocator to use (default is default allocator).
208 *
209 * NB: @a __s must have at least @a __n characters, '\\0' has no special
210 * meaning.
211 */
212 __versa_string(const _CharT* __s, size_type __n,
213 const _Alloc& __a = _Alloc())
214 : __vstring_base(__s, __s + __n, __a) { }
215
216 /**
217 * @brief Construct string as copy of a C string.
218 * @param __s Source C string.
219 * @param __a Allocator to use (default is default allocator).
220 */
221 __versa_string(const _CharT* __s, const _Alloc& __a = _Alloc())
222 : __vstring_base(__s, __s ? __s + traits_type::length(__s) :
223 __s + npos, __a) { }
224
225 /**
226 * @brief Construct string as multiple characters.
227 * @param __n Number of characters.
228 * @param __c Character to use.
229 * @param __a Allocator to use (default is default allocator).
230 */
231 __versa_string(size_type __n, _CharT __c, const _Alloc& __a = _Alloc())
232 : __vstring_base(__n, __c, __a) { }
233
234 /**
235 * @brief Construct string as copy of a range.
236 * @param __beg Start of range.
237 * @param __end End of range.
238 * @param __a Allocator to use (default is default allocator).
239 */
240 #if __cplusplus >= 201103L
241 template<class _InputIterator,
242 typename = std::_RequireInputIter<_InputIterator>>
243 #else
244 template<class _InputIterator>
245 #endif
246 __versa_string(_InputIterator __beg, _InputIterator __end,
247 const _Alloc& __a = _Alloc())
248 : __vstring_base(__beg, __end, __a) { }
249
250 /**
251 * @brief Destroy the string instance.
252 */
253 ~__versa_string() _GLIBCXX_NOEXCEPT { }
254
255 /**
256 * @brief Assign the value of @a str to this string.
257 * @param __str Source string.
258 */
259 __versa_string&
260 operator=(const __versa_string& __str)
261 { return this->assign(__str); }
262
263 #if __cplusplus >= 201103L
264 /**
265 * @brief String move assignment operator.
266 * @param __str Source string.
267 *
268 * The contents of @a __str are moved into this string (without
269 * copying). @a __str is a valid, but unspecified string.
270 */
271 __versa_string&
272 operator=(__versa_string&& __str)
273 {
274 // NB: DR 1204.
275 this->swap(__str);
276 return *this;
277 }
278
279 /**
280 * @brief Set value to string constructed from initializer list.
281 * @param __l std::initializer_list.
282 */
283 __versa_string&
284 operator=(std::initializer_list<_CharT> __l)
285 {
286 this->assign(__l.begin(), __l.end());
287 return *this;
288 }
289 #endif
290
291 /**
292 * @brief Copy contents of @a __s into this string.
293 * @param __s Source null-terminated string.
294 */
295 __versa_string&
296 operator=(const _CharT* __s)
297 { return this->assign(__s); }
298
299 /**
300 * @brief Set value to string of length 1.
301 * @param __c Source character.
302 *
303 * Assigning to a character makes this string length 1 and
304 * (*this)[0] == @a __c.
305 */
306 __versa_string&
307 operator=(_CharT __c)
308 {
309 this->assign(1, __c);
310 return *this;
311 }
312
313 // Iterators:
314 /**
315 * Returns a read/write iterator that points to the first character in
316 * the %string. Unshares the string.
317 */
318 iterator
319 begin() _GLIBCXX_NOEXCEPT
320 {
321 this->_M_leak();
322 return iterator(this->_M_data());
323 }
324
325 /**
326 * Returns a read-only (constant) iterator that points to the first
327 * character in the %string.
328 */
329 const_iterator
330 begin() const _GLIBCXX_NOEXCEPT
331 { return const_iterator(this->_M_data()); }
332
333 /**
334 * Returns a read/write iterator that points one past the last
335 * character in the %string. Unshares the string.
336 */
337 iterator
338 end() _GLIBCXX_NOEXCEPT
339 {
340 this->_M_leak();
341 return iterator(this->_M_data() + this->size());
342 }
343
344 /**
345 * Returns a read-only (constant) iterator that points one past the
346 * last character in the %string.
347 */
348 const_iterator
349 end() const _GLIBCXX_NOEXCEPT
350 { return const_iterator(this->_M_data() + this->size()); }
351
352 /**
353 * Returns a read/write reverse iterator that points to the last
354 * character in the %string. Iteration is done in reverse element
355 * order. Unshares the string.
356 */
357 reverse_iterator
358 rbegin() _GLIBCXX_NOEXCEPT
359 { return reverse_iterator(this->end()); }
360
361 /**
362 * Returns a read-only (constant) reverse iterator that points
363 * to the last character in the %string. Iteration is done in
364 * reverse element order.
365 */
366 const_reverse_iterator
367 rbegin() const _GLIBCXX_NOEXCEPT
368 { return const_reverse_iterator(this->end()); }
369
370 /**
371 * Returns a read/write reverse iterator that points to one before the
372 * first character in the %string. Iteration is done in reverse
373 * element order. Unshares the string.
374 */
375 reverse_iterator
376 rend() _GLIBCXX_NOEXCEPT
377 { return reverse_iterator(this->begin()); }
378
379 /**
380 * Returns a read-only (constant) reverse iterator that points
381 * to one before the first character in the %string. Iteration
382 * is done in reverse element order.
383 */
384 const_reverse_iterator
385 rend() const _GLIBCXX_NOEXCEPT
386 { return const_reverse_iterator(this->begin()); }
387
388 #if __cplusplus >= 201103L
389 /**
390 * Returns a read-only (constant) iterator that points to the first
391 * character in the %string.
392 */
393 const_iterator
394 cbegin() const noexcept
395 { return const_iterator(this->_M_data()); }
396
397 /**
398 * Returns a read-only (constant) iterator that points one past the
399 * last character in the %string.
400 */
401 const_iterator
402 cend() const noexcept
403 { return const_iterator(this->_M_data() + this->size()); }
404
405 /**
406 * Returns a read-only (constant) reverse iterator that points
407 * to the last character in the %string. Iteration is done in
408 * reverse element order.
409 */
410 const_reverse_iterator
411 crbegin() const noexcept
412 { return const_reverse_iterator(this->end()); }
413
414 /**
415 * Returns a read-only (constant) reverse iterator that points
416 * to one before the first character in the %string. Iteration
417 * is done in reverse element order.
418 */
419 const_reverse_iterator
420 crend() const noexcept
421 { return const_reverse_iterator(this->begin()); }
422 #endif
423
424 public:
425 // Capacity:
426 /// Returns the number of characters in the string, not including any
427 /// null-termination.
428 size_type
429 size() const _GLIBCXX_NOEXCEPT
430 { return this->_M_length(); }
431
432 /// Returns the number of characters in the string, not including any
433 /// null-termination.
434 size_type
435 length() const _GLIBCXX_NOEXCEPT
436 { return this->_M_length(); }
437
438 /// Returns the size() of the largest possible %string.
439 size_type
440 max_size() const _GLIBCXX_NOEXCEPT
441 { return this->_M_max_size(); }
442
443 /**
444 * @brief Resizes the %string to the specified number of characters.
445 * @param __n Number of characters the %string should contain.
446 * @param __c Character to fill any new elements.
447 *
448 * This function will %resize the %string to the specified
449 * number of characters. If the number is smaller than the
450 * %string's current size the %string is truncated, otherwise
451 * the %string is extended and new elements are set to @a __c.
452 */
453 void
454 resize(size_type __n, _CharT __c);
455
456 /**
457 * @brief Resizes the %string to the specified number of characters.
458 * @param __n Number of characters the %string should contain.
459 *
460 * This function will resize the %string to the specified
461 * length. If the new size is smaller than the %string's
462 * current size the %string is truncated, otherwise the %string
463 * is extended and new characters are default-constructed. For
464 * basic types such as char, this means setting them to 0.
465 */
466 void
467 resize(size_type __n)
468 { this->resize(__n, _CharT()); }
469
470 #if __cplusplus >= 201103L
471 /// A non-binding request to reduce capacity() to size().
472 void
473 shrink_to_fit()
474 {
475 if (capacity() > size())
476 {
477 __try
478 { this->reserve(0); }
479 __catch(...)
480 { }
481 }
482 }
483 #endif
484
485 /**
486 * Returns the total number of characters that the %string can
487 * hold before needing to allocate more memory.
488 */
489 size_type
490 capacity() const _GLIBCXX_NOEXCEPT
491 { return this->_M_capacity(); }
492
493 /**
494 * @brief Attempt to preallocate enough memory for specified number of
495 * characters.
496 * @param __res_arg Number of characters required.
497 * @throw std::length_error If @a __res_arg exceeds @c max_size().
498 *
499 * This function attempts to reserve enough memory for the
500 * %string to hold the specified number of characters. If the
501 * number requested is more than max_size(), length_error is
502 * thrown.
503 *
504 * The advantage of this function is that if optimal code is a
505 * necessity and the user can determine the string length that
506 * will be required, the user can reserve the memory in
507 * %advance, and thus prevent a possible reallocation of memory
508 * and copying of %string data.
509 */
510 void
511 reserve(size_type __res_arg = 0)
512 { this->_M_reserve(__res_arg); }
513
514 /**
515 * Erases the string, making it empty.
516 */
517 void
518 clear() _GLIBCXX_NOEXCEPT
519 { this->_M_clear(); }
520
521 /**
522 * Returns true if the %string is empty. Equivalent to
523 * <code>*this == ""</code>.
524 */
525 bool
526 empty() const _GLIBCXX_NOEXCEPT
527 { return this->size() == 0; }
528
529 // Element access:
530 /**
531 * @brief Subscript access to the data contained in the %string.
532 * @param __pos The index of the character to access.
533 * @return Read-only (constant) reference to the character.
534 *
535 * This operator allows for easy, array-style, data access.
536 * Note that data access with this operator is unchecked and
537 * out_of_range lookups are not defined. (For checked lookups
538 * see at().)
539 */
540 const_reference
541 operator[] (size_type __pos) const
542 {
543 _GLIBCXX_DEBUG_ASSERT(__pos <= this->size());
544 return this->_M_data()[__pos];
545 }
546
547 /**
548 * @brief Subscript access to the data contained in the %string.
549 * @param __pos The index of the character to access.
550 * @return Read/write reference to the character.
551 *
552 * This operator allows for easy, array-style, data access.
553 * Note that data access with this operator is unchecked and
554 * out_of_range lookups are not defined. (For checked lookups
555 * see at().) Unshares the string.
556 */
557 reference
558 operator[](size_type __pos)
559 {
560 // allow pos == size() as v3 extension:
561 _GLIBCXX_DEBUG_ASSERT(__pos <= this->size());
562 // but be strict in pedantic mode:
563 _GLIBCXX_DEBUG_PEDASSERT(__pos < this->size());
564 this->_M_leak();
565 return this->_M_data()[__pos];
566 }
567
568 /**
569 * @brief Provides access to the data contained in the %string.
570 * @param __n The index of the character to access.
571 * @return Read-only (const) reference to the character.
572 * @throw std::out_of_range If @a __n is an invalid index.
573 *
574 * This function provides for safer data access. The parameter
575 * is first checked that it is in the range of the string. The
576 * function throws out_of_range if the check fails.
577 */
578 const_reference
579 at(size_type __n) const
580 {
581 if (__n >= this->size())
582 std::__throw_out_of_range(__N("__versa_string::at"));
583 return this->_M_data()[__n];
584 }
585
586 /**
587 * @brief Provides access to the data contained in the %string.
588 * @param __n The index of the character to access.
589 * @return Read/write reference to the character.
590 * @throw std::out_of_range If @a __n is an invalid index.
591 *
592 * This function provides for safer data access. The parameter
593 * is first checked that it is in the range of the string. The
594 * function throws out_of_range if the check fails. Success
595 * results in unsharing the string.
596 */
597 reference
598 at(size_type __n)
599 {
600 if (__n >= this->size())
601 std::__throw_out_of_range(__N("__versa_string::at"));
602 this->_M_leak();
603 return this->_M_data()[__n];
604 }
605
606 #if __cplusplus >= 201103L
607 /**
608 * Returns a read/write reference to the data at the first
609 * element of the %string.
610 */
611 reference
612 front()
613 { return operator[](0); }
614
615 /**
616 * Returns a read-only (constant) reference to the data at the first
617 * element of the %string.
618 */
619 const_reference
620 front() const
621 { return operator[](0); }
622
623 /**
624 * Returns a read/write reference to the data at the last
625 * element of the %string.
626 */
627 reference
628 back()
629 { return operator[](this->size() - 1); }
630
631 /**
632 * Returns a read-only (constant) reference to the data at the
633 * last element of the %string.
634 */
635 const_reference
636 back() const
637 { return operator[](this->size() - 1); }
638 #endif
639
640 // Modifiers:
641 /**
642 * @brief Append a string to this string.
643 * @param __str The string to append.
644 * @return Reference to this string.
645 */
646 __versa_string&
647 operator+=(const __versa_string& __str)
648 { return this->append(__str); }
649
650 /**
651 * @brief Append a C string.
652 * @param __s The C string to append.
653 * @return Reference to this string.
654 */
655 __versa_string&
656 operator+=(const _CharT* __s)
657 { return this->append(__s); }
658
659 /**
660 * @brief Append a character.
661 * @param __c The character to append.
662 * @return Reference to this string.
663 */
664 __versa_string&
665 operator+=(_CharT __c)
666 {
667 this->push_back(__c);
668 return *this;
669 }
670
671 #if __cplusplus >= 201103L
672 /**
673 * @brief Append an initializer_list of characters.
674 * @param __l The initializer_list of characters to be appended.
675 * @return Reference to this string.
676 */
677 __versa_string&
678 operator+=(std::initializer_list<_CharT> __l)
679 { return this->append(__l.begin(), __l.end()); }
680 #endif // C++11
681
682 /**
683 * @brief Append a string to this string.
684 * @param __str The string to append.
685 * @return Reference to this string.
686 */
687 __versa_string&
688 append(const __versa_string& __str)
689 { return _M_append(__str._M_data(), __str.size()); }
690
691 /**
692 * @brief Append a substring.
693 * @param __str The string to append.
694 * @param __pos Index of the first character of str to append.
695 * @param __n The number of characters to append.
696 * @return Reference to this string.
697 * @throw std::out_of_range if @a pos is not a valid index.
698 *
699 * This function appends @a __n characters from @a __str
700 * starting at @a __pos to this string. If @a __n is is larger
701 * than the number of available characters in @a __str, the
702 * remainder of @a __str is appended.
703 */
704 __versa_string&
705 append(const __versa_string& __str, size_type __pos, size_type __n)
706 { return _M_append(__str._M_data()
707 + __str._M_check(__pos, "__versa_string::append"),
708 __str._M_limit(__pos, __n)); }
709
710 /**
711 * @brief Append a C substring.
712 * @param __s The C string to append.
713 * @param __n The number of characters to append.
714 * @return Reference to this string.
715 */
716 __versa_string&
717 append(const _CharT* __s, size_type __n)
718 {
719 __glibcxx_requires_string_len(__s, __n);
720 _M_check_length(size_type(0), __n, "__versa_string::append");
721 return _M_append(__s, __n);
722 }
723
724 /**
725 * @brief Append a C string.
726 * @param __s The C string to append.
727 * @return Reference to this string.
728 */
729 __versa_string&
730 append(const _CharT* __s)
731 {
732 __glibcxx_requires_string(__s);
733 const size_type __n = traits_type::length(__s);
734 _M_check_length(size_type(0), __n, "__versa_string::append");
735 return _M_append(__s, __n);
736 }
737
738 /**
739 * @brief Append multiple characters.
740 * @param __n The number of characters to append.
741 * @param __c The character to use.
742 * @return Reference to this string.
743 *
744 * Appends n copies of c to this string.
745 */
746 __versa_string&
747 append(size_type __n, _CharT __c)
748 { return _M_replace_aux(this->size(), size_type(0), __n, __c); }
749
750 #if __cplusplus >= 201103L
751 /**
752 * @brief Append an initializer_list of characters.
753 * @param __l The initializer_list of characters to append.
754 * @return Reference to this string.
755 */
756 __versa_string&
757 append(std::initializer_list<_CharT> __l)
758 { return this->append(__l.begin(), __l.end()); }
759 #endif // C++11
760
761 /**
762 * @brief Append a range of characters.
763 * @param __first Iterator referencing the first character to append.
764 * @param __last Iterator marking the end of the range.
765 * @return Reference to this string.
766 *
767 * Appends characters in the range [first,last) to this string.
768 */
769 #if __cplusplus >= 201103L
770 template<class _InputIterator,
771 typename = std::_RequireInputIter<_InputIterator>>
772 #else
773 template<class _InputIterator>
774 #endif
775 __versa_string&
776 append(_InputIterator __first, _InputIterator __last)
777 { return this->replace(_M_iend(), _M_iend(), __first, __last); }
778
779 /**
780 * @brief Append a single character.
781 * @param __c Character to append.
782 */
783 void
784 push_back(_CharT __c)
785 {
786 const size_type __size = this->size();
787 if (__size + 1 > this->capacity() || this->_M_is_shared())
788 this->_M_mutate(__size, size_type(0), 0, size_type(1));
789 traits_type::assign(this->_M_data()[__size], __c);
790 this->_M_set_length(__size + 1);
791 }
792
793 /**
794 * @brief Set value to contents of another string.
795 * @param __str Source string to use.
796 * @return Reference to this string.
797 */
798 __versa_string&
799 assign(const __versa_string& __str)
800 {
801 this->_M_assign(__str);
802 return *this;
803 }
804
805 #if __cplusplus >= 201103L
806 /**
807 * @brief Set value to contents of another string.
808 * @param __str Source string to use.
809 * @return Reference to this string.
810 *
811 * This function sets this string to the exact contents of @a __str.
812 * @a __str is a valid, but unspecified string.
813 */
814 __versa_string&
815 assign(__versa_string&& __str)
816 {
817 this->swap(__str);
818 return *this;
819 }
820 #endif // C++11
821
822 /**
823 * @brief Set value to a substring of a string.
824 * @param __str The string to use.
825 * @param __pos Index of the first character of str.
826 * @param __n Number of characters to use.
827 * @return Reference to this string.
828 * @throw std::out_of_range if @a __pos is not a valid index.
829 *
830 * This function sets this string to the substring of @a __str
831 * consisting of @a __n characters at @a __pos. If @a __n is
832 * is larger than the number of available characters in @a
833 * __str, the remainder of @a __str is used.
834 */
835 __versa_string&
836 assign(const __versa_string& __str, size_type __pos, size_type __n)
837 { return _M_replace(size_type(0), this->size(), __str._M_data()
838 + __str._M_check(__pos, "__versa_string::assign"),
839 __str._M_limit(__pos, __n)); }
840
841 /**
842 * @brief Set value to a C substring.
843 * @param __s The C string to use.
844 * @param __n Number of characters to use.
845 * @return Reference to this string.
846 *
847 * This function sets the value of this string to the first @a
848 * __n characters of @a __s. If @a __n is is larger than the
849 * number of available characters in @a __s, the remainder of
850 * @a __s is used.
851 */
852 __versa_string&
853 assign(const _CharT* __s, size_type __n)
854 {
855 __glibcxx_requires_string_len(__s, __n);
856 return _M_replace(size_type(0), this->size(), __s, __n);
857 }
858
859 /**
860 * @brief Set value to contents of a C string.
861 * @param __s The C string to use.
862 * @return Reference to this string.
863 *
864 * This function sets the value of this string to the value of
865 * @a __s. The data is copied, so there is no dependence on @a
866 * __s once the function returns.
867 */
868 __versa_string&
869 assign(const _CharT* __s)
870 {
871 __glibcxx_requires_string(__s);
872 return _M_replace(size_type(0), this->size(), __s,
873 traits_type::length(__s));
874 }
875
876 /**
877 * @brief Set value to multiple characters.
878 * @param __n Length of the resulting string.
879 * @param __c The character to use.
880 * @return Reference to this string.
881 *
882 * This function sets the value of this string to @a __n copies of
883 * character @a __c.
884 */
885 __versa_string&
886 assign(size_type __n, _CharT __c)
887 { return _M_replace_aux(size_type(0), this->size(), __n, __c); }
888
889 /**
890 * @brief Set value to a range of characters.
891 * @param __first Iterator referencing the first character to append.
892 * @param __last Iterator marking the end of the range.
893 * @return Reference to this string.
894 *
895 * Sets value of string to characters in the range
896 * [first,last).
897 */
898 #if __cplusplus >= 201103L
899 template<class _InputIterator,
900 typename = std::_RequireInputIter<_InputIterator>>
901 #else
902 template<class _InputIterator>
903 #endif
904 __versa_string&
905 assign(_InputIterator __first, _InputIterator __last)
906 { return this->replace(_M_ibegin(), _M_iend(), __first, __last); }
907
908 #if __cplusplus >= 201103L
909 /**
910 * @brief Set value to an initializer_list of characters.
911 * @param __l The initializer_list of characters to assign.
912 * @return Reference to this string.
913 */
914 __versa_string&
915 assign(std::initializer_list<_CharT> __l)
916 { return this->assign(__l.begin(), __l.end()); }
917 #endif // C++11
918
919 /**
920 * @brief Insert multiple characters.
921 * @param __p Iterator referencing location in string to insert at.
922 * @param __n Number of characters to insert
923 * @param __c The character to insert.
924 * @throw std::length_error If new length exceeds @c max_size().
925 *
926 * Inserts @a __n copies of character @a __c starting at the
927 * position referenced by iterator @a __p. If adding
928 * characters causes the length to exceed max_size(),
929 * length_error is thrown. The value of the string doesn't
930 * change if an error is thrown.
931 */
932 void
933 insert(iterator __p, size_type __n, _CharT __c)
934 { this->replace(__p, __p, __n, __c); }
935
936 /**
937 * @brief Insert a range of characters.
938 * @param __p Iterator referencing location in string to insert at.
939 * @param __beg Start of range.
940 * @param __end End of range.
941 * @throw std::length_error If new length exceeds @c max_size().
942 *
943 * Inserts characters in range [beg,end). If adding characters
944 * causes the length to exceed max_size(), length_error is
945 * thrown. The value of the string doesn't change if an error
946 * is thrown.
947 */
948 #if __cplusplus >= 201103L
949 template<class _InputIterator,
950 typename = std::_RequireInputIter<_InputIterator>>
951 #else
952 template<class _InputIterator>
953 #endif
954 void
955 insert(iterator __p, _InputIterator __beg, _InputIterator __end)
956 { this->replace(__p, __p, __beg, __end); }
957
958 #if __cplusplus >= 201103L
959 /**
960 * @brief Insert an initializer_list of characters.
961 * @param __p Iterator referencing location in string to insert at.
962 * @param __l The initializer_list of characters to insert.
963 * @throw std::length_error If new length exceeds @c max_size().
964 */
965 void
966 insert(iterator __p, std::initializer_list<_CharT> __l)
967 { this->insert(__p, __l.begin(), __l.end()); }
968 #endif // C++11
969
970 /**
971 * @brief Insert value of a string.
972 * @param __pos1 Iterator referencing location in string to insert at.
973 * @param __str The string to insert.
974 * @return Reference to this string.
975 * @throw std::length_error If new length exceeds @c max_size().
976 *
977 * Inserts value of @a __str starting at @a __pos1. If adding
978 * characters causes the length to exceed max_size(),
979 * length_error is thrown. The value of the string doesn't
980 * change if an error is thrown.
981 */
982 __versa_string&
983 insert(size_type __pos1, const __versa_string& __str)
984 { return this->replace(__pos1, size_type(0),
985 __str._M_data(), __str.size()); }
986
987 /**
988 * @brief Insert a substring.
989 * @param __pos1 Iterator referencing location in string to insert at.
990 * @param __str The string to insert.
991 * @param __pos2 Start of characters in str to insert.
992 * @param __n Number of characters to insert.
993 * @return Reference to this string.
994 * @throw std::length_error If new length exceeds @c max_size().
995 * @throw std::out_of_range If @a __pos1 > size() or
996 * @a __pos2 > @a __str.size().
997 *
998 * Starting at @a __pos1, insert @a __n character of @a __str
999 * beginning with @a __pos2. If adding characters causes the
1000 * length to exceed max_size(), length_error is thrown. If @a
1001 * __pos1 is beyond the end of this string or @a __pos2 is
1002 * beyond the end of @a __str, out_of_range is thrown. The
1003 * value of the string doesn't change if an error is thrown.
1004 */
1005 __versa_string&
1006 insert(size_type __pos1, const __versa_string& __str,
1007 size_type __pos2, size_type __n)
1008 { return this->replace(__pos1, size_type(0), __str._M_data()
1009 + __str._M_check(__pos2, "__versa_string::insert"),
1010 __str._M_limit(__pos2, __n)); }
1011
1012 /**
1013 * @brief Insert a C substring.
1014 * @param __pos Iterator referencing location in string to insert at.
1015 * @param __s The C string to insert.
1016 * @param __n The number of characters to insert.
1017 * @return Reference to this string.
1018 * @throw std::length_error If new length exceeds @c max_size().
1019 * @throw std::out_of_range If @a __pos is beyond the end of this
1020 * string.
1021 *
1022 * Inserts the first @a __n characters of @a __s starting at @a
1023 * __pos. If adding characters causes the length to exceed
1024 * max_size(), length_error is thrown. If @a __pos is beyond
1025 * end(), out_of_range is thrown. The value of the string
1026 * doesn't change if an error is thrown.
1027 */
1028 __versa_string&
1029 insert(size_type __pos, const _CharT* __s, size_type __n)
1030 { return this->replace(__pos, size_type(0), __s, __n); }
1031
1032 /**
1033 * @brief Insert a C string.
1034 * @param __pos Iterator referencing location in string to insert at.
1035 * @param __s The C string to insert.
1036 * @return Reference to this string.
1037 * @throw std::length_error If new length exceeds @c max_size().
1038 * @throw std::out_of_range If @a __pos is beyond the end of this
1039 * string.
1040 *
1041 * Inserts the first @a __n characters of @a __s starting at @a
1042 * __pos. If adding characters causes the length to exceed
1043 * max_size(), length_error is thrown. If @a __pos is beyond
1044 * end(), out_of_range is thrown. The value of the string
1045 * doesn't change if an error is thrown.
1046 */
1047 __versa_string&
1048 insert(size_type __pos, const _CharT* __s)
1049 {
1050 __glibcxx_requires_string(__s);
1051 return this->replace(__pos, size_type(0), __s,
1052 traits_type::length(__s));
1053 }
1054
1055 /**
1056 * @brief Insert multiple characters.
1057 * @param __pos Index in string to insert at.
1058 * @param __n Number of characters to insert
1059 * @param __c The character to insert.
1060 * @return Reference to this string.
1061 * @throw std::length_error If new length exceeds @c max_size().
1062 * @throw std::out_of_range If @a __pos is beyond the end of this
1063 * string.
1064 *
1065 * Inserts @a __n copies of character @a __c starting at index
1066 * @a __pos. If adding characters causes the length to exceed
1067 * max_size(), length_error is thrown. If @a __pos > length(),
1068 * out_of_range is thrown. The value of the string doesn't
1069 * change if an error is thrown.
1070 */
1071 __versa_string&
1072 insert(size_type __pos, size_type __n, _CharT __c)
1073 { return _M_replace_aux(_M_check(__pos, "__versa_string::insert"),
1074 size_type(0), __n, __c); }
1075
1076 /**
1077 * @brief Insert one character.
1078 * @param __p Iterator referencing position in string to insert at.
1079 * @param __c The character to insert.
1080 * @return Iterator referencing newly inserted char.
1081 * @throw std::length_error If new length exceeds @c max_size().
1082 *
1083 * Inserts character @a __c at position referenced by @a __p.
1084 * If adding character causes the length to exceed max_size(),
1085 * length_error is thrown. If @a __p is beyond end of string,
1086 * out_of_range is thrown. The value of the string doesn't
1087 * change if an error is thrown.
1088 */
1089 iterator
1090 insert(iterator __p, _CharT __c)
1091 {
1092 _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend());
1093 const size_type __pos = __p - _M_ibegin();
1094 _M_replace_aux(__pos, size_type(0), size_type(1), __c);
1095 this->_M_set_leaked();
1096 return iterator(this->_M_data() + __pos);
1097 }
1098
1099 /**
1100 * @brief Remove characters.
1101 * @param __pos Index of first character to remove (default 0).
1102 * @param __n Number of characters to remove (default remainder).
1103 * @return Reference to this string.
1104 * @throw std::out_of_range If @a __pos is beyond the end of this
1105 * string.
1106 *
1107 * Removes @a __n characters from this string starting at @a
1108 * __pos. The length of the string is reduced by @a __n. If
1109 * there are < @a __n characters to remove, the remainder of
1110 * the string is truncated. If @a __p is beyond end of string,
1111 * out_of_range is thrown. The value of the string doesn't
1112 * change if an error is thrown.
1113 */
1114 __versa_string&
1115 erase(size_type __pos = 0, size_type __n = npos)
1116 {
1117 this->_M_erase(_M_check(__pos, "__versa_string::erase"),
1118 _M_limit(__pos, __n));
1119 return *this;
1120 }
1121
1122 /**
1123 * @brief Remove one character.
1124 * @param __position Iterator referencing the character to remove.
1125 * @return iterator referencing same location after removal.
1126 *
1127 * Removes the character at @a __position from this string. The
1128 * value of the string doesn't change if an error is thrown.
1129 */
1130 iterator
1131 erase(iterator __position)
1132 {
1133 _GLIBCXX_DEBUG_PEDASSERT(__position >= _M_ibegin()
1134 && __position < _M_iend());
1135 const size_type __pos = __position - _M_ibegin();
1136 this->_M_erase(__pos, size_type(1));
1137 this->_M_set_leaked();
1138 return iterator(this->_M_data() + __pos);
1139 }
1140
1141 /**
1142 * @brief Remove a range of characters.
1143 * @param __first Iterator referencing the first character to remove.
1144 * @param __last Iterator referencing the end of the range.
1145 * @return Iterator referencing location of first after removal.
1146 *
1147 * Removes the characters in the range [first,last) from this
1148 * string. The value of the string doesn't change if an error
1149 * is thrown.
1150 */
1151 iterator
1152 erase(iterator __first, iterator __last)
1153 {
1154 _GLIBCXX_DEBUG_PEDASSERT(__first >= _M_ibegin() && __first <= __last
1155 && __last <= _M_iend());
1156 const size_type __pos = __first - _M_ibegin();
1157 this->_M_erase(__pos, __last - __first);
1158 this->_M_set_leaked();
1159 return iterator(this->_M_data() + __pos);
1160 }
1161
1162 #if __cplusplus >= 201103L
1163 /**
1164 * @brief Remove the last character.
1165 *
1166 * The string must be non-empty.
1167 */
1168 void
1169 pop_back()
1170 { this->_M_erase(size()-1, 1); }
1171 #endif // C++11
1172
1173 /**
1174 * @brief Replace characters with value from another string.
1175 * @param __pos Index of first character to replace.
1176 * @param __n Number of characters to be replaced.
1177 * @param __str String to insert.
1178 * @return Reference to this string.
1179 * @throw std::out_of_range If @a __pos is beyond the end of this
1180 * string.
1181 * @throw std::length_error If new length exceeds @c max_size().
1182 *
1183 * Removes the characters in the range [pos,pos+n) from this
1184 * string. In place, the value of @a __str is inserted. If @a
1185 * __pos is beyond end of string, out_of_range is thrown. If
1186 * the length of the result exceeds max_size(), length_error is
1187 * thrown. The value of the string doesn't change if an error
1188 * is thrown.
1189 */
1190 __versa_string&
1191 replace(size_type __pos, size_type __n, const __versa_string& __str)
1192 { return this->replace(__pos, __n, __str._M_data(), __str.size()); }
1193
1194 /**
1195 * @brief Replace characters with value from another string.
1196 * @param __pos1 Index of first character to replace.
1197 * @param __n1 Number of characters to be replaced.
1198 * @param __str String to insert.
1199 * @param __pos2 Index of first character of str to use.
1200 * @param __n2 Number of characters from str to use.
1201 * @return Reference to this string.
1202 * @throw std::out_of_range If @a __pos1 > size() or @a __pos2 >
1203 * str.size().
1204 * @throw std::length_error If new length exceeds @c max_size().
1205 *
1206 * Removes the characters in the range [pos1,pos1 + n) from
1207 * this string. In place, the value of @a __str is inserted.
1208 * If @a __pos is beyond end of string, out_of_range is thrown.
1209 * If the length of the result exceeds max_size(), length_error
1210 * is thrown. The value of the string doesn't change if an
1211 * error is thrown.
1212 */
1213 __versa_string&
1214 replace(size_type __pos1, size_type __n1, const __versa_string& __str,
1215 size_type __pos2, size_type __n2)
1216 {
1217 return this->replace(__pos1, __n1, __str._M_data()
1218 + __str._M_check(__pos2,
1219 "__versa_string::replace"),
1220 __str._M_limit(__pos2, __n2));
1221 }
1222
1223 /**
1224 * @brief Replace characters with value of a C substring.
1225 * @param __pos Index of first character to replace.
1226 * @param __n1 Number of characters to be replaced.
1227 * @param __s C string to insert.
1228 * @param __n2 Number of characters from @a __s to use.
1229 * @return Reference to this string.
1230 * @throw std::out_of_range If @a __pos1 > size().
1231 * @throw std::length_error If new length exceeds @c max_size().
1232 *
1233 * Removes the characters in the range [pos,pos + n1) from this
1234 * string. In place, the first @a __n2 characters of @a __s
1235 * are inserted, or all of @a __s if @a __n2 is too large. If
1236 * @a __pos is beyond end of string, out_of_range is thrown.
1237 * If the length of result exceeds max_size(), length_error is
1238 * thrown. The value of the string doesn't change if an error
1239 * is thrown.
1240 */
1241 __versa_string&
1242 replace(size_type __pos, size_type __n1, const _CharT* __s,
1243 size_type __n2)
1244 {
1245 __glibcxx_requires_string_len(__s, __n2);
1246 return _M_replace(_M_check(__pos, "__versa_string::replace"),
1247 _M_limit(__pos, __n1), __s, __n2);
1248 }
1249
1250 /**
1251 * @brief Replace characters with value of a C string.
1252 * @param __pos Index of first character to replace.
1253 * @param __n1 Number of characters to be replaced.
1254 * @param __s C string to insert.
1255 * @return Reference to this string.
1256 * @throw std::out_of_range If @a __pos > size().
1257 * @throw std::length_error If new length exceeds @c max_size().
1258 *
1259 * Removes the characters in the range [pos,pos + n1) from this
1260 * string. In place, the characters of @a __s are inserted. If
1261 * @a pos is beyond end of string, out_of_range is thrown. If
1262 * the length of result exceeds max_size(), length_error is thrown.
1263 * The value of the string doesn't change if an error is thrown.
1264 */
1265 __versa_string&
1266 replace(size_type __pos, size_type __n1, const _CharT* __s)
1267 {
1268 __glibcxx_requires_string(__s);
1269 return this->replace(__pos, __n1, __s, traits_type::length(__s));
1270 }
1271
1272 /**
1273 * @brief Replace characters with multiple characters.
1274 * @param __pos Index of first character to replace.
1275 * @param __n1 Number of characters to be replaced.
1276 * @param __n2 Number of characters to insert.
1277 * @param __c Character to insert.
1278 * @return Reference to this string.
1279 * @throw std::out_of_range If @a __pos > size().
1280 * @throw std::length_error If new length exceeds @c max_size().
1281 *
1282 * Removes the characters in the range [pos,pos + n1) from this
1283 * string. In place, @a __n2 copies of @a __c are inserted.
1284 * If @a __pos is beyond end of string, out_of_range is thrown.
1285 * If the length of result exceeds max_size(), length_error is
1286 * thrown. The value of the string doesn't change if an error
1287 * is thrown.
1288 */
1289 __versa_string&
1290 replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
1291 { return _M_replace_aux(_M_check(__pos, "__versa_string::replace"),
1292 _M_limit(__pos, __n1), __n2, __c); }
1293
1294 /**
1295 * @brief Replace range of characters with string.
1296 * @param __i1 Iterator referencing start of range to replace.
1297 * @param __i2 Iterator referencing end of range to replace.
1298 * @param __str String value to insert.
1299 * @return Reference to this string.
1300 * @throw std::length_error If new length exceeds @c max_size().
1301 *
1302 * Removes the characters in the range [i1,i2). In place, the
1303 * value of @a __str is inserted. If the length of result
1304 * exceeds max_size(), length_error is thrown. The value of
1305 * the string doesn't change if an error is thrown.
1306 */
1307 __versa_string&
1308 replace(iterator __i1, iterator __i2, const __versa_string& __str)
1309 { return this->replace(__i1, __i2, __str._M_data(), __str.size()); }
1310
1311 /**
1312 * @brief Replace range of characters with C substring.
1313 * @param __i1 Iterator referencing start of range to replace.
1314 * @param __i2 Iterator referencing end of range to replace.
1315 * @param __s C string value to insert.
1316 * @param __n Number of characters from s to insert.
1317 * @return Reference to this string.
1318 * @throw std::length_error If new length exceeds @c max_size().
1319 *
1320 * Removes the characters in the range [i1,i2). In place, the
1321 * first @a n characters of @a __s are inserted. If the length
1322 * of result exceeds max_size(), length_error is thrown. The
1323 * value of the string doesn't change if an error is thrown.
1324 */
1325 __versa_string&
1326 replace(iterator __i1, iterator __i2, const _CharT* __s, size_type __n)
1327 {
1328 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1329 && __i2 <= _M_iend());
1330 return this->replace(__i1 - _M_ibegin(), __i2 - __i1, __s, __n);
1331 }
1332
1333 /**
1334 * @brief Replace range of characters with C string.
1335 * @param __i1 Iterator referencing start of range to replace.
1336 * @param __i2 Iterator referencing end of range to replace.
1337 * @param __s C string value to insert.
1338 * @return Reference to this string.
1339 * @throw std::length_error If new length exceeds @c max_size().
1340 *
1341 * Removes the characters in the range [i1,i2). In place, the
1342 * characters of @a __s are inserted. If the length of result
1343 * exceeds max_size(), length_error is thrown. The value of
1344 * the string doesn't change if an error is thrown.
1345 */
1346 __versa_string&
1347 replace(iterator __i1, iterator __i2, const _CharT* __s)
1348 {
1349 __glibcxx_requires_string(__s);
1350 return this->replace(__i1, __i2, __s, traits_type::length(__s));
1351 }
1352
1353 /**
1354 * @brief Replace range of characters with multiple characters
1355 * @param __i1 Iterator referencing start of range to replace.
1356 * @param __i2 Iterator referencing end of range to replace.
1357 * @param __n Number of characters to insert.
1358 * @param __c Character to insert.
1359 * @return Reference to this string.
1360 * @throw std::length_error If new length exceeds @c max_size().
1361 *
1362 * Removes the characters in the range [i1,i2). In place, @a
1363 * __n copies of @a __c are inserted. If the length of result
1364 * exceeds max_size(), length_error is thrown. The value of
1365 * the string doesn't change if an error is thrown.
1366 */
1367 __versa_string&
1368 replace(iterator __i1, iterator __i2, size_type __n, _CharT __c)
1369 {
1370 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1371 && __i2 <= _M_iend());
1372 return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __c);
1373 }
1374
1375 /**
1376 * @brief Replace range of characters with range.
1377 * @param __i1 Iterator referencing start of range to replace.
1378 * @param __i2 Iterator referencing end of range to replace.
1379 * @param __k1 Iterator referencing start of range to insert.
1380 * @param __k2 Iterator referencing end of range to insert.
1381 * @return Reference to this string.
1382 * @throw std::length_error If new length exceeds @c max_size().
1383 *
1384 * Removes the characters in the range [i1,i2). In place,
1385 * characters in the range [k1,k2) are inserted. If the length
1386 * of result exceeds max_size(), length_error is thrown. The
1387 * value of the string doesn't change if an error is thrown.
1388 */
1389 #if __cplusplus >= 201103L
1390 template<class _InputIterator,
1391 typename = std::_RequireInputIter<_InputIterator>>
1392 __versa_string&
1393 replace(iterator __i1, iterator __i2,
1394 _InputIterator __k1, _InputIterator __k2)
1395 {
1396 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1397 && __i2 <= _M_iend());
1398 __glibcxx_requires_valid_range(__k1, __k2);
1399 return this->_M_replace_dispatch(__i1, __i2, __k1, __k2,
1400 std::__false_type());
1401 }
1402 #else
1403 template<class _InputIterator>
1404 __versa_string&
1405 replace(iterator __i1, iterator __i2,
1406 _InputIterator __k1, _InputIterator __k2)
1407 {
1408 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1409 && __i2 <= _M_iend());
1410 __glibcxx_requires_valid_range(__k1, __k2);
1411 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1412 return this->_M_replace_dispatch(__i1, __i2, __k1, __k2, _Integral());
1413 }
1414 #endif
1415
1416 // Specializations for the common case of pointer and iterator:
1417 // useful to avoid the overhead of temporary buffering in _M_replace.
1418 __versa_string&
1419 replace(iterator __i1, iterator __i2, _CharT* __k1, _CharT* __k2)
1420 {
1421 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1422 && __i2 <= _M_iend());
1423 __glibcxx_requires_valid_range(__k1, __k2);
1424 return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1425 __k1, __k2 - __k1);
1426 }
1427
1428 __versa_string&
1429 replace(iterator __i1, iterator __i2,
1430 const _CharT* __k1, const _CharT* __k2)
1431 {
1432 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1433 && __i2 <= _M_iend());
1434 __glibcxx_requires_valid_range(__k1, __k2);
1435 return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1436 __k1, __k2 - __k1);
1437 }
1438
1439 __versa_string&
1440 replace(iterator __i1, iterator __i2, iterator __k1, iterator __k2)
1441 {
1442 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1443 && __i2 <= _M_iend());
1444 __glibcxx_requires_valid_range(__k1, __k2);
1445 return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1446 __k1.base(), __k2 - __k1);
1447 }
1448
1449 __versa_string&
1450 replace(iterator __i1, iterator __i2,
1451 const_iterator __k1, const_iterator __k2)
1452 {
1453 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
1454 && __i2 <= _M_iend());
1455 __glibcxx_requires_valid_range(__k1, __k2);
1456 return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
1457 __k1.base(), __k2 - __k1);
1458 }
1459
1460 #if __cplusplus >= 201103L
1461 /**
1462 * @brief Replace range of characters with initializer_list.
1463 * @param __i1 Iterator referencing start of range to replace.
1464 * @param __i2 Iterator referencing end of range to replace.
1465 * @param __l The initializer_list of characters to insert.
1466 * @return Reference to this string.
1467 * @throw std::length_error If new length exceeds @c max_size().
1468 *
1469 * Removes the characters in the range [i1,i2). In place,
1470 * characters in the range [k1,k2) are inserted. If the length
1471 * of result exceeds max_size(), length_error is thrown. The
1472 * value of the string doesn't change if an error is thrown.
1473 */
1474 __versa_string& replace(iterator __i1, iterator __i2,
1475 std::initializer_list<_CharT> __l)
1476 { return this->replace(__i1, __i2, __l.begin(), __l.end()); }
1477 #endif // C++11
1478
1479 private:
1480 template<class _Integer>
1481 __versa_string&
1482 _M_replace_dispatch(iterator __i1, iterator __i2, _Integer __n,
1483 _Integer __val, std::__true_type)
1484 { return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __val); }
1485
1486 template<class _InputIterator>
1487 __versa_string&
1488 _M_replace_dispatch(iterator __i1, iterator __i2, _InputIterator __k1,
1489 _InputIterator __k2, std::__false_type);
1490
1491 __versa_string&
1492 _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2,
1493 _CharT __c);
1494
1495 __versa_string&
1496 _M_replace(size_type __pos, size_type __len1, const _CharT* __s,
1497 const size_type __len2);
1498
1499 __versa_string&
1500 _M_append(const _CharT* __s, size_type __n);
1501
1502 public:
1503
1504 /**
1505 * @brief Copy substring into C string.
1506 * @param __s C string to copy value into.
1507 * @param __n Number of characters to copy.
1508 * @param __pos Index of first character to copy.
1509 * @return Number of characters actually copied
1510 * @throw std::out_of_range If pos > size().
1511 *
1512 * Copies up to @a __n characters starting at @a __pos into the
1513 * C string @a s. If @a __pos is greater than size(),
1514 * out_of_range is thrown.
1515 */
1516 size_type
1517 copy(_CharT* __s, size_type __n, size_type __pos = 0) const;
1518
1519 /**
1520 * @brief Swap contents with another string.
1521 * @param __s String to swap with.
1522 *
1523 * Exchanges the contents of this string with that of @a __s in
1524 * constant time.
1525 */
1526 void
1527 swap(__versa_string& __s)
1528 { this->_M_swap(__s); }
1529
1530 // String operations:
1531 /**
1532 * @brief Return const pointer to null-terminated contents.
1533 *
1534 * This is a handle to internal data. Do not modify or dire things may
1535 * happen.
1536 */
1537 const _CharT*
1538 c_str() const _GLIBCXX_NOEXCEPT
1539 { return this->_M_data(); }
1540
1541 /**
1542 * @brief Return const pointer to contents.
1543 *
1544 * This is a handle to internal data. Do not modify or dire things may
1545 * happen.
1546 */
1547 const _CharT*
1548 data() const _GLIBCXX_NOEXCEPT
1549 { return this->_M_data(); }
1550
1551 /**
1552 * @brief Return copy of allocator used to construct this string.
1553 */
1554 allocator_type
1555 get_allocator() const _GLIBCXX_NOEXCEPT
1556 { return allocator_type(this->_M_get_allocator()); }
1557
1558 /**
1559 * @brief Find position of a C substring.
1560 * @param __s C string to locate.
1561 * @param __pos Index of character to search from.
1562 * @param __n Number of characters from @a __s to search for.
1563 * @return Index of start of first occurrence.
1564 *
1565 * Starting from @a __pos, searches forward for the first @a
1566 * __n characters in @a __s within this string. If found,
1567 * returns the index where it begins. If not found, returns
1568 * npos.
1569 */
1570 size_type
1571 find(const _CharT* __s, size_type __pos, size_type __n) const;
1572
1573 /**
1574 * @brief Find position of a string.
1575 * @param __str String to locate.
1576 * @param __pos Index of character to search from (default 0).
1577 * @return Index of start of first occurrence.
1578 *
1579 * Starting from @a __pos, searches forward for value of @a
1580 * __str within this string. If found, returns the index where
1581 * it begins. If not found, returns npos.
1582 */
1583 size_type
1584 find(const __versa_string& __str, size_type __pos = 0) const
1585 _GLIBCXX_NOEXCEPT
1586 { return this->find(__str.data(), __pos, __str.size()); }
1587
1588 /**
1589 * @brief Find position of a C string.
1590 * @param __s C string to locate.
1591 * @param __pos Index of character to search from (default 0).
1592 * @return Index of start of first occurrence.
1593 *
1594 * Starting from @a __pos, searches forward for the value of @a
1595 * __s within this string. If found, returns the index where
1596 * it begins. If not found, returns npos.
1597 */
1598 size_type
1599 find(const _CharT* __s, size_type __pos = 0) const
1600 {
1601 __glibcxx_requires_string(__s);
1602 return this->find(__s, __pos, traits_type::length(__s));
1603 }
1604
1605 /**
1606 * @brief Find position of a character.
1607 * @param __c Character to locate.
1608 * @param __pos Index of character to search from (default 0).
1609 * @return Index of first occurrence.
1610 *
1611 * Starting from @a __pos, searches forward for @a __c within
1612 * this string. If found, returns the index where it was
1613 * found. If not found, returns npos.
1614 */
1615 size_type
1616 find(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT;
1617
1618 /**
1619 * @brief Find last position of a string.
1620 * @param __str String to locate.
1621 * @param __pos Index of character to search back from (default end).
1622 * @return Index of start of last occurrence.
1623 *
1624 * Starting from @a __pos, searches backward for value of @a
1625 * __str within this string. If found, returns the index where
1626 * it begins. If not found, returns npos.
1627 */
1628 size_type
1629 rfind(const __versa_string& __str, size_type __pos = npos) const
1630 _GLIBCXX_NOEXCEPT
1631 { return this->rfind(__str.data(), __pos, __str.size()); }
1632
1633 /**
1634 * @brief Find last position of a C substring.
1635 * @param __s C string to locate.
1636 * @param __pos Index of character to search back from.
1637 * @param __n Number of characters from s to search for.
1638 * @return Index of start of last occurrence.
1639 *
1640 * Starting from @a __pos, searches backward for the first @a
1641 * __n characters in @a __s within this string. If found,
1642 * returns the index where it begins. If not found, returns
1643 * npos.
1644 */
1645 size_type
1646 rfind(const _CharT* __s, size_type __pos, size_type __n) const;
1647
1648 /**
1649 * @brief Find last position of a C string.
1650 * @param __s C string to locate.
1651 * @param __pos Index of character to start search at (default end).
1652 * @return Index of start of last occurrence.
1653 *
1654 * Starting from @a __pos, searches backward for the value of
1655 * @a __s within this string. If found, returns the index
1656 * where it begins. If not found, returns npos.
1657 */
1658 size_type
1659 rfind(const _CharT* __s, size_type __pos = npos) const
1660 {
1661 __glibcxx_requires_string(__s);
1662 return this->rfind(__s, __pos, traits_type::length(__s));
1663 }
1664
1665 /**
1666 * @brief Find last position of a character.
1667 * @param __c Character to locate.
1668 * @param __pos Index of character to search back from (default end).
1669 * @return Index of last occurrence.
1670 *
1671 * Starting from @a __pos, searches backward for @a __c within
1672 * this string. If found, returns the index where it was
1673 * found. If not found, returns npos.
1674 */
1675 size_type
1676 rfind(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPT;
1677
1678 /**
1679 * @brief Find position of a character of string.
1680 * @param __str String containing characters to locate.
1681 * @param __pos Index of character to search from (default 0).
1682 * @return Index of first occurrence.
1683 *
1684 * Starting from @a __pos, searches forward for one of the characters of
1685 * @a __str within this string. If found, returns the index where it was
1686 * found. If not found, returns npos.
1687 */
1688 size_type
1689 find_first_of(const __versa_string& __str, size_type __pos = 0) const
1690 _GLIBCXX_NOEXCEPT
1691 { return this->find_first_of(__str.data(), __pos, __str.size()); }
1692
1693 /**
1694 * @brief Find position of a character of C substring.
1695 * @param __s String containing characters to locate.
1696 * @param __pos Index of character to search from.
1697 * @param __n Number of characters from s to search for.
1698 * @return Index of first occurrence.
1699 *
1700 * Starting from @a __pos, searches forward for one of the
1701 * first @a __n characters of @a __s within this string. If
1702 * found, returns the index where it was found. If not found,
1703 * returns npos.
1704 */
1705 size_type
1706 find_first_of(const _CharT* __s, size_type __pos, size_type __n) const;
1707
1708 /**
1709 * @brief Find position of a character of C string.
1710 * @param __s String containing characters 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 one of the
1715 * characters of @a __s within this string. If found, returns
1716 * the index where it was found. If not found, returns npos.
1717 */
1718 size_type
1719 find_first_of(const _CharT* __s, size_type __pos = 0) const
1720 {
1721 __glibcxx_requires_string(__s);
1722 return this->find_first_of(__s, __pos, traits_type::length(__s));
1723 }
1724
1725 /**
1726 * @brief Find position of a character.
1727 * @param __c Character to locate.
1728 * @param __pos Index of character to search from (default 0).
1729 * @return Index of first occurrence.
1730 *
1731 * Starting from @a __pos, searches forward for the character
1732 * @a __c within this string. If found, returns the index
1733 * where it was found. If not found, returns npos.
1734 *
1735 * Note: equivalent to find(c, pos).
1736 */
1737 size_type
1738 find_first_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
1739 { return this->find(__c, __pos); }
1740
1741 /**
1742 * @brief Find last position of a character of string.
1743 * @param __str String containing characters to locate.
1744 * @param __pos Index of character to search back from (default end).
1745 * @return Index of last occurrence.
1746 *
1747 * Starting from @a __pos, searches backward for one of the
1748 * characters of @a __str within this string. If found,
1749 * returns the index where it was found. If not found, returns
1750 * npos.
1751 */
1752 size_type
1753 find_last_of(const __versa_string& __str, size_type __pos = npos) const
1754 _GLIBCXX_NOEXCEPT
1755 { return this->find_last_of(__str.data(), __pos, __str.size()); }
1756
1757 /**
1758 * @brief Find last position of a character of C substring.
1759 * @param __s C string containing characters to locate.
1760 * @param __pos Index of character to search back from.
1761 * @param __n Number of characters from s to search for.
1762 * @return Index of last occurrence.
1763 *
1764 * Starting from @a __pos, searches backward for one of the
1765 * first @a __n characters of @a __s within this string. If
1766 * found, returns the index where it was found. If not found,
1767 * returns npos.
1768 */
1769 size_type
1770 find_last_of(const _CharT* __s, size_type __pos, size_type __n) const;
1771
1772 /**
1773 * @brief Find last position of a character of C string.
1774 * @param __s C string containing characters to locate.
1775 * @param __pos Index of character to search back from (default end).
1776 * @return Index of last occurrence.
1777 *
1778 * Starting from @a __pos, searches backward for one of the
1779 * characters of @a __s within this string. If found, returns
1780 * the index where it was found. If not found, returns npos.
1781 */
1782 size_type
1783 find_last_of(const _CharT* __s, size_type __pos = npos) const
1784 {
1785 __glibcxx_requires_string(__s);
1786 return this->find_last_of(__s, __pos, traits_type::length(__s));
1787 }
1788
1789 /**
1790 * @brief Find last position of a character.
1791 * @param __c Character to locate.
1792 * @param __pos Index of character to search back from (default end).
1793 * @return Index of last occurrence.
1794 *
1795 * Starting from @a __pos, searches backward for @a __c within
1796 * this string. If found, returns the index where it was
1797 * found. If not found, returns npos.
1798 *
1799 * Note: equivalent to rfind(c, pos).
1800 */
1801 size_type
1802 find_last_of(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPT
1803 { return this->rfind(__c, __pos); }
1804
1805 /**
1806 * @brief Find position of a character not in string.
1807 * @param __str String containing characters to avoid.
1808 * @param __pos Index of character to search from (default 0).
1809 * @return Index of first occurrence.
1810 *
1811 * Starting from @a __pos, searches forward for a character not
1812 * contained in @a __str within this string. If found, returns
1813 * the index where it was found. If not found, returns npos.
1814 */
1815 size_type
1816 find_first_not_of(const __versa_string& __str, size_type __pos = 0) const
1817 _GLIBCXX_NOEXCEPT
1818 { return this->find_first_not_of(__str.data(), __pos, __str.size()); }
1819
1820 /**
1821 * @brief Find position of a character not in C substring.
1822 * @param __s C string containing characters to avoid.
1823 * @param __pos Index of character to search from.
1824 * @param __n Number of characters from s to consider.
1825 * @return Index of first occurrence.
1826 *
1827 * Starting from @a __pos, searches forward for a character not
1828 * contained in the first @a __n characters of @a __s within
1829 * this string. If found, returns the index where it was
1830 * found. If not found, returns npos.
1831 */
1832 size_type
1833 find_first_not_of(const _CharT* __s, size_type __pos,
1834 size_type __n) const;
1835
1836 /**
1837 * @brief Find position of a character not in C string.
1838 * @param __s C string containing characters to avoid.
1839 * @param __pos Index of character to search from (default 0).
1840 * @return Index of first occurrence.
1841 *
1842 * Starting from @a __pos, searches forward for a character not
1843 * contained in @a __s within this string. If found, returns
1844 * the index where it was found. If not found, returns npos.
1845 */
1846 size_type
1847 find_first_not_of(const _CharT* __s, size_type __pos = 0) const
1848 {
1849 __glibcxx_requires_string(__s);
1850 return this->find_first_not_of(__s, __pos, traits_type::length(__s));
1851 }
1852
1853 /**
1854 * @brief Find position of a different character.
1855 * @param __c Character to avoid.
1856 * @param __pos Index of character to search from (default 0).
1857 * @return Index of first occurrence.
1858 *
1859 * Starting from @a __pos, searches forward for a character
1860 * other than @a __c within this string. If found, returns the
1861 * index where it was found. If not found, returns npos.
1862 */
1863 size_type
1864 find_first_not_of(_CharT __c, size_type __pos = 0) const
1865 _GLIBCXX_NOEXCEPT;
1866
1867 /**
1868 * @brief Find last position of a character not in string.
1869 * @param __str String containing characters to avoid.
1870 * @param __pos Index of character to search back from (default end).
1871 * @return Index of last occurrence.
1872 *
1873 * Starting from @a __pos, searches backward for a character
1874 * not contained in @a __str within this string. If found,
1875 * returns the index where it was found. If not found, returns
1876 * npos.
1877 */
1878 size_type
1879 find_last_not_of(const __versa_string& __str,
1880 size_type __pos = npos) const _GLIBCXX_NOEXCEPT
1881 { return this->find_last_not_of(__str.data(), __pos, __str.size()); }
1882
1883 /**
1884 * @brief Find last position of a character not in C substring.
1885 * @param __s C string containing characters to avoid.
1886 * @param __pos Index of character to search back from.
1887 * @param __n Number of characters from s to consider.
1888 * @return Index of last occurrence.
1889 *
1890 * Starting from @a __pos, searches backward for a character
1891 * not contained in the first @a __n characters of @a __s
1892 * within this string. If found, returns the index where it
1893 * was found. If not found, returns npos.
1894 */
1895 size_type
1896 find_last_not_of(const _CharT* __s, size_type __pos,
1897 size_type __n) const;
1898 /**
1899 * @brief Find last position of a character not in C string.
1900 * @param __s C string containing characters to avoid.
1901 * @param __pos Index of character to search back from (default end).
1902 * @return Index of last occurrence.
1903 *
1904 * Starting from @a __pos, searches backward for a character
1905 * not contained in @a __s within this string. If found,
1906 * returns the index where it was found. If not found, returns
1907 * npos.
1908 */
1909 size_type
1910 find_last_not_of(const _CharT* __s, size_type __pos = npos) const
1911 {
1912 __glibcxx_requires_string(__s);
1913 return this->find_last_not_of(__s, __pos, traits_type::length(__s));
1914 }
1915
1916 /**
1917 * @brief Find last position of a different character.
1918 * @param __c Character to avoid.
1919 * @param __pos Index of character to search back from (default end).
1920 * @return Index of last occurrence.
1921 *
1922 * Starting from @a __pos, searches backward for a character
1923 * other than @a __c within this string. If found, returns the
1924 * index where it was found. If not found, returns npos.
1925 */
1926 size_type
1927 find_last_not_of(_CharT __c, size_type __pos = npos) const
1928 _GLIBCXX_NOEXCEPT;
1929
1930 /**
1931 * @brief Get a substring.
1932 * @param __pos Index of first character (default 0).
1933 * @param __n Number of characters in substring (default remainder).
1934 * @return The new string.
1935 * @throw std::out_of_range If pos > size().
1936 *
1937 * Construct and return a new string using the @a __n
1938 * characters starting at @a __pos. If the string is too
1939 * short, use the remainder of the characters. If @a __pos is
1940 * beyond the end of the string, out_of_range is thrown.
1941 */
1942 __versa_string
1943 substr(size_type __pos = 0, size_type __n = npos) const
1944 {
1945 return __versa_string(*this, _M_check(__pos, "__versa_string::substr"),
1946 __n);
1947 }
1948
1949 /**
1950 * @brief Compare to a string.
1951 * @param __str String to compare against.
1952 * @return Integer < 0, 0, or > 0.
1953 *
1954 * Returns an integer < 0 if this string is ordered before @a
1955 * __str, 0 if their values are equivalent, or > 0 if this
1956 * string is ordered after @a __str. Determines the effective
1957 * length rlen of the strings to compare as the smallest of
1958 * size() and str.size(). The function then compares the two
1959 * strings by calling traits::compare(data(), str.data(),rlen).
1960 * If the result of the comparison is nonzero returns it,
1961 * otherwise the shorter one is ordered first.
1962 */
1963 int
1964 compare(const __versa_string& __str) const
1965 {
1966 if (this->_M_compare(__str))
1967 return 0;
1968
1969 const size_type __size = this->size();
1970 const size_type __osize = __str.size();
1971 const size_type __len = std::min(__size, __osize);
1972
1973 int __r = traits_type::compare(this->_M_data(), __str.data(), __len);
1974 if (!__r)
1975 __r = this->_S_compare(__size, __osize);
1976 return __r;
1977 }
1978
1979 /**
1980 * @brief Compare substring to a string.
1981 * @param __pos Index of first character of substring.
1982 * @param __n Number of characters in substring.
1983 * @param __str String to compare against.
1984 * @return Integer < 0, 0, or > 0.
1985 *
1986 * Form the substring of this string from the @a __n characters
1987 * starting at @a __pos. Returns an integer < 0 if the
1988 * substring is ordered before @a __str, 0 if their values are
1989 * equivalent, or > 0 if the substring is ordered after @a
1990 * __str. Determines the effective length rlen of the strings
1991 * to compare as the smallest of the length of the substring
1992 * and @a __str.size(). The function then compares the two
1993 * strings by calling
1994 * traits::compare(substring.data(),str.data(),rlen). If the
1995 * result of the comparison is nonzero returns it, otherwise
1996 * the shorter one is ordered first.
1997 */
1998 int
1999 compare(size_type __pos, size_type __n,
2000 const __versa_string& __str) const;
2001
2002 /**
2003 * @brief Compare substring to a substring.
2004 * @param __pos1 Index of first character of substring.
2005 * @param __n1 Number of characters in substring.
2006 * @param __str String to compare against.
2007 * @param __pos2 Index of first character of substring of str.
2008 * @param __n2 Number of characters in substring of str.
2009 * @return Integer < 0, 0, or > 0.
2010 *
2011 * Form the substring of this string from the @a __n1
2012 * characters starting at @a __pos1. Form the substring of @a
2013 * __str from the @a __n2 characters starting at @a __pos2.
2014 * Returns an integer < 0 if this substring is ordered before
2015 * the substring of @a __str, 0 if their values are equivalent,
2016 * or > 0 if this substring is ordered after the substring of
2017 * @a __str. Determines the effective length rlen of the
2018 * strings to compare as the smallest of the lengths of the
2019 * substrings. The function then compares the two strings by
2020 * calling
2021 * traits::compare(substring.data(),str.substr(pos2,n2).data(),rlen).
2022 * If the result of the comparison is nonzero returns it,
2023 * otherwise the shorter one is ordered first.
2024 */
2025 int
2026 compare(size_type __pos1, size_type __n1, const __versa_string& __str,
2027 size_type __pos2, size_type __n2) const;
2028
2029 /**
2030 * @brief Compare to a C string.
2031 * @param __s C string to compare against.
2032 * @return Integer < 0, 0, or > 0.
2033 *
2034 * Returns an integer < 0 if this string is ordered before @a
2035 * __s, 0 if their values are equivalent, or > 0 if this string
2036 * is ordered after @a __s. Determines the effective length
2037 * rlen of the strings to compare as the smallest of size() and
2038 * the length of a string constructed from @a __s. The
2039 * function then compares the two strings by calling
2040 * traits::compare(data(),s,rlen). If the result of the
2041 * comparison is nonzero returns it, otherwise the shorter one
2042 * is ordered first.
2043 */
2044 int
2045 compare(const _CharT* __s) const;
2046
2047 // _GLIBCXX_RESOLVE_LIB_DEFECTS
2048 // 5 String::compare specification questionable
2049 /**
2050 * @brief Compare substring to a C string.
2051 * @param __pos Index of first character of substring.
2052 * @param __n1 Number of characters in substring.
2053 * @param __s C string to compare against.
2054 * @return Integer < 0, 0, or > 0.
2055 *
2056 * Form the substring of this string from the @a __n1
2057 * characters starting at @a __pos. Returns an integer < 0 if
2058 * the substring is ordered before @a __s, 0 if their values
2059 * are equivalent, or > 0 if the substring is ordered after @a
2060 * __s. Determines the effective length rlen of the strings to
2061 * compare as the smallest of the length of the substring and
2062 * the length of a string constructed from @a __s. The
2063 * function then compares the two string by calling
2064 * traits::compare(substring.data(),s,rlen). If the result of
2065 * the comparison is nonzero returns it, otherwise the shorter
2066 * one is ordered first.
2067 */
2068 int
2069 compare(size_type __pos, size_type __n1, const _CharT* __s) const;
2070
2071 /**
2072 * @brief Compare substring against a character array.
2073 * @param __pos Index of first character of substring.
2074 * @param __n1 Number of characters in substring.
2075 * @param __s character array to compare against.
2076 * @param __n2 Number of characters of s.
2077 * @return Integer < 0, 0, or > 0.
2078 *
2079 * Form the substring of this string from the @a __n1
2080 * characters starting at @a __pos. Form a string from the
2081 * first @a __n2 characters of @a __s. Returns an integer < 0
2082 * if this substring is ordered before the string from @a __s,
2083 * 0 if their values are equivalent, or > 0 if this substring
2084 * is ordered after the string from @a __s. Determines the
2085 * effective length rlen of the strings to compare as the
2086 * smallest of the length of the substring and @a __n2. The
2087 * function then compares the two strings by calling
2088 * traits::compare(substring.data(),__s,rlen). If the result of
2089 * the comparison is nonzero returns it, otherwise the shorter
2090 * one is ordered first.
2091 *
2092 * NB: __s must have at least n2 characters, <em>\\0</em> has no special
2093 * meaning.
2094 */
2095 int
2096 compare(size_type __pos, size_type __n1, const _CharT* __s,
2097 size_type __n2) const;
2098 };
2099
2100 // operator+
2101 /**
2102 * @brief Concatenate two strings.
2103 * @param __lhs First string.
2104 * @param __rhs Last string.
2105 * @return New string with value of @a __lhs followed by @a __rhs.
2106 */
2107 template<typename _CharT, typename _Traits, typename _Alloc,
2108 template <typename, typename, typename> class _Base>
2109 __versa_string<_CharT, _Traits, _Alloc, _Base>
2110 operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2111 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs);
2112
2113 /**
2114 * @brief Concatenate C string and string.
2115 * @param __lhs First string.
2116 * @param __rhs Last string.
2117 * @return New string with value of @a __lhs followed by @a __rhs.
2118 */
2119 template<typename _CharT, typename _Traits, typename _Alloc,
2120 template <typename, typename, typename> class _Base>
2121 __versa_string<_CharT, _Traits, _Alloc, _Base>
2122 operator+(const _CharT* __lhs,
2123 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs);
2124
2125 /**
2126 * @brief Concatenate character and string.
2127 * @param __lhs First string.
2128 * @param __rhs Last string.
2129 * @return New string with @a __lhs followed by @a __rhs.
2130 */
2131 template<typename _CharT, typename _Traits, typename _Alloc,
2132 template <typename, typename, typename> class _Base>
2133 __versa_string<_CharT, _Traits, _Alloc, _Base>
2134 operator+(_CharT __lhs,
2135 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs);
2136
2137 /**
2138 * @brief Concatenate string and C string.
2139 * @param __lhs First string.
2140 * @param __rhs Last string.
2141 * @return New string with @a __lhs followed by @a __rhs.
2142 */
2143 template<typename _CharT, typename _Traits, typename _Alloc,
2144 template <typename, typename, typename> class _Base>
2145 __versa_string<_CharT, _Traits, _Alloc, _Base>
2146 operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2147 const _CharT* __rhs);
2148
2149 /**
2150 * @brief Concatenate string and character.
2151 * @param __lhs First string.
2152 * @param __rhs Last string.
2153 * @return New string with @a __lhs followed by @a __rhs.
2154 */
2155 template<typename _CharT, typename _Traits, typename _Alloc,
2156 template <typename, typename, typename> class _Base>
2157 __versa_string<_CharT, _Traits, _Alloc, _Base>
2158 operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2159 _CharT __rhs);
2160
2161 #if __cplusplus >= 201103L
2162 template<typename _CharT, typename _Traits, typename _Alloc,
2163 template <typename, typename, typename> class _Base>
2164 inline __versa_string<_CharT, _Traits, _Alloc, _Base>
2165 operator+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs,
2166 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2167 { return std::move(__lhs.append(__rhs)); }
2168
2169 template<typename _CharT, typename _Traits, typename _Alloc,
2170 template <typename, typename, typename> class _Base>
2171 inline __versa_string<_CharT, _Traits, _Alloc, _Base>
2172 operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2173 __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs)
2174 { return std::move(__rhs.insert(0, __lhs)); }
2175
2176 template<typename _CharT, typename _Traits, typename _Alloc,
2177 template <typename, typename, typename> class _Base>
2178 inline __versa_string<_CharT, _Traits, _Alloc, _Base>
2179 operator+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs,
2180 __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs)
2181 {
2182 const auto __size = __lhs.size() + __rhs.size();
2183 const bool __cond = (__size > __lhs.capacity()
2184 && __size <= __rhs.capacity());
2185 return __cond ? std::move(__rhs.insert(0, __lhs))
2186 : std::move(__lhs.append(__rhs));
2187 }
2188
2189 template<typename _CharT, typename _Traits, typename _Alloc,
2190 template <typename, typename, typename> class _Base>
2191 inline __versa_string<_CharT, _Traits, _Alloc, _Base>
2192 operator+(const _CharT* __lhs,
2193 __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs)
2194 { return std::move(__rhs.insert(0, __lhs)); }
2195
2196 template<typename _CharT, typename _Traits, typename _Alloc,
2197 template <typename, typename, typename> class _Base>
2198 inline __versa_string<_CharT, _Traits, _Alloc, _Base>
2199 operator+(_CharT __lhs,
2200 __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs)
2201 { return std::move(__rhs.insert(0, 1, __lhs)); }
2202
2203 template<typename _CharT, typename _Traits, typename _Alloc,
2204 template <typename, typename, typename> class _Base>
2205 inline __versa_string<_CharT, _Traits, _Alloc, _Base>
2206 operator+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs,
2207 const _CharT* __rhs)
2208 { return std::move(__lhs.append(__rhs)); }
2209
2210 template<typename _CharT, typename _Traits, typename _Alloc,
2211 template <typename, typename, typename> class _Base>
2212 inline __versa_string<_CharT, _Traits, _Alloc, _Base>
2213 operator+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs,
2214 _CharT __rhs)
2215 { return std::move(__lhs.append(1, __rhs)); }
2216 #endif
2217
2218 // operator ==
2219 /**
2220 * @brief Test equivalence of two strings.
2221 * @param __lhs First string.
2222 * @param __rhs Second string.
2223 * @return True if @a __lhs.compare(@a __rhs) == 0. False otherwise.
2224 */
2225 template<typename _CharT, typename _Traits, typename _Alloc,
2226 template <typename, typename, typename> class _Base>
2227 inline bool
2228 operator==(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2229 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2230 { return __lhs.compare(__rhs) == 0; }
2231
2232 template<typename _CharT,
2233 template <typename, typename, typename> class _Base>
2234 inline typename __enable_if<std::__is_char<_CharT>::__value, bool>::__type
2235 operator==(const __versa_string<_CharT, std::char_traits<_CharT>,
2236 std::allocator<_CharT>, _Base>& __lhs,
2237 const __versa_string<_CharT, std::char_traits<_CharT>,
2238 std::allocator<_CharT>, _Base>& __rhs)
2239 { return (__lhs.size() == __rhs.size()
2240 && !std::char_traits<_CharT>::compare(__lhs.data(), __rhs.data(),
2241 __lhs.size())); }
2242
2243 /**
2244 * @brief Test equivalence of C string and string.
2245 * @param __lhs C string.
2246 * @param __rhs String.
2247 * @return True if @a __rhs.compare(@a __lhs) == 0. False otherwise.
2248 */
2249 template<typename _CharT, typename _Traits, typename _Alloc,
2250 template <typename, typename, typename> class _Base>
2251 inline bool
2252 operator==(const _CharT* __lhs,
2253 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2254 { return __rhs.compare(__lhs) == 0; }
2255
2256 /**
2257 * @brief Test equivalence of string and C string.
2258 * @param __lhs String.
2259 * @param __rhs C string.
2260 * @return True if @a __lhs.compare(@a __rhs) == 0. False otherwise.
2261 */
2262 template<typename _CharT, typename _Traits, typename _Alloc,
2263 template <typename, typename, typename> class _Base>
2264 inline bool
2265 operator==(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2266 const _CharT* __rhs)
2267 { return __lhs.compare(__rhs) == 0; }
2268
2269 // operator !=
2270 /**
2271 * @brief Test difference of two strings.
2272 * @param __lhs First string.
2273 * @param __rhs Second string.
2274 * @return True if @a __lhs.compare(@a __rhs) != 0. False otherwise.
2275 */
2276 template<typename _CharT, typename _Traits, typename _Alloc,
2277 template <typename, typename, typename> class _Base>
2278 inline bool
2279 operator!=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2280 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2281 { return !(__lhs == __rhs); }
2282
2283 /**
2284 * @brief Test difference of C string and string.
2285 * @param __lhs C string.
2286 * @param __rhs String.
2287 * @return True if @a __rhs.compare(@a __lhs) != 0. False otherwise.
2288 */
2289 template<typename _CharT, typename _Traits, typename _Alloc,
2290 template <typename, typename, typename> class _Base>
2291 inline bool
2292 operator!=(const _CharT* __lhs,
2293 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2294 { return !(__lhs == __rhs); }
2295
2296 /**
2297 * @brief Test difference of string and C string.
2298 * @param __lhs String.
2299 * @param __rhs C string.
2300 * @return True if @a __lhs.compare(@a __rhs) != 0. False otherwise.
2301 */
2302 template<typename _CharT, typename _Traits, typename _Alloc,
2303 template <typename, typename, typename> class _Base>
2304 inline bool
2305 operator!=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2306 const _CharT* __rhs)
2307 { return !(__lhs == __rhs); }
2308
2309 // operator <
2310 /**
2311 * @brief Test if string precedes string.
2312 * @param __lhs First string.
2313 * @param __rhs Second string.
2314 * @return True if @a __lhs precedes @a __rhs. False otherwise.
2315 */
2316 template<typename _CharT, typename _Traits, typename _Alloc,
2317 template <typename, typename, typename> class _Base>
2318 inline bool
2319 operator<(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2320 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2321 { return __lhs.compare(__rhs) < 0; }
2322
2323 /**
2324 * @brief Test if string precedes C string.
2325 * @param __lhs String.
2326 * @param __rhs C string.
2327 * @return True if @a __lhs precedes @a __rhs. False otherwise.
2328 */
2329 template<typename _CharT, typename _Traits, typename _Alloc,
2330 template <typename, typename, typename> class _Base>
2331 inline bool
2332 operator<(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2333 const _CharT* __rhs)
2334 { return __lhs.compare(__rhs) < 0; }
2335
2336 /**
2337 * @brief Test if C string precedes string.
2338 * @param __lhs C string.
2339 * @param __rhs String.
2340 * @return True if @a __lhs precedes @a __rhs. False otherwise.
2341 */
2342 template<typename _CharT, typename _Traits, typename _Alloc,
2343 template <typename, typename, typename> class _Base>
2344 inline bool
2345 operator<(const _CharT* __lhs,
2346 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2347 { return __rhs.compare(__lhs) > 0; }
2348
2349 // operator >
2350 /**
2351 * @brief Test if string follows string.
2352 * @param __lhs First string.
2353 * @param __rhs Second string.
2354 * @return True if @a __lhs follows @a __rhs. False otherwise.
2355 */
2356 template<typename _CharT, typename _Traits, typename _Alloc,
2357 template <typename, typename, typename> class _Base>
2358 inline bool
2359 operator>(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2360 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2361 { return __lhs.compare(__rhs) > 0; }
2362
2363 /**
2364 * @brief Test if string follows C string.
2365 * @param __lhs String.
2366 * @param __rhs C string.
2367 * @return True if @a __lhs follows @a __rhs. False otherwise.
2368 */
2369 template<typename _CharT, typename _Traits, typename _Alloc,
2370 template <typename, typename, typename> class _Base>
2371 inline bool
2372 operator>(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2373 const _CharT* __rhs)
2374 { return __lhs.compare(__rhs) > 0; }
2375
2376 /**
2377 * @brief Test if C string follows string.
2378 * @param __lhs C string.
2379 * @param __rhs String.
2380 * @return True if @a __lhs follows @a __rhs. False otherwise.
2381 */
2382 template<typename _CharT, typename _Traits, typename _Alloc,
2383 template <typename, typename, typename> class _Base>
2384 inline bool
2385 operator>(const _CharT* __lhs,
2386 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2387 { return __rhs.compare(__lhs) < 0; }
2388
2389 // operator <=
2390 /**
2391 * @brief Test if string doesn't follow string.
2392 * @param __lhs First string.
2393 * @param __rhs Second string.
2394 * @return True if @a __lhs doesn't follow @a __rhs. False otherwise.
2395 */
2396 template<typename _CharT, typename _Traits, typename _Alloc,
2397 template <typename, typename, typename> class _Base>
2398 inline bool
2399 operator<=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2400 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2401 { return __lhs.compare(__rhs) <= 0; }
2402
2403 /**
2404 * @brief Test if string doesn't follow C string.
2405 * @param __lhs String.
2406 * @param __rhs C string.
2407 * @return True if @a __lhs doesn't follow @a __rhs. False otherwise.
2408 */
2409 template<typename _CharT, typename _Traits, typename _Alloc,
2410 template <typename, typename, typename> class _Base>
2411 inline bool
2412 operator<=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2413 const _CharT* __rhs)
2414 { return __lhs.compare(__rhs) <= 0; }
2415
2416 /**
2417 * @brief Test if C string doesn't follow string.
2418 * @param __lhs C string.
2419 * @param __rhs String.
2420 * @return True if @a __lhs doesn't follow @a __rhs. False otherwise.
2421 */
2422 template<typename _CharT, typename _Traits, typename _Alloc,
2423 template <typename, typename, typename> class _Base>
2424 inline bool
2425 operator<=(const _CharT* __lhs,
2426 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2427 { return __rhs.compare(__lhs) >= 0; }
2428
2429 // operator >=
2430 /**
2431 * @brief Test if string doesn't precede string.
2432 * @param __lhs First string.
2433 * @param __rhs Second string.
2434 * @return True if @a __lhs doesn't precede @a __rhs. False otherwise.
2435 */
2436 template<typename _CharT, typename _Traits, typename _Alloc,
2437 template <typename, typename, typename> class _Base>
2438 inline bool
2439 operator>=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2440 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2441 { return __lhs.compare(__rhs) >= 0; }
2442
2443 /**
2444 * @brief Test if string doesn't precede C string.
2445 * @param __lhs String.
2446 * @param __rhs C string.
2447 * @return True if @a __lhs doesn't precede @a __rhs. False otherwise.
2448 */
2449 template<typename _CharT, typename _Traits, typename _Alloc,
2450 template <typename, typename, typename> class _Base>
2451 inline bool
2452 operator>=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2453 const _CharT* __rhs)
2454 { return __lhs.compare(__rhs) >= 0; }
2455
2456 /**
2457 * @brief Test if C string doesn't precede string.
2458 * @param __lhs C string.
2459 * @param __rhs String.
2460 * @return True if @a __lhs doesn't precede @a __rhs. False otherwise.
2461 */
2462 template<typename _CharT, typename _Traits, typename _Alloc,
2463 template <typename, typename, typename> class _Base>
2464 inline bool
2465 operator>=(const _CharT* __lhs,
2466 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2467 { return __rhs.compare(__lhs) <= 0; }
2468
2469 /**
2470 * @brief Swap contents of two strings.
2471 * @param __lhs First string.
2472 * @param __rhs Second string.
2473 *
2474 * Exchanges the contents of @a __lhs and @a __rhs in constant time.
2475 */
2476 template<typename _CharT, typename _Traits, typename _Alloc,
2477 template <typename, typename, typename> class _Base>
2478 inline void
2479 swap(__versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
2480 __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
2481 { __lhs.swap(__rhs); }
2482
2483 _GLIBCXX_END_NAMESPACE_VERSION
2484 } // namespace
2485
2486 namespace std _GLIBCXX_VISIBILITY(default)
2487 {
2488 _GLIBCXX_BEGIN_NAMESPACE_VERSION
2489
2490 /**
2491 * @brief Read stream into a string.
2492 * @param __is Input stream.
2493 * @param __str Buffer to store into.
2494 * @return Reference to the input stream.
2495 *
2496 * Stores characters from @a __is into @a __str until whitespace is
2497 * found, the end of the stream is encountered, or str.max_size()
2498 * is reached. If is.width() is non-zero, that is the limit on the
2499 * number of characters stored into @a __str. Any previous
2500 * contents of @a __str are erased.
2501 */
2502 template<typename _CharT, typename _Traits, typename _Alloc,
2503 template <typename, typename, typename> class _Base>
2504 basic_istream<_CharT, _Traits>&
2505 operator>>(basic_istream<_CharT, _Traits>& __is,
2506 __gnu_cxx::__versa_string<_CharT, _Traits,
2507 _Alloc, _Base>& __str);
2508
2509 /**
2510 * @brief Write string to a stream.
2511 * @param __os Output stream.
2512 * @param __str String to write out.
2513 * @return Reference to the output stream.
2514 *
2515 * Output characters of @a __str into os following the same rules as for
2516 * writing a C string.
2517 */
2518 template<typename _CharT, typename _Traits, typename _Alloc,
2519 template <typename, typename, typename> class _Base>
2520 inline basic_ostream<_CharT, _Traits>&
2521 operator<<(basic_ostream<_CharT, _Traits>& __os,
2522 const __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc,
2523 _Base>& __str)
2524 {
2525 // _GLIBCXX_RESOLVE_LIB_DEFECTS
2526 // 586. string inserter not a formatted function
2527 return __ostream_insert(__os, __str.data(), __str.size());
2528 }
2529
2530 /**
2531 * @brief Read a line from stream into a string.
2532 * @param __is Input stream.
2533 * @param __str Buffer to store into.
2534 * @param __delim Character marking end of line.
2535 * @return Reference to the input stream.
2536 *
2537 * Stores characters from @a __is into @a __str until @a __delim is
2538 * found, the end of the stream is encountered, or str.max_size()
2539 * is reached. If is.width() is non-zero, that is the limit on the
2540 * number of characters stored into @a __str. Any previous
2541 * contents of @a __str are erased. If @a delim was encountered,
2542 * it is extracted but not stored into @a __str.
2543 */
2544 template<typename _CharT, typename _Traits, typename _Alloc,
2545 template <typename, typename, typename> class _Base>
2546 basic_istream<_CharT, _Traits>&
2547 getline(basic_istream<_CharT, _Traits>& __is,
2548 __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc, _Base>& __str,
2549 _CharT __delim);
2550
2551 /**
2552 * @brief Read a line from stream into a string.
2553 * @param __is Input stream.
2554 * @param __str Buffer to store into.
2555 * @return Reference to the input stream.
2556 *
2557 * Stores characters from is into @a __str until &apos;\n&apos; is
2558 * found, the end of the stream is encountered, or str.max_size()
2559 * is reached. If is.width() is non-zero, that is the limit on the
2560 * number of characters stored into @a __str. Any previous
2561 * contents of @a __str are erased. If end of line was
2562 * encountered, it is extracted but not stored into @a __str.
2563 */
2564 template<typename _CharT, typename _Traits, typename _Alloc,
2565 template <typename, typename, typename> class _Base>
2566 inline basic_istream<_CharT, _Traits>&
2567 getline(basic_istream<_CharT, _Traits>& __is,
2568 __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc, _Base>& __str)
2569 { return getline(__is, __str, __is.widen('\n')); }
2570
2571 _GLIBCXX_END_NAMESPACE_VERSION
2572 } // namespace
2573
2574 #if ((__cplusplus >= 201103L) && defined(_GLIBCXX_USE_C99))
2575
2576 #include <ext/string_conversions.h>
2577
2578 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
2579 {
2580 _GLIBCXX_BEGIN_NAMESPACE_VERSION
2581
2582 // 21.4 Numeric Conversions [string.conversions].
2583 inline int
2584 stoi(const __vstring& __str, std::size_t* __idx = 0, int __base = 10)
2585 { return __gnu_cxx::__stoa<long, int>(&std::strtol, "stoi", __str.c_str(),
2586 __idx, __base); }
2587
2588 inline long
2589 stol(const __vstring& __str, std::size_t* __idx = 0, int __base = 10)
2590 { return __gnu_cxx::__stoa(&std::strtol, "stol", __str.c_str(),
2591 __idx, __base); }
2592
2593 inline unsigned long
2594 stoul(const __vstring& __str, std::size_t* __idx = 0, int __base = 10)
2595 { return __gnu_cxx::__stoa(&std::strtoul, "stoul", __str.c_str(),
2596 __idx, __base); }
2597
2598 inline long long
2599 stoll(const __vstring& __str, std::size_t* __idx = 0, int __base = 10)
2600 { return __gnu_cxx::__stoa(&std::strtoll, "stoll", __str.c_str(),
2601 __idx, __base); }
2602
2603 inline unsigned long long
2604 stoull(const __vstring& __str, std::size_t* __idx, int __base = 10)
2605 { return __gnu_cxx::__stoa(&std::strtoull, "stoull", __str.c_str(),
2606 __idx, __base); }
2607
2608 // NB: strtof vs strtod.
2609 inline float
2610 stof(const __vstring& __str, std::size_t* __idx = 0)
2611 { return __gnu_cxx::__stoa(&std::strtof, "stof", __str.c_str(), __idx); }
2612
2613 inline double
2614 stod(const __vstring& __str, std::size_t* __idx = 0)
2615 { return __gnu_cxx::__stoa(&std::strtod, "stod", __str.c_str(), __idx); }
2616
2617 inline long double
2618 stold(const __vstring& __str, std::size_t* __idx = 0)
2619 { return __gnu_cxx::__stoa(&std::strtold, "stold", __str.c_str(), __idx); }
2620
2621 // NB: (v)snprintf vs sprintf.
2622
2623 // DR 1261.
2624 inline __vstring
2625 to_string(int __val)
2626 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, 4 * sizeof(int),
2627 "%d", __val); }
2628
2629 inline __vstring
2630 to_string(unsigned __val)
2631 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
2632 4 * sizeof(unsigned),
2633 "%u", __val); }
2634
2635 inline __vstring
2636 to_string(long __val)
2637 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
2638 4 * sizeof(long),
2639 "%ld", __val); }
2640
2641 inline __vstring
2642 to_string(unsigned long __val)
2643 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
2644 4 * sizeof(unsigned long),
2645 "%lu", __val); }
2646
2647
2648 inline __vstring
2649 to_string(long long __val)
2650 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
2651 4 * sizeof(long long),
2652 "%lld", __val); }
2653
2654 inline __vstring
2655 to_string(unsigned long long __val)
2656 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf,
2657 4 * sizeof(unsigned long long),
2658 "%llu", __val); }
2659
2660 inline __vstring
2661 to_string(float __val)
2662 {
2663 const int __n = __numeric_traits<float>::__max_exponent10 + 20;
2664 return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, __n,
2665 "%f", __val);
2666 }
2667
2668 inline __vstring
2669 to_string(double __val)
2670 {
2671 const int __n = __numeric_traits<double>::__max_exponent10 + 20;
2672 return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, __n,
2673 "%f", __val);
2674 }
2675
2676 inline __vstring
2677 to_string(long double __val)
2678 {
2679 const int __n = __numeric_traits<long double>::__max_exponent10 + 20;
2680 return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, __n,
2681 "%Lf", __val);
2682 }
2683
2684 #ifdef _GLIBCXX_USE_WCHAR_T
2685 inline int
2686 stoi(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
2687 { return __gnu_cxx::__stoa<long, int>(&std::wcstol, "stoi", __str.c_str(),
2688 __idx, __base); }
2689
2690 inline long
2691 stol(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
2692 { return __gnu_cxx::__stoa(&std::wcstol, "stol", __str.c_str(),
2693 __idx, __base); }
2694
2695 inline unsigned long
2696 stoul(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
2697 { return __gnu_cxx::__stoa(&std::wcstoul, "stoul", __str.c_str(),
2698 __idx, __base); }
2699
2700 inline long long
2701 stoll(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
2702 { return __gnu_cxx::__stoa(&std::wcstoll, "stoll", __str.c_str(),
2703 __idx, __base); }
2704
2705 inline unsigned long long
2706 stoull(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10)
2707 { return __gnu_cxx::__stoa(&std::wcstoull, "stoull", __str.c_str(),
2708 __idx, __base); }
2709
2710 // NB: wcstof vs wcstod.
2711 inline float
2712 stof(const __wvstring& __str, std::size_t* __idx = 0)
2713 { return __gnu_cxx::__stoa(&std::wcstof, "stof", __str.c_str(), __idx); }
2714
2715 inline double
2716 stod(const __wvstring& __str, std::size_t* __idx = 0)
2717 { return __gnu_cxx::__stoa(&std::wcstod, "stod", __str.c_str(), __idx); }
2718
2719 inline long double
2720 stold(const __wvstring& __str, std::size_t* __idx = 0)
2721 { return __gnu_cxx::__stoa(&std::wcstold, "stold", __str.c_str(), __idx); }
2722
2723 #ifndef _GLIBCXX_HAVE_BROKEN_VSWPRINTF
2724 // DR 1261.
2725 inline __wvstring
2726 to_wstring(int __val)
2727 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
2728 4 * sizeof(int),
2729 L"%d", __val); }
2730
2731 inline __wvstring
2732 to_wstring(unsigned __val)
2733 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
2734 4 * sizeof(unsigned),
2735 L"%u", __val); }
2736
2737 inline __wvstring
2738 to_wstring(long __val)
2739 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
2740 4 * sizeof(long),
2741 L"%ld", __val); }
2742
2743 inline __wvstring
2744 to_wstring(unsigned long __val)
2745 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
2746 4 * sizeof(unsigned long),
2747 L"%lu", __val); }
2748
2749 inline __wvstring
2750 to_wstring(long long __val)
2751 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
2752 4 * sizeof(long long),
2753 L"%lld", __val); }
2754
2755 inline __wvstring
2756 to_wstring(unsigned long long __val)
2757 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf,
2758 4 * sizeof(unsigned long long),
2759 L"%llu", __val); }
2760
2761 inline __wvstring
2762 to_wstring(float __val)
2763 {
2764 const int __n = __numeric_traits<float>::__max_exponent10 + 20;
2765 return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, __n,
2766 L"%f", __val);
2767 }
2768
2769 inline __wvstring
2770 to_wstring(double __val)
2771 {
2772 const int __n = __numeric_traits<double>::__max_exponent10 + 20;
2773 return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, __n,
2774 L"%f", __val);
2775 }
2776
2777 inline __wvstring
2778 to_wstring(long double __val)
2779 {
2780 const int __n = __numeric_traits<long double>::__max_exponent10 + 20;
2781 return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, __n,
2782 L"%Lf", __val);
2783 }
2784 #endif
2785 #endif
2786
2787 _GLIBCXX_END_NAMESPACE_VERSION
2788 } // namespace
2789
2790 #endif
2791
2792 #if __cplusplus >= 201103L
2793
2794 #include <bits/functional_hash.h>
2795
2796 namespace std _GLIBCXX_VISIBILITY(default)
2797 {
2798 _GLIBCXX_BEGIN_NAMESPACE_VERSION
2799
2800 /// std::hash specialization for __vstring.
2801 template<>
2802 struct hash<__gnu_cxx::__vstring>
2803 : public __hash_base<size_t, __gnu_cxx::__vstring>
2804 {
2805 size_t
2806 operator()(const __gnu_cxx::__vstring& __s) const noexcept
2807 { return std::_Hash_impl::hash(__s.data(), __s.length()); }
2808 };
2809
2810 #ifdef _GLIBCXX_USE_WCHAR_T
2811 /// std::hash specialization for __wvstring.
2812 template<>
2813 struct hash<__gnu_cxx::__wvstring>
2814 : public __hash_base<size_t, __gnu_cxx::__wvstring>
2815 {
2816 size_t
2817 operator()(const __gnu_cxx::__wvstring& __s) const noexcept
2818 { return std::_Hash_impl::hash(__s.data(),
2819 __s.length() * sizeof(wchar_t)); }
2820 };
2821 #endif
2822
2823 #ifdef _GLIBCXX_USE_C99_STDINT_TR1
2824 /// std::hash specialization for __u16vstring.
2825 template<>
2826 struct hash<__gnu_cxx::__u16vstring>
2827 : public __hash_base<size_t, __gnu_cxx::__u16vstring>
2828 {
2829 size_t
2830 operator()(const __gnu_cxx::__u16vstring& __s) const noexcept
2831 { return std::_Hash_impl::hash(__s.data(),
2832 __s.length() * sizeof(char16_t)); }
2833 };
2834
2835 /// std::hash specialization for __u32vstring.
2836 template<>
2837 struct hash<__gnu_cxx::__u32vstring>
2838 : public __hash_base<size_t, __gnu_cxx::__u32vstring>
2839 {
2840 size_t
2841 operator()(const __gnu_cxx::__u32vstring& __s) const noexcept
2842 { return std::_Hash_impl::hash(__s.data(),
2843 __s.length() * sizeof(char32_t)); }
2844 };
2845 #endif
2846
2847 _GLIBCXX_END_NAMESPACE_VERSION
2848 } // namespace
2849
2850 #endif // C++11
2851
2852 #include "vstring.tcc"
2853
2854 #endif /* _VSTRING_H */