1// Debugging string implementation -*- C++ -*-
3// Copyright (C) 2003-2021 Free Software Foundation, Inc.
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)
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.
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.
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/>.
26 * This file is a GNU debug extension to the Standard C++ Library.
29#ifndef _GLIBCXX_DEBUG_STRING
30#define _GLIBCXX_DEBUG_STRING 1
32#pragma GCC system_header
35#include <debug/safe_sequence.h>
36#include <debug/safe_container.h>
37#include <debug/safe_iterator.h>
39#define _GLIBCXX_DEBUG_VERIFY_STR_COND_AT(_Cond,_File,_Line,_Func) \
41 __gnu_debug::_Error_formatter::_S_at(_File, _Line, _Func) \
42 ._M_message(#_Cond)._M_error()
44#if _GLIBCXX_USE_CXX11_ABI && __cplusplus >= 201103
45# define _GLIBCXX_INSERT_RETURNS_ITERATOR 1
46# define _GLIBCXX_INSERT_RETURNS_ITERATOR_ONLY(expr) expr
48# define _GLIBCXX_INSERT_RETURNS_ITERATOR 0
49# define _GLIBCXX_INSERT_RETURNS_ITERATOR_ONLY(expr)
54 /** Checks that __s is non-NULL or __n == 0, and then returns __s. */
55 template<typename _CharT, typename _Integer>
57 __check_string(const _CharT* __s,
58 _Integer __n __attribute__((__unused__)),
59 const char* __file __attribute__((__unused__)),
60 unsigned int __line __attribute__((__unused__)),
61 const char* __function __attribute__((__unused__)))
63#ifdef _GLIBCXX_DEBUG_PEDANTIC
64 _GLIBCXX_DEBUG_VERIFY_STR_COND_AT(__s != 0 || __n == 0,
65 __file, __line, __function);
70 /** Checks that __s is non-NULL and then returns __s. */
71 template<typename _CharT>
73 __check_string(const _CharT* __s,
74 const char* __file __attribute__((__unused__)),
75 unsigned int __line __attribute__((__unused__)),
76 const char* __function __attribute__((__unused__)))
78#ifdef _GLIBCXX_DEBUG_PEDANTIC
79 _GLIBCXX_DEBUG_VERIFY_STR_COND_AT(__s != 0,
80 __file, __line, __function);
85#define __glibcxx_check_string_n_constructor(_Str, _Size) \
86 __check_string(_Str, _Size, __FILE__, __LINE__, __PRETTY_FUNCTION__)
88#define __glibcxx_check_string_constructor(_Str) \
89 __check_string(_Str, __FILE__, __LINE__, __PRETTY_FUNCTION__)
91 /// Class std::basic_string with safety/checking/debug instrumentation.
92 template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
93 typename _Allocator = std::allocator<_CharT> >
95 : public __gnu_debug::_Safe_container<
96 basic_string<_CharT, _Traits, _Allocator>,
97 _Allocator, _Safe_sequence, bool(_GLIBCXX_USE_CXX11_ABI)>,
98 public std::basic_string<_CharT, _Traits, _Allocator>
100 typedef std::basic_string<_CharT, _Traits, _Allocator> _Base;
101 typedef __gnu_debug::_Safe_container<
102 basic_string, _Allocator, _Safe_sequence, bool(_GLIBCXX_USE_CXX11_ABI)>
105 template<typename _ItT, typename _SeqT, typename _CatT>
106 friend class ::__gnu_debug::_Safe_iterator;
108 // type used for positions in insert, erase etc.
109 typedef __gnu_debug::_Safe_iterator<
110 typename _Base::__const_iterator, basic_string> __const_iterator;
114 typedef _Traits traits_type;
115 typedef typename _Traits::char_type value_type;
116 typedef _Allocator allocator_type;
117 typedef typename _Base::size_type size_type;
118 typedef typename _Base::difference_type difference_type;
119 typedef typename _Base::reference reference;
120 typedef typename _Base::const_reference const_reference;
121 typedef typename _Base::pointer pointer;
122 typedef typename _Base::const_pointer const_pointer;
124 typedef __gnu_debug::_Safe_iterator<
125 typename _Base::iterator, basic_string> iterator;
126 typedef __gnu_debug::_Safe_iterator<
127 typename _Base::const_iterator, basic_string> const_iterator;
129 typedef std::reverse_iterator<iterator> reverse_iterator;
130 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
134 // 21.3.1 construct/copy/destroy:
137 basic_string(const _Allocator& __a) _GLIBCXX_NOEXCEPT
140#if __cplusplus < 201103L
141 basic_string() : _Base() { }
143 basic_string(const basic_string& __str)
148 basic_string() = default;
149 basic_string(const basic_string&) = default;
150 basic_string(basic_string&&) = default;
152 basic_string(std::initializer_list<_CharT> __l,
153 const _Allocator& __a = _Allocator())
157 basic_string(const basic_string& __s, const _Allocator& __a)
158 : _Base(__s, __a) { }
160 basic_string(basic_string&& __s, const _Allocator& __a)
162 std::is_nothrow_constructible<_Base, _Base, const _Allocator&>::value )
163 : _Safe(std::move(__s._M_safe()), __a),
164 _Base(std::move(__s._M_base()), __a)
167 ~basic_string() = default;
169 // Provides conversion from a normal-mode string to a debug-mode string
170 basic_string(_Base&& __base) noexcept
171 : _Base(std::move(__base)) { }
174 // Provides conversion from a normal-mode string to a debug-mode string
175 basic_string(const _Base& __base)
178 // _GLIBCXX_RESOLVE_LIB_DEFECTS
179 // 42. string ctors specify wrong default allocator
180 basic_string(const basic_string& __str, size_type __pos,
181 size_type __n = _Base::npos,
182 const _Allocator& __a = _Allocator())
183 : _Base(__str, __pos, __n, __a) { }
185 basic_string(const _CharT* __s, size_type __n,
186 const _Allocator& __a = _Allocator())
187 : _Base(__glibcxx_check_string_n_constructor(__s, __n), __n, __a) { }
189 basic_string(const _CharT* __s, const _Allocator& __a = _Allocator())
190 : _Base(__glibcxx_check_string_constructor(__s), __a)
193 basic_string(size_type __n, _CharT __c,
194 const _Allocator& __a = _Allocator())
195 : _Base(__n, __c, __a) { }
197 template<typename _InputIterator>
198 basic_string(_InputIterator __begin, _InputIterator __end,
199 const _Allocator& __a = _Allocator())
200 : _Base(__gnu_debug::__base(
201 __glibcxx_check_valid_constructor_range(__begin, __end)),
202 __gnu_debug::__base(__end), __a) { }
204#if __cplusplus < 201103L
206 operator=(const basic_string& __str)
208 this->_M_safe() = __str;
214 operator=(const basic_string&) = default;
217 operator=(basic_string&&) = default;
221 operator=(const _CharT* __s)
223 __glibcxx_check_string(__s);
225 this->_M_invalidate_all();
230 operator=(_CharT __c)
233 this->_M_invalidate_all();
237#if __cplusplus >= 201103L
239 operator=(std::initializer_list<_CharT> __l)
242 this->_M_invalidate_all();
249 begin() // _GLIBCXX_NOEXCEPT
250 { return iterator(_Base::begin(), this); }
253 begin() const _GLIBCXX_NOEXCEPT
254 { return const_iterator(_Base::begin(), this); }
257 end() // _GLIBCXX_NOEXCEPT
258 { return iterator(_Base::end(), this); }
261 end() const _GLIBCXX_NOEXCEPT
262 { return const_iterator(_Base::end(), this); }
265 rbegin() // _GLIBCXX_NOEXCEPT
266 { return reverse_iterator(end()); }
268 const_reverse_iterator
269 rbegin() const _GLIBCXX_NOEXCEPT
270 { return const_reverse_iterator(end()); }
273 rend() // _GLIBCXX_NOEXCEPT
274 { return reverse_iterator(begin()); }
276 const_reverse_iterator
277 rend() const _GLIBCXX_NOEXCEPT
278 { return const_reverse_iterator(begin()); }
280#if __cplusplus >= 201103L
282 cbegin() const noexcept
283 { return const_iterator(_Base::begin(), this); }
286 cend() const noexcept
287 { return const_iterator(_Base::end(), this); }
289 const_reverse_iterator
290 crbegin() const noexcept
291 { return const_reverse_iterator(end()); }
293 const_reverse_iterator
294 crend() const noexcept
295 { return const_reverse_iterator(begin()); }
301 using _Base::max_size;
304 resize(size_type __n, _CharT __c)
306 _Base::resize(__n, __c);
307 this->_M_invalidate_all();
311 resize(size_type __n)
312 { this->resize(__n, _CharT()); }
314#if __cplusplus >= 201103L
316 shrink_to_fit() noexcept
318 if (capacity() > size())
323 this->_M_invalidate_all();
331 using _Base::capacity;
332 using _Base::reserve;
335 clear() // _GLIBCXX_NOEXCEPT
338 this->_M_invalidate_all();
343 // 21.3.4 element access:
345 operator[](size_type __pos) const _GLIBCXX_NOEXCEPT
347 _GLIBCXX_DEBUG_VERIFY(__pos <= this->size(),
348 _M_message(__gnu_debug::__msg_subscript_oob)
349 ._M_sequence(*this, "this")
350 ._M_integer(__pos, "__pos")
351 ._M_integer(this->size(), "size"));
352 return _M_base()[__pos];
356 operator[](size_type __pos) // _GLIBCXX_NOEXCEPT
358#if __cplusplus < 201103L && defined(_GLIBCXX_DEBUG_PEDANTIC)
359 __glibcxx_check_subscript(__pos);
361 // as an extension v3 allows s[s.size()] when s is non-const.
362 _GLIBCXX_DEBUG_VERIFY(__pos <= this->size(),
363 _M_message(__gnu_debug::__msg_subscript_oob)
364 ._M_sequence(*this, "this")
365 ._M_integer(__pos, "__pos")
366 ._M_integer(this->size(), "size"));
368 return _M_base()[__pos];
373#if __cplusplus >= 201103L
380 operator+=(const basic_string& __str)
383 this->_M_invalidate_all();
388 operator+=(const _CharT* __s)
390 __glibcxx_check_string(__s);
392 this->_M_invalidate_all();
397 operator+=(_CharT __c)
400 this->_M_invalidate_all();
404#if __cplusplus >= 201103L
406 operator+=(std::initializer_list<_CharT> __l)
409 this->_M_invalidate_all();
415 append(const basic_string& __str)
417 _Base::append(__str);
418 this->_M_invalidate_all();
423 append(const basic_string& __str, size_type __pos, size_type __n)
425 _Base::append(__str, __pos, __n);
426 this->_M_invalidate_all();
431 append(const _CharT* __s, size_type __n)
433 __glibcxx_check_string_len(__s, __n);
434 _Base::append(__s, __n);
435 this->_M_invalidate_all();
440 append(const _CharT* __s)
442 __glibcxx_check_string(__s);
444 this->_M_invalidate_all();
449 append(size_type __n, _CharT __c)
451 _Base::append(__n, __c);
452 this->_M_invalidate_all();
456 template<typename _InputIterator>
458 append(_InputIterator __first, _InputIterator __last)
460 typename __gnu_debug::_Distance_traits<_InputIterator>::__type __dist;
461 __glibcxx_check_valid_range2(__first, __last, __dist);
463 if (__dist.second >= __dp_sign)
464 _Base::append(__gnu_debug::__unsafe(__first),
465 __gnu_debug::__unsafe(__last));
467 _Base::append(__first, __last);
469 this->_M_invalidate_all();
473 // _GLIBCXX_RESOLVE_LIB_DEFECTS
474 // 7. string clause minor problems
476 push_back(_CharT __c)
478 _Base::push_back(__c);
479 this->_M_invalidate_all();
483 assign(const basic_string& __x)
486 this->_M_invalidate_all();
490#if __cplusplus >= 201103L
492 assign(basic_string&& __x)
493 noexcept(noexcept(std::declval<_Base&>().assign(std::move(__x))))
495 _Base::assign(std::move(__x));
496 this->_M_invalidate_all();
502 assign(const basic_string& __str, size_type __pos, size_type __n)
504 _Base::assign(__str, __pos, __n);
505 this->_M_invalidate_all();
510 assign(const _CharT* __s, size_type __n)
512 __glibcxx_check_string_len(__s, __n);
513 _Base::assign(__s, __n);
514 this->_M_invalidate_all();
519 assign(const _CharT* __s)
521 __glibcxx_check_string(__s);
523 this->_M_invalidate_all();
528 assign(size_type __n, _CharT __c)
530 _Base::assign(__n, __c);
531 this->_M_invalidate_all();
535 template<typename _InputIterator>
537 assign(_InputIterator __first, _InputIterator __last)
539 typename __gnu_debug::_Distance_traits<_InputIterator>::__type __dist;
540 __glibcxx_check_valid_range2(__first, __last, __dist);
542 if (__dist.second >= __dp_sign)
543 _Base::assign(__gnu_debug::__unsafe(__first),
544 __gnu_debug::__unsafe(__last));
546 _Base::assign(__first, __last);
548 this->_M_invalidate_all();
552#if __cplusplus >= 201103L
554 assign(std::initializer_list<_CharT> __l)
557 this->_M_invalidate_all();
563 insert(size_type __pos1, const basic_string& __str)
565 _Base::insert(__pos1, __str);
566 this->_M_invalidate_all();
571 insert(size_type __pos1, const basic_string& __str,
572 size_type __pos2, size_type __n)
574 _Base::insert(__pos1, __str, __pos2, __n);
575 this->_M_invalidate_all();
580 insert(size_type __pos, const _CharT* __s, size_type __n)
582 __glibcxx_check_string(__s);
583 _Base::insert(__pos, __s, __n);
584 this->_M_invalidate_all();
589 insert(size_type __pos, const _CharT* __s)
591 __glibcxx_check_string(__s);
592 _Base::insert(__pos, __s);
593 this->_M_invalidate_all();
598 insert(size_type __pos, size_type __n, _CharT __c)
600 _Base::insert(__pos, __n, __c);
601 this->_M_invalidate_all();
606 insert(__const_iterator __p, _CharT __c)
608 __glibcxx_check_insert(__p);
609 typename _Base::iterator __res = _Base::insert(__p.base(), __c);
610 this->_M_invalidate_all();
611 return iterator(__res, this);
614#if __cplusplus >= 201103L
616 insert(const_iterator __p, size_type __n, _CharT __c)
618 __glibcxx_check_insert(__p);
619#if _GLIBCXX_USE_CXX11_ABI
620 typename _Base::iterator __res = _Base::insert(__p.base(), __n, __c);
622 const size_type __offset = __p.base() - _Base::cbegin();
623 _Base::insert(_Base::begin() + __offset, __n, __c);
624 typename _Base::iterator __res = _Base::begin() + __offset;
626 this->_M_invalidate_all();
627 return iterator(__res, this);
631 insert(iterator __p, size_type __n, _CharT __c)
633 __glibcxx_check_insert(__p);
634 _Base::insert(__p.base(), __n, __c);
635 this->_M_invalidate_all();
639 template<typename _InputIterator>
641 insert(__const_iterator __p,
642 _InputIterator __first, _InputIterator __last)
644 typename __gnu_debug::_Distance_traits<_InputIterator>::__type __dist;
645 __glibcxx_check_insert_range(__p, __first, __last, __dist);
647 typename _Base::iterator __res;
648#if ! _GLIBCXX_INSERT_RETURNS_ITERATOR
649 const size_type __offset = __p.base() - _Base::begin();
651 if (__dist.second >= __dp_sign)
653 _GLIBCXX_INSERT_RETURNS_ITERATOR_ONLY(__res =)
654 _Base::insert(__p.base(), __gnu_debug::__unsafe(__first),
655 __gnu_debug::__unsafe(__last));
659 _GLIBCXX_INSERT_RETURNS_ITERATOR_ONLY(__res =)
660 _Base::insert(__p.base(), __first, __last);
663#if ! _GLIBCXX_INSERT_RETURNS_ITERATOR
664 __res = _Base::begin() + __offset;
666 this->_M_invalidate_all();
667 return iterator(__res, this);
670#if __cplusplus >= 201103L
672 insert(const_iterator __p, std::initializer_list<_CharT> __l)
674 __glibcxx_check_insert(__p);
675#if _GLIBCXX_USE_CXX11_ABI
676 const auto __res = _Base::insert(__p.base(), __l);
678 const size_type __offset = __p.base() - _Base::cbegin();
679 _Base::insert(_Base::begin() + __offset, __l);
680 auto __res = _Base::begin() + __offset;
682 this->_M_invalidate_all();
683 return iterator(__res, this);
688 erase(size_type __pos = 0, size_type __n = _Base::npos)
690 _Base::erase(__pos, __n);
691 this->_M_invalidate_all();
696 erase(__const_iterator __position)
698 __glibcxx_check_erase(__position);
699 typename _Base::iterator __res = _Base::erase(__position.base());
700 this->_M_invalidate_all();
701 return iterator(__res, this);
705 erase(__const_iterator __first, __const_iterator __last)
707 // _GLIBCXX_RESOLVE_LIB_DEFECTS
708 // 151. can't currently clear() empty container
709 __glibcxx_check_erase_range(__first, __last);
710 typename _Base::iterator __res = _Base::erase(__first.base(),
712 this->_M_invalidate_all();
713 return iterator(__res, this);
716#if __cplusplus >= 201103L
718 pop_back() // noexcept
720 __glibcxx_check_nonempty();
722 this->_M_invalidate_all();
727 replace(size_type __pos1, size_type __n1, const basic_string& __str)
729 _Base::replace(__pos1, __n1, __str);
730 this->_M_invalidate_all();
735 replace(size_type __pos1, size_type __n1, const basic_string& __str,
736 size_type __pos2, size_type __n2)
738 _Base::replace(__pos1, __n1, __str, __pos2, __n2);
739 this->_M_invalidate_all();
744 replace(size_type __pos, size_type __n1, const _CharT* __s,
747 __glibcxx_check_string_len(__s, __n2);
748 _Base::replace(__pos, __n1, __s, __n2);
749 this->_M_invalidate_all();
754 replace(size_type __pos, size_type __n1, const _CharT* __s)
756 __glibcxx_check_string(__s);
757 _Base::replace(__pos, __n1, __s);
758 this->_M_invalidate_all();
763 replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
765 _Base::replace(__pos, __n1, __n2, __c);
766 this->_M_invalidate_all();
771 replace(__const_iterator __i1, __const_iterator __i2,
772 const basic_string& __str)
774 __glibcxx_check_erase_range(__i1, __i2);
775 _Base::replace(__i1.base(), __i2.base(), __str);
776 this->_M_invalidate_all();
781 replace(__const_iterator __i1, __const_iterator __i2,
782 const _CharT* __s, size_type __n)
784 __glibcxx_check_erase_range(__i1, __i2);
785 __glibcxx_check_string_len(__s, __n);
786 _Base::replace(__i1.base(), __i2.base(), __s, __n);
787 this->_M_invalidate_all();
792 replace(__const_iterator __i1, __const_iterator __i2,
795 __glibcxx_check_erase_range(__i1, __i2);
796 __glibcxx_check_string(__s);
797 _Base::replace(__i1.base(), __i2.base(), __s);
798 this->_M_invalidate_all();
803 replace(__const_iterator __i1, __const_iterator __i2,
804 size_type __n, _CharT __c)
806 __glibcxx_check_erase_range(__i1, __i2);
807 _Base::replace(__i1.base(), __i2.base(), __n, __c);
808 this->_M_invalidate_all();
812 template<typename _InputIterator>
814 replace(__const_iterator __i1, __const_iterator __i2,
815 _InputIterator __j1, _InputIterator __j2)
817 __glibcxx_check_erase_range(__i1, __i2);
819 typename __gnu_debug::_Distance_traits<_InputIterator>::__type __dist;
820 __glibcxx_check_valid_range2(__j1, __j2, __dist);
822 if (__dist.second >= __dp_sign)
823 _Base::replace(__i1.base(), __i2.base(),
824 __gnu_debug::__unsafe(__j1),
825 __gnu_debug::__unsafe(__j2));
827 _Base::replace(__i1.base(), __i2.base(), __j1, __j2);
829 this->_M_invalidate_all();
833#if __cplusplus >= 201103L
835 replace(__const_iterator __i1, __const_iterator __i2,
836 std::initializer_list<_CharT> __l)
838 __glibcxx_check_erase_range(__i1, __i2);
839 _Base::replace(__i1.base(), __i2.base(), __l);
840 this->_M_invalidate_all();
846 copy(_CharT* __s, size_type __n, size_type __pos = 0) const
848 __glibcxx_check_string_len(__s, __n);
849 return _Base::copy(__s, __n, __pos);
853 swap(basic_string& __x)
854 _GLIBCXX_NOEXCEPT_IF(std::__is_nothrow_swappable<_Base>::value)
860 // 21.3.6 string operations:
862 c_str() const _GLIBCXX_NOEXCEPT
864 const _CharT* __res = _Base::c_str();
865 this->_M_invalidate_all();
870 data() const _GLIBCXX_NOEXCEPT
872 const _CharT* __res = _Base::data();
873 this->_M_invalidate_all();
877 using _Base::get_allocator;
880 find(const basic_string& __str, size_type __pos = 0) const
882 { return _Base::find(__str, __pos); }
885 find(const _CharT* __s, size_type __pos, size_type __n) const
887 __glibcxx_check_string(__s);
888 return _Base::find(__s, __pos, __n);
892 find(const _CharT* __s, size_type __pos = 0) const
894 __glibcxx_check_string(__s);
895 return _Base::find(__s, __pos);
899 find(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
900 { return _Base::find(__c, __pos); }
903 rfind(const basic_string& __str, size_type __pos = _Base::npos) const
905 { return _Base::rfind(__str, __pos); }
908 rfind(const _CharT* __s, size_type __pos, size_type __n) const
910 __glibcxx_check_string_len(__s, __n);
911 return _Base::rfind(__s, __pos, __n);
915 rfind(const _CharT* __s, size_type __pos = _Base::npos) const
917 __glibcxx_check_string(__s);
918 return _Base::rfind(__s, __pos);
922 rfind(_CharT __c, size_type __pos = _Base::npos) const _GLIBCXX_NOEXCEPT
923 { return _Base::rfind(__c, __pos); }
926 find_first_of(const basic_string& __str, size_type __pos = 0) const
928 { return _Base::find_first_of(__str, __pos); }
931 find_first_of(const _CharT* __s, size_type __pos, size_type __n) const
933 __glibcxx_check_string(__s);
934 return _Base::find_first_of(__s, __pos, __n);
938 find_first_of(const _CharT* __s, size_type __pos = 0) const
940 __glibcxx_check_string(__s);
941 return _Base::find_first_of(__s, __pos);
945 find_first_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
946 { return _Base::find_first_of(__c, __pos); }
949 find_last_of(const basic_string& __str,
950 size_type __pos = _Base::npos) const _GLIBCXX_NOEXCEPT
951 { return _Base::find_last_of(__str, __pos); }
954 find_last_of(const _CharT* __s, size_type __pos, size_type __n) const
956 __glibcxx_check_string(__s);
957 return _Base::find_last_of(__s, __pos, __n);
961 find_last_of(const _CharT* __s, size_type __pos = _Base::npos) const
963 __glibcxx_check_string(__s);
964 return _Base::find_last_of(__s, __pos);
968 find_last_of(_CharT __c, size_type __pos = _Base::npos) const
970 { return _Base::find_last_of(__c, __pos); }
973 find_first_not_of(const basic_string& __str, size_type __pos = 0) const
975 { return _Base::find_first_not_of(__str, __pos); }
978 find_first_not_of(const _CharT* __s, size_type __pos, size_type __n) const
980 __glibcxx_check_string_len(__s, __n);
981 return _Base::find_first_not_of(__s, __pos, __n);
985 find_first_not_of(const _CharT* __s, size_type __pos = 0) const
987 __glibcxx_check_string(__s);
988 return _Base::find_first_not_of(__s, __pos);
992 find_first_not_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
993 { return _Base::find_first_not_of(__c, __pos); }
996 find_last_not_of(const basic_string& __str,
997 size_type __pos = _Base::npos) const
999 { return _Base::find_last_not_of(__str, __pos); }
1002 find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const
1004 __glibcxx_check_string(__s);
1005 return _Base::find_last_not_of(__s, __pos, __n);
1009 find_last_not_of(const _CharT* __s, size_type __pos = _Base::npos) const
1011 __glibcxx_check_string(__s);
1012 return _Base::find_last_not_of(__s, __pos);
1016 find_last_not_of(_CharT __c, size_type __pos = _Base::npos) const
1018 { return _Base::find_last_not_of(__c, __pos); }
1021 substr(size_type __pos = 0, size_type __n = _Base::npos) const
1022 { return basic_string(_Base::substr(__pos, __n)); }
1025 compare(const basic_string& __str) const
1026 { return _Base::compare(__str); }
1029 compare(size_type __pos1, size_type __n1,
1030 const basic_string& __str) const
1031 { return _Base::compare(__pos1, __n1, __str); }
1034 compare(size_type __pos1, size_type __n1, const basic_string& __str,
1035 size_type __pos2, size_type __n2) const
1036 { return _Base::compare(__pos1, __n1, __str, __pos2, __n2); }
1039 compare(const _CharT* __s) const
1041 __glibcxx_check_string(__s);
1042 return _Base::compare(__s);
1045 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1046 // 5. string::compare specification questionable
1048 compare(size_type __pos1, size_type __n1, const _CharT* __s) const
1050 __glibcxx_check_string(__s);
1051 return _Base::compare(__pos1, __n1, __s);
1054 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1055 // 5. string::compare specification questionable
1057 compare(size_type __pos1, size_type __n1,const _CharT* __s,
1058 size_type __n2) const
1060 __glibcxx_check_string_len(__s, __n2);
1061 return _Base::compare(__pos1, __n1, __s, __n2);
1065 _M_base() _GLIBCXX_NOEXCEPT { return *this; }
1068 _M_base() const _GLIBCXX_NOEXCEPT { return *this; }
1070 using _Safe::_M_invalidate_all;
1073 template<typename _CharT, typename _Traits, typename _Allocator>
1074 inline basic_string<_CharT,_Traits,_Allocator>
1075 operator+(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1076 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1077 { return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs; }
1079 template<typename _CharT, typename _Traits, typename _Allocator>
1080 inline basic_string<_CharT,_Traits,_Allocator>
1081 operator+(const _CharT* __lhs,
1082 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1084 __glibcxx_check_string(__lhs);
1085 return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs;
1088 template<typename _CharT, typename _Traits, typename _Allocator>
1089 inline basic_string<_CharT,_Traits,_Allocator>
1090 operator+(_CharT __lhs,
1091 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1092 { return basic_string<_CharT,_Traits,_Allocator>(1, __lhs) += __rhs; }
1094 template<typename _CharT, typename _Traits, typename _Allocator>
1095 inline basic_string<_CharT,_Traits,_Allocator>
1096 operator+(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1097 const _CharT* __rhs)
1099 __glibcxx_check_string(__rhs);
1100 return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs;
1103 template<typename _CharT, typename _Traits, typename _Allocator>
1104 inline basic_string<_CharT,_Traits,_Allocator>
1105 operator+(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1107 { return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs; }
1109 template<typename _CharT, typename _Traits, typename _Allocator>
1111 operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1112 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1113 { return __lhs._M_base() == __rhs._M_base(); }
1115 template<typename _CharT, typename _Traits, typename _Allocator>
1117 operator==(const _CharT* __lhs,
1118 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1120 __glibcxx_check_string(__lhs);
1121 return __lhs == __rhs._M_base();
1124 template<typename _CharT, typename _Traits, typename _Allocator>
1126 operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1127 const _CharT* __rhs)
1129 __glibcxx_check_string(__rhs);
1130 return __lhs._M_base() == __rhs;
1133 template<typename _CharT, typename _Traits, typename _Allocator>
1135 operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1136 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1137 { return __lhs._M_base() != __rhs._M_base(); }
1139 template<typename _CharT, typename _Traits, typename _Allocator>
1141 operator!=(const _CharT* __lhs,
1142 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1144 __glibcxx_check_string(__lhs);
1145 return __lhs != __rhs._M_base();
1148 template<typename _CharT, typename _Traits, typename _Allocator>
1150 operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1151 const _CharT* __rhs)
1153 __glibcxx_check_string(__rhs);
1154 return __lhs._M_base() != __rhs;
1157 template<typename _CharT, typename _Traits, typename _Allocator>
1159 operator<(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1160 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1161 { return __lhs._M_base() < __rhs._M_base(); }
1163 template<typename _CharT, typename _Traits, typename _Allocator>
1165 operator<(const _CharT* __lhs,
1166 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1168 __glibcxx_check_string(__lhs);
1169 return __lhs < __rhs._M_base();
1172 template<typename _CharT, typename _Traits, typename _Allocator>
1174 operator<(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1175 const _CharT* __rhs)
1177 __glibcxx_check_string(__rhs);
1178 return __lhs._M_base() < __rhs;
1181 template<typename _CharT, typename _Traits, typename _Allocator>
1183 operator<=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1184 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1185 { return __lhs._M_base() <= __rhs._M_base(); }
1187 template<typename _CharT, typename _Traits, typename _Allocator>
1189 operator<=(const _CharT* __lhs,
1190 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1192 __glibcxx_check_string(__lhs);
1193 return __lhs <= __rhs._M_base();
1196 template<typename _CharT, typename _Traits, typename _Allocator>
1198 operator<=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1199 const _CharT* __rhs)
1201 __glibcxx_check_string(__rhs);
1202 return __lhs._M_base() <= __rhs;
1205 template<typename _CharT, typename _Traits, typename _Allocator>
1207 operator>=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1208 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1209 { return __lhs._M_base() >= __rhs._M_base(); }
1211 template<typename _CharT, typename _Traits, typename _Allocator>
1213 operator>=(const _CharT* __lhs,
1214 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1216 __glibcxx_check_string(__lhs);
1217 return __lhs >= __rhs._M_base();
1220 template<typename _CharT, typename _Traits, typename _Allocator>
1222 operator>=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1223 const _CharT* __rhs)
1225 __glibcxx_check_string(__rhs);
1226 return __lhs._M_base() >= __rhs;
1229 template<typename _CharT, typename _Traits, typename _Allocator>
1231 operator>(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1232 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1233 { return __lhs._M_base() > __rhs._M_base(); }
1235 template<typename _CharT, typename _Traits, typename _Allocator>
1237 operator>(const _CharT* __lhs,
1238 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1240 __glibcxx_check_string(__lhs);
1241 return __lhs > __rhs._M_base();
1244 template<typename _CharT, typename _Traits, typename _Allocator>
1246 operator>(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1247 const _CharT* __rhs)
1249 __glibcxx_check_string(__rhs);
1250 return __lhs._M_base() > __rhs;
1254 template<typename _CharT, typename _Traits, typename _Allocator>
1256 swap(basic_string<_CharT,_Traits,_Allocator>& __lhs,
1257 basic_string<_CharT,_Traits,_Allocator>& __rhs)
1258 { __lhs.swap(__rhs); }
1260 template<typename _CharT, typename _Traits, typename _Allocator>
1261 std::basic_ostream<_CharT, _Traits>&
1262 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1263 const basic_string<_CharT, _Traits, _Allocator>& __str)
1264 { return __os << __str._M_base(); }
1266 template<typename _CharT, typename _Traits, typename _Allocator>
1267 std::basic_istream<_CharT,_Traits>&
1268 operator>>(std::basic_istream<_CharT,_Traits>& __is,
1269 basic_string<_CharT,_Traits,_Allocator>& __str)
1271 std::basic_istream<_CharT,_Traits>& __res = __is >> __str._M_base();
1272 __str._M_invalidate_all();
1276 template<typename _CharT, typename _Traits, typename _Allocator>
1277 std::basic_istream<_CharT,_Traits>&
1278 getline(std::basic_istream<_CharT,_Traits>& __is,
1279 basic_string<_CharT,_Traits,_Allocator>& __str, _CharT __delim)
1281 std::basic_istream<_CharT,_Traits>& __res = getline(__is,
1284 __str._M_invalidate_all();
1288 template<typename _CharT, typename _Traits, typename _Allocator>
1289 std::basic_istream<_CharT,_Traits>&
1290 getline(std::basic_istream<_CharT,_Traits>& __is,
1291 basic_string<_CharT,_Traits,_Allocator>& __str)
1293 std::basic_istream<_CharT,_Traits>& __res = getline(__is,
1295 __str._M_invalidate_all();
1299 typedef basic_string<char> string;
1301#ifdef _GLIBCXX_USE_WCHAR_T
1302 typedef basic_string<wchar_t> wstring;
1305#ifdef _GLIBCXX_USE_CHAR8_T
1306 /// A string of @c char8_t
1307 typedef basic_string<char8_t> u8string;
1310#if __cplusplus >= 201103L
1311 /// A string of @c char16_t
1312 typedef basic_string<char16_t> u16string;
1314 /// A string of @c char32_t
1315 typedef basic_string<char32_t> u32string;
1318 template<typename _CharT, typename _Traits, typename _Allocator>
1319 struct _Insert_range_from_self_is_safe<
1320 __gnu_debug::basic_string<_CharT, _Traits, _Allocator> >
1321 { enum { __value = 1 }; };
1323} // namespace __gnu_debug
1325#if __cplusplus >= 201103L
1326namespace std _GLIBCXX_VISIBILITY(default)
1328_GLIBCXX_BEGIN_NAMESPACE_VERSION
1330 /// std::hash specialization for __gnu_debug::basic_string.
1331 template<typename _CharT>
1332 struct hash<__gnu_debug::basic_string<_CharT>>
1333 : public hash<std::basic_string<_CharT>>
1336 template<typename _CharT>
1337 struct __is_fast_hash<hash<__gnu_debug::basic_string<_CharT>>>
1338 : __is_fast_hash<hash<std::basic_string<_CharT>>>
1341_GLIBCXX_END_NAMESPACE_VERSION
1345#undef _GLIBCXX_INSERT_RETURNS_ITERATOR
1346#undef _GLIBCXX_INSERT_RETURNS_ITERATOR_ONLY