1 // Debugging string implementation -*- C++ -*-
3 // Copyright (C) 2003-2020 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/>.
25 /** @file debug/string
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()
46 /** Checks that __s is non-NULL or __n == 0, and then returns __s. */
47 template<typename _CharT, typename _Integer>
49 __check_string(const _CharT* __s,
50 _Integer __n __attribute__((__unused__)),
51 const char* __file __attribute__((__unused__)),
52 unsigned int __line __attribute__((__unused__)),
53 const char* __function __attribute__((__unused__)))
55 #ifdef _GLIBCXX_DEBUG_PEDANTIC
56 _GLIBCXX_DEBUG_VERIFY_STR_COND_AT(__s != 0 || __n == 0,
57 __file, __line, __function);
62 /** Checks that __s is non-NULL and then returns __s. */
63 template<typename _CharT>
65 __check_string(const _CharT* __s,
66 const char* __file __attribute__((__unused__)),
67 unsigned int __line __attribute__((__unused__)),
68 const char* __function __attribute__((__unused__)))
70 #ifdef _GLIBCXX_DEBUG_PEDANTIC
71 _GLIBCXX_DEBUG_VERIFY_STR_COND_AT(__s != 0,
72 __file, __line, __function);
77 #define __glibcxx_check_string_n_constructor(_Str, _Size) \
78 __check_string(_Str, _Size, __FILE__, __LINE__, __PRETTY_FUNCTION__)
80 #define __glibcxx_check_string_constructor(_Str) \
81 __check_string(_Str, __FILE__, __LINE__, __PRETTY_FUNCTION__)
83 /// Class std::basic_string with safety/checking/debug instrumentation.
84 template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
85 typename _Allocator = std::allocator<_CharT> >
87 : public __gnu_debug::_Safe_container<
88 basic_string<_CharT, _Traits, _Allocator>,
89 _Allocator, _Safe_sequence, bool(_GLIBCXX_USE_CXX11_ABI)>,
90 public std::basic_string<_CharT, _Traits, _Allocator>
92 typedef std::basic_string<_CharT, _Traits, _Allocator> _Base;
93 typedef __gnu_debug::_Safe_container<
94 basic_string, _Allocator, _Safe_sequence, bool(_GLIBCXX_USE_CXX11_ABI)>
97 template<typename _ItT, typename _SeqT, typename _CatT>
98 friend class ::__gnu_debug::_Safe_iterator;
100 // type used for positions in insert, erase etc.
101 typedef __gnu_debug::_Safe_iterator<
102 typename _Base::__const_iterator, basic_string> __const_iterator;
106 typedef _Traits traits_type;
107 typedef typename _Traits::char_type value_type;
108 typedef _Allocator allocator_type;
109 typedef typename _Base::size_type size_type;
110 typedef typename _Base::difference_type difference_type;
111 typedef typename _Base::reference reference;
112 typedef typename _Base::const_reference const_reference;
113 typedef typename _Base::pointer pointer;
114 typedef typename _Base::const_pointer const_pointer;
116 typedef __gnu_debug::_Safe_iterator<
117 typename _Base::iterator, basic_string> iterator;
118 typedef __gnu_debug::_Safe_iterator<
119 typename _Base::const_iterator, basic_string> const_iterator;
121 typedef std::reverse_iterator<iterator> reverse_iterator;
122 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
127 _GLIBCXX_NOEXCEPT_IF(std::is_nothrow_default_constructible<_Base>::value)
130 // 21.3.1 construct/copy/destroy:
132 basic_string(const _Allocator& __a) _GLIBCXX_NOEXCEPT
135 #if __cplusplus < 201103L
136 basic_string(const basic_string& __str)
141 basic_string(const basic_string&) = default;
142 basic_string(basic_string&&) = default;
144 basic_string(std::initializer_list<_CharT> __l,
145 const _Allocator& __a = _Allocator())
149 #if _GLIBCXX_USE_CXX11_ABI
150 basic_string(const basic_string& __s, const _Allocator& __a)
151 : _Base(__s, __a) { }
153 basic_string(basic_string&& __s, const _Allocator& __a)
154 : _Base(std::move(__s), __a) { }
157 ~basic_string() = default;
159 // Provides conversion from a normal-mode string to a debug-mode string
160 basic_string(_Base&& __base) noexcept
161 : _Base(std::move(__base)) { }
164 // Provides conversion from a normal-mode string to a debug-mode string
165 basic_string(const _Base& __base)
168 // _GLIBCXX_RESOLVE_LIB_DEFECTS
169 // 42. string ctors specify wrong default allocator
170 basic_string(const basic_string& __str, size_type __pos,
171 size_type __n = _Base::npos,
172 const _Allocator& __a = _Allocator())
173 : _Base(__str, __pos, __n, __a) { }
175 basic_string(const _CharT* __s, size_type __n,
176 const _Allocator& __a = _Allocator())
177 : _Base(__glibcxx_check_string_n_constructor(__s, __n), __n, __a) { }
179 basic_string(const _CharT* __s, const _Allocator& __a = _Allocator())
180 : _Base(__glibcxx_check_string_constructor(__s), __a)
181 { this->assign(__s); }
183 basic_string(size_type __n, _CharT __c,
184 const _Allocator& __a = _Allocator())
185 : _Base(__n, __c, __a) { }
187 template<typename _InputIterator>
188 basic_string(_InputIterator __begin, _InputIterator __end,
189 const _Allocator& __a = _Allocator())
190 : _Base(__gnu_debug::__base(
191 __glibcxx_check_valid_constructor_range(__begin, __end)),
192 __gnu_debug::__base(__end), __a) { }
194 #if __cplusplus < 201103L
196 operator=(const basic_string& __str)
198 this->_M_safe() = __str;
204 operator=(const basic_string&) = default;
207 operator=(basic_string&&) = default;
211 operator=(const _CharT* __s)
213 __glibcxx_check_string(__s);
215 this->_M_invalidate_all();
220 operator=(_CharT __c)
223 this->_M_invalidate_all();
227 #if __cplusplus >= 201103L
229 operator=(std::initializer_list<_CharT> __l)
232 this->_M_invalidate_all();
239 begin() // _GLIBCXX_NOEXCEPT
240 { return iterator(_Base::begin(), this); }
243 begin() const _GLIBCXX_NOEXCEPT
244 { return const_iterator(_Base::begin(), this); }
247 end() // _GLIBCXX_NOEXCEPT
248 { return iterator(_Base::end(), this); }
251 end() const _GLIBCXX_NOEXCEPT
252 { return const_iterator(_Base::end(), this); }
255 rbegin() // _GLIBCXX_NOEXCEPT
256 { return reverse_iterator(end()); }
258 const_reverse_iterator
259 rbegin() const _GLIBCXX_NOEXCEPT
260 { return const_reverse_iterator(end()); }
263 rend() // _GLIBCXX_NOEXCEPT
264 { return reverse_iterator(begin()); }
266 const_reverse_iterator
267 rend() const _GLIBCXX_NOEXCEPT
268 { return const_reverse_iterator(begin()); }
270 #if __cplusplus >= 201103L
272 cbegin() const noexcept
273 { return const_iterator(_Base::begin(), this); }
276 cend() const noexcept
277 { return const_iterator(_Base::end(), this); }
279 const_reverse_iterator
280 crbegin() const noexcept
281 { return const_reverse_iterator(end()); }
283 const_reverse_iterator
284 crend() const noexcept
285 { return const_reverse_iterator(begin()); }
291 using _Base::max_size;
294 resize(size_type __n, _CharT __c)
296 _Base::resize(__n, __c);
297 this->_M_invalidate_all();
301 resize(size_type __n)
302 { this->resize(__n, _CharT()); }
304 #if __cplusplus >= 201103L
306 shrink_to_fit() noexcept
308 if (capacity() > size())
313 this->_M_invalidate_all();
321 using _Base::capacity;
322 using _Base::reserve;
325 clear() // _GLIBCXX_NOEXCEPT
328 this->_M_invalidate_all();
333 // 21.3.4 element access:
335 operator[](size_type __pos) const _GLIBCXX_NOEXCEPT
337 _GLIBCXX_DEBUG_VERIFY(__pos <= this->size(),
338 _M_message(__gnu_debug::__msg_subscript_oob)
339 ._M_sequence(*this, "this")
340 ._M_integer(__pos, "__pos")
341 ._M_integer(this->size(), "size"));
342 return _M_base()[__pos];
346 operator[](size_type __pos) // _GLIBCXX_NOEXCEPT
348 #if __cplusplus < 201103L && defined(_GLIBCXX_DEBUG_PEDANTIC)
349 __glibcxx_check_subscript(__pos);
351 // as an extension v3 allows s[s.size()] when s is non-const.
352 _GLIBCXX_DEBUG_VERIFY(__pos <= this->size(),
353 _M_message(__gnu_debug::__msg_subscript_oob)
354 ._M_sequence(*this, "this")
355 ._M_integer(__pos, "__pos")
356 ._M_integer(this->size(), "size"));
358 return _M_base()[__pos];
363 #if __cplusplus >= 201103L
370 operator+=(const basic_string& __str)
373 this->_M_invalidate_all();
378 operator+=(const _CharT* __s)
380 __glibcxx_check_string(__s);
382 this->_M_invalidate_all();
387 operator+=(_CharT __c)
390 this->_M_invalidate_all();
394 #if __cplusplus >= 201103L
396 operator+=(std::initializer_list<_CharT> __l)
399 this->_M_invalidate_all();
405 append(const basic_string& __str)
407 _Base::append(__str);
408 this->_M_invalidate_all();
413 append(const basic_string& __str, size_type __pos, size_type __n)
415 _Base::append(__str, __pos, __n);
416 this->_M_invalidate_all();
421 append(const _CharT* __s, size_type __n)
423 __glibcxx_check_string_len(__s, __n);
424 _Base::append(__s, __n);
425 this->_M_invalidate_all();
430 append(const _CharT* __s)
432 __glibcxx_check_string(__s);
434 this->_M_invalidate_all();
439 append(size_type __n, _CharT __c)
441 _Base::append(__n, __c);
442 this->_M_invalidate_all();
446 template<typename _InputIterator>
448 append(_InputIterator __first, _InputIterator __last)
450 typename __gnu_debug::_Distance_traits<_InputIterator>::__type __dist;
451 __glibcxx_check_valid_range2(__first, __last, __dist);
453 if (__dist.second >= __dp_sign)
454 _Base::append(__gnu_debug::__unsafe(__first),
455 __gnu_debug::__unsafe(__last));
457 _Base::append(__first, __last);
459 this->_M_invalidate_all();
463 // _GLIBCXX_RESOLVE_LIB_DEFECTS
464 // 7. string clause minor problems
466 push_back(_CharT __c)
468 _Base::push_back(__c);
469 this->_M_invalidate_all();
473 assign(const basic_string& __x)
476 this->_M_invalidate_all();
480 #if __cplusplus >= 201103L
482 assign(basic_string&& __x)
483 noexcept(noexcept(std::declval<_Base&>().assign(std::move(__x))))
485 _Base::assign(std::move(__x));
486 this->_M_invalidate_all();
492 assign(const basic_string& __str, size_type __pos, size_type __n)
494 _Base::assign(__str, __pos, __n);
495 this->_M_invalidate_all();
500 assign(const _CharT* __s, size_type __n)
502 __glibcxx_check_string_len(__s, __n);
503 _Base::assign(__s, __n);
504 this->_M_invalidate_all();
509 assign(const _CharT* __s)
511 __glibcxx_check_string(__s);
513 this->_M_invalidate_all();
518 assign(size_type __n, _CharT __c)
520 _Base::assign(__n, __c);
521 this->_M_invalidate_all();
525 template<typename _InputIterator>
527 assign(_InputIterator __first, _InputIterator __last)
529 typename __gnu_debug::_Distance_traits<_InputIterator>::__type __dist;
530 __glibcxx_check_valid_range2(__first, __last, __dist);
532 if (__dist.second >= __dp_sign)
533 _Base::assign(__gnu_debug::__unsafe(__first),
534 __gnu_debug::__unsafe(__last));
536 _Base::assign(__first, __last);
538 this->_M_invalidate_all();
542 #if __cplusplus >= 201103L
544 assign(std::initializer_list<_CharT> __l)
547 this->_M_invalidate_all();
553 insert(size_type __pos1, const basic_string& __str)
555 _Base::insert(__pos1, __str);
556 this->_M_invalidate_all();
561 insert(size_type __pos1, const basic_string& __str,
562 size_type __pos2, size_type __n)
564 _Base::insert(__pos1, __str, __pos2, __n);
565 this->_M_invalidate_all();
570 insert(size_type __pos, const _CharT* __s, size_type __n)
572 __glibcxx_check_string(__s);
573 _Base::insert(__pos, __s, __n);
574 this->_M_invalidate_all();
579 insert(size_type __pos, const _CharT* __s)
581 __glibcxx_check_string(__s);
582 _Base::insert(__pos, __s);
583 this->_M_invalidate_all();
588 insert(size_type __pos, size_type __n, _CharT __c)
590 _Base::insert(__pos, __n, __c);
591 this->_M_invalidate_all();
596 insert(__const_iterator __p, _CharT __c)
598 __glibcxx_check_insert(__p);
599 typename _Base::iterator __res = _Base::insert(__p.base(), __c);
600 this->_M_invalidate_all();
601 return iterator(__res, this);
604 #if __cplusplus >= 201103L
606 insert(const_iterator __p, size_type __n, _CharT __c)
608 __glibcxx_check_insert(__p);
609 #if _GLIBCXX_USE_CXX11_ABI
610 typename _Base::iterator __res = _Base::insert(__p.base(), __n, __c);
612 const size_type __offset = __p.base() - _Base::cbegin();
613 _Base::insert(_Base::begin() + __offset, __n, __c);
614 typename _Base::iterator __res = _Base::begin() + __offset;
616 this->_M_invalidate_all();
617 return iterator(__res, this);
621 insert(iterator __p, size_type __n, _CharT __c)
623 __glibcxx_check_insert(__p);
624 _Base::insert(__p.base(), __n, __c);
625 this->_M_invalidate_all();
629 template<typename _InputIterator>
631 insert(__const_iterator __p,
632 _InputIterator __first, _InputIterator __last)
634 typename __gnu_debug::_Distance_traits<_InputIterator>::__type __dist;
635 __glibcxx_check_insert_range(__p, __first, __last, __dist);
637 typename _Base::iterator __res;
638 #if _GLIBCXX_USE_CXX11_ABI && __cplusplus >= 201103
639 if (__dist.second >= __dp_sign)
640 __res = _Base::insert(__p.base(), __gnu_debug::__unsafe(__first),
641 __gnu_debug::__unsafe(__last));
643 __res = _Base::insert(__p.base(), __first, __last);
645 const size_type __offset = __p.base() - _Base::begin();
646 _Base::insert(__p.base(), __first, __last);
647 __res = _Base::begin() + __offset;
649 this->_M_invalidate_all();
650 return iterator(__res, this);
653 #if __cplusplus >= 201103L
655 insert(const_iterator __p, std::initializer_list<_CharT> __l)
657 __glibcxx_check_insert(__p);
658 #if _GLIBCXX_USE_CXX11_ABI
659 const auto __res = _Base::insert(__p.base(), __l);
661 const size_type __offset = __p.base() - _Base::cbegin();
662 _Base::insert(_Base::begin() + __offset, __l);
663 auto __res = _Base::begin() + __offset;
665 this->_M_invalidate_all();
666 return iterator(__res, this);
671 erase(size_type __pos = 0, size_type __n = _Base::npos)
673 _Base::erase(__pos, __n);
674 this->_M_invalidate_all();
679 erase(iterator __position)
681 __glibcxx_check_erase(__position);
682 typename _Base::iterator __res = _Base::erase(__position.base());
683 this->_M_invalidate_all();
684 return iterator(__res, this);
688 erase(iterator __first, iterator __last)
690 // _GLIBCXX_RESOLVE_LIB_DEFECTS
691 // 151. can't currently clear() empty container
692 __glibcxx_check_erase_range(__first, __last);
693 typename _Base::iterator __res = _Base::erase(__first.base(),
695 this->_M_invalidate_all();
696 return iterator(__res, this);
699 #if __cplusplus >= 201103L
701 pop_back() // noexcept
703 __glibcxx_check_nonempty();
705 this->_M_invalidate_all();
710 replace(size_type __pos1, size_type __n1, const basic_string& __str)
712 _Base::replace(__pos1, __n1, __str);
713 this->_M_invalidate_all();
718 replace(size_type __pos1, size_type __n1, const basic_string& __str,
719 size_type __pos2, size_type __n2)
721 _Base::replace(__pos1, __n1, __str, __pos2, __n2);
722 this->_M_invalidate_all();
727 replace(size_type __pos, size_type __n1, const _CharT* __s,
730 __glibcxx_check_string_len(__s, __n2);
731 _Base::replace(__pos, __n1, __s, __n2);
732 this->_M_invalidate_all();
737 replace(size_type __pos, size_type __n1, const _CharT* __s)
739 __glibcxx_check_string(__s);
740 _Base::replace(__pos, __n1, __s);
741 this->_M_invalidate_all();
746 replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
748 _Base::replace(__pos, __n1, __n2, __c);
749 this->_M_invalidate_all();
754 replace(__const_iterator __i1, __const_iterator __i2,
755 const basic_string& __str)
757 __glibcxx_check_erase_range(__i1, __i2);
758 _Base::replace(__i1.base(), __i2.base(), __str);
759 this->_M_invalidate_all();
764 replace(__const_iterator __i1, __const_iterator __i2,
765 const _CharT* __s, size_type __n)
767 __glibcxx_check_erase_range(__i1, __i2);
768 __glibcxx_check_string_len(__s, __n);
769 _Base::replace(__i1.base(), __i2.base(), __s, __n);
770 this->_M_invalidate_all();
775 replace(__const_iterator __i1, __const_iterator __i2,
778 __glibcxx_check_erase_range(__i1, __i2);
779 __glibcxx_check_string(__s);
780 _Base::replace(__i1.base(), __i2.base(), __s);
781 this->_M_invalidate_all();
786 replace(__const_iterator __i1, __const_iterator __i2,
787 size_type __n, _CharT __c)
789 __glibcxx_check_erase_range(__i1, __i2);
790 _Base::replace(__i1.base(), __i2.base(), __n, __c);
791 this->_M_invalidate_all();
795 template<typename _InputIterator>
797 replace(__const_iterator __i1, __const_iterator __i2,
798 _InputIterator __j1, _InputIterator __j2)
800 __glibcxx_check_erase_range(__i1, __i2);
802 typename __gnu_debug::_Distance_traits<_InputIterator>::__type __dist;
803 __glibcxx_check_valid_range2(__j1, __j2, __dist);
805 if (__dist.second >= __dp_sign)
806 _Base::replace(__i1.base(), __i2.base(),
807 __gnu_debug::__unsafe(__j1),
808 __gnu_debug::__unsafe(__j2));
810 _Base::replace(__i1.base(), __i2.base(), __j1, __j2);
812 this->_M_invalidate_all();
816 #if __cplusplus >= 201103L
818 replace(__const_iterator __i1, __const_iterator __i2,
819 std::initializer_list<_CharT> __l)
821 __glibcxx_check_erase_range(__i1, __i2);
822 _Base::replace(__i1.base(), __i2.base(), __l);
823 this->_M_invalidate_all();
829 copy(_CharT* __s, size_type __n, size_type __pos = 0) const
831 __glibcxx_check_string_len(__s, __n);
832 return _Base::copy(__s, __n, __pos);
836 swap(basic_string& __x)
837 _GLIBCXX_NOEXCEPT_IF(std::__is_nothrow_swappable<_Base>::value)
843 // 21.3.6 string operations:
845 c_str() const _GLIBCXX_NOEXCEPT
847 const _CharT* __res = _Base::c_str();
848 this->_M_invalidate_all();
853 data() const _GLIBCXX_NOEXCEPT
855 const _CharT* __res = _Base::data();
856 this->_M_invalidate_all();
860 using _Base::get_allocator;
863 find(const basic_string& __str, size_type __pos = 0) const
865 { return _Base::find(__str, __pos); }
868 find(const _CharT* __s, size_type __pos, size_type __n) const
870 __glibcxx_check_string(__s);
871 return _Base::find(__s, __pos, __n);
875 find(const _CharT* __s, size_type __pos = 0) const
877 __glibcxx_check_string(__s);
878 return _Base::find(__s, __pos);
882 find(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
883 { return _Base::find(__c, __pos); }
886 rfind(const basic_string& __str, size_type __pos = _Base::npos) const
888 { return _Base::rfind(__str, __pos); }
891 rfind(const _CharT* __s, size_type __pos, size_type __n) const
893 __glibcxx_check_string_len(__s, __n);
894 return _Base::rfind(__s, __pos, __n);
898 rfind(const _CharT* __s, size_type __pos = _Base::npos) const
900 __glibcxx_check_string(__s);
901 return _Base::rfind(__s, __pos);
905 rfind(_CharT __c, size_type __pos = _Base::npos) const _GLIBCXX_NOEXCEPT
906 { return _Base::rfind(__c, __pos); }
909 find_first_of(const basic_string& __str, size_type __pos = 0) const
911 { return _Base::find_first_of(__str, __pos); }
914 find_first_of(const _CharT* __s, size_type __pos, size_type __n) const
916 __glibcxx_check_string(__s);
917 return _Base::find_first_of(__s, __pos, __n);
921 find_first_of(const _CharT* __s, size_type __pos = 0) const
923 __glibcxx_check_string(__s);
924 return _Base::find_first_of(__s, __pos);
928 find_first_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
929 { return _Base::find_first_of(__c, __pos); }
932 find_last_of(const basic_string& __str,
933 size_type __pos = _Base::npos) const _GLIBCXX_NOEXCEPT
934 { return _Base::find_last_of(__str, __pos); }
937 find_last_of(const _CharT* __s, size_type __pos, size_type __n) const
939 __glibcxx_check_string(__s);
940 return _Base::find_last_of(__s, __pos, __n);
944 find_last_of(const _CharT* __s, size_type __pos = _Base::npos) const
946 __glibcxx_check_string(__s);
947 return _Base::find_last_of(__s, __pos);
951 find_last_of(_CharT __c, size_type __pos = _Base::npos) const
953 { return _Base::find_last_of(__c, __pos); }
956 find_first_not_of(const basic_string& __str, size_type __pos = 0) const
958 { return _Base::find_first_not_of(__str, __pos); }
961 find_first_not_of(const _CharT* __s, size_type __pos, size_type __n) const
963 __glibcxx_check_string_len(__s, __n);
964 return _Base::find_first_not_of(__s, __pos, __n);
968 find_first_not_of(const _CharT* __s, size_type __pos = 0) const
970 __glibcxx_check_string(__s);
971 return _Base::find_first_not_of(__s, __pos);
975 find_first_not_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
976 { return _Base::find_first_not_of(__c, __pos); }
979 find_last_not_of(const basic_string& __str,
980 size_type __pos = _Base::npos) const
982 { return _Base::find_last_not_of(__str, __pos); }
985 find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const
987 __glibcxx_check_string(__s);
988 return _Base::find_last_not_of(__s, __pos, __n);
992 find_last_not_of(const _CharT* __s, size_type __pos = _Base::npos) const
994 __glibcxx_check_string(__s);
995 return _Base::find_last_not_of(__s, __pos);
999 find_last_not_of(_CharT __c, size_type __pos = _Base::npos) const
1001 { return _Base::find_last_not_of(__c, __pos); }
1004 substr(size_type __pos = 0, size_type __n = _Base::npos) const
1005 { return basic_string(_Base::substr(__pos, __n)); }
1008 compare(const basic_string& __str) const
1009 { return _Base::compare(__str); }
1012 compare(size_type __pos1, size_type __n1,
1013 const basic_string& __str) const
1014 { return _Base::compare(__pos1, __n1, __str); }
1017 compare(size_type __pos1, size_type __n1, const basic_string& __str,
1018 size_type __pos2, size_type __n2) const
1019 { return _Base::compare(__pos1, __n1, __str, __pos2, __n2); }
1022 compare(const _CharT* __s) const
1024 __glibcxx_check_string(__s);
1025 return _Base::compare(__s);
1028 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1029 // 5. string::compare specification questionable
1031 compare(size_type __pos1, size_type __n1, const _CharT* __s) const
1033 __glibcxx_check_string(__s);
1034 return _Base::compare(__pos1, __n1, __s);
1037 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1038 // 5. string::compare specification questionable
1040 compare(size_type __pos1, size_type __n1,const _CharT* __s,
1041 size_type __n2) const
1043 __glibcxx_check_string_len(__s, __n2);
1044 return _Base::compare(__pos1, __n1, __s, __n2);
1048 _M_base() _GLIBCXX_NOEXCEPT { return *this; }
1051 _M_base() const _GLIBCXX_NOEXCEPT { return *this; }
1053 using _Safe::_M_invalidate_all;
1056 template<typename _CharT, typename _Traits, typename _Allocator>
1057 inline basic_string<_CharT,_Traits,_Allocator>
1058 operator+(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1059 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1060 { return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs; }
1062 template<typename _CharT, typename _Traits, typename _Allocator>
1063 inline basic_string<_CharT,_Traits,_Allocator>
1064 operator+(const _CharT* __lhs,
1065 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1067 __glibcxx_check_string(__lhs);
1068 return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs;
1071 template<typename _CharT, typename _Traits, typename _Allocator>
1072 inline basic_string<_CharT,_Traits,_Allocator>
1073 operator+(_CharT __lhs,
1074 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1075 { return basic_string<_CharT,_Traits,_Allocator>(1, __lhs) += __rhs; }
1077 template<typename _CharT, typename _Traits, typename _Allocator>
1078 inline basic_string<_CharT,_Traits,_Allocator>
1079 operator+(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1080 const _CharT* __rhs)
1082 __glibcxx_check_string(__rhs);
1083 return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs;
1086 template<typename _CharT, typename _Traits, typename _Allocator>
1087 inline basic_string<_CharT,_Traits,_Allocator>
1088 operator+(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1090 { return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs; }
1092 template<typename _CharT, typename _Traits, typename _Allocator>
1094 operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1095 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1096 { return __lhs._M_base() == __rhs._M_base(); }
1098 template<typename _CharT, typename _Traits, typename _Allocator>
1100 operator==(const _CharT* __lhs,
1101 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1103 __glibcxx_check_string(__lhs);
1104 return __lhs == __rhs._M_base();
1107 template<typename _CharT, typename _Traits, typename _Allocator>
1109 operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1110 const _CharT* __rhs)
1112 __glibcxx_check_string(__rhs);
1113 return __lhs._M_base() == __rhs;
1116 template<typename _CharT, typename _Traits, typename _Allocator>
1118 operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1119 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1120 { return __lhs._M_base() != __rhs._M_base(); }
1122 template<typename _CharT, typename _Traits, typename _Allocator>
1124 operator!=(const _CharT* __lhs,
1125 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1127 __glibcxx_check_string(__lhs);
1128 return __lhs != __rhs._M_base();
1131 template<typename _CharT, typename _Traits, typename _Allocator>
1133 operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1134 const _CharT* __rhs)
1136 __glibcxx_check_string(__rhs);
1137 return __lhs._M_base() != __rhs;
1140 template<typename _CharT, typename _Traits, typename _Allocator>
1142 operator<(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1143 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1144 { return __lhs._M_base() < __rhs._M_base(); }
1146 template<typename _CharT, typename _Traits, typename _Allocator>
1148 operator<(const _CharT* __lhs,
1149 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1151 __glibcxx_check_string(__lhs);
1152 return __lhs < __rhs._M_base();
1155 template<typename _CharT, typename _Traits, typename _Allocator>
1157 operator<(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1158 const _CharT* __rhs)
1160 __glibcxx_check_string(__rhs);
1161 return __lhs._M_base() < __rhs;
1164 template<typename _CharT, typename _Traits, typename _Allocator>
1166 operator<=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1167 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1168 { return __lhs._M_base() <= __rhs._M_base(); }
1170 template<typename _CharT, typename _Traits, typename _Allocator>
1172 operator<=(const _CharT* __lhs,
1173 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1175 __glibcxx_check_string(__lhs);
1176 return __lhs <= __rhs._M_base();
1179 template<typename _CharT, typename _Traits, typename _Allocator>
1181 operator<=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1182 const _CharT* __rhs)
1184 __glibcxx_check_string(__rhs);
1185 return __lhs._M_base() <= __rhs;
1188 template<typename _CharT, typename _Traits, typename _Allocator>
1190 operator>=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1191 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1192 { return __lhs._M_base() >= __rhs._M_base(); }
1194 template<typename _CharT, typename _Traits, typename _Allocator>
1196 operator>=(const _CharT* __lhs,
1197 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1199 __glibcxx_check_string(__lhs);
1200 return __lhs >= __rhs._M_base();
1203 template<typename _CharT, typename _Traits, typename _Allocator>
1205 operator>=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1206 const _CharT* __rhs)
1208 __glibcxx_check_string(__rhs);
1209 return __lhs._M_base() >= __rhs;
1212 template<typename _CharT, typename _Traits, typename _Allocator>
1214 operator>(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1215 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1216 { return __lhs._M_base() > __rhs._M_base(); }
1218 template<typename _CharT, typename _Traits, typename _Allocator>
1220 operator>(const _CharT* __lhs,
1221 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1223 __glibcxx_check_string(__lhs);
1224 return __lhs > __rhs._M_base();
1227 template<typename _CharT, typename _Traits, typename _Allocator>
1229 operator>(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1230 const _CharT* __rhs)
1232 __glibcxx_check_string(__rhs);
1233 return __lhs._M_base() > __rhs;
1237 template<typename _CharT, typename _Traits, typename _Allocator>
1239 swap(basic_string<_CharT,_Traits,_Allocator>& __lhs,
1240 basic_string<_CharT,_Traits,_Allocator>& __rhs)
1241 { __lhs.swap(__rhs); }
1243 template<typename _CharT, typename _Traits, typename _Allocator>
1244 std::basic_ostream<_CharT, _Traits>&
1245 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1246 const basic_string<_CharT, _Traits, _Allocator>& __str)
1247 { return __os << __str._M_base(); }
1249 template<typename _CharT, typename _Traits, typename _Allocator>
1250 std::basic_istream<_CharT,_Traits>&
1251 operator>>(std::basic_istream<_CharT,_Traits>& __is,
1252 basic_string<_CharT,_Traits,_Allocator>& __str)
1254 std::basic_istream<_CharT,_Traits>& __res = __is >> __str._M_base();
1255 __str._M_invalidate_all();
1259 template<typename _CharT, typename _Traits, typename _Allocator>
1260 std::basic_istream<_CharT,_Traits>&
1261 getline(std::basic_istream<_CharT,_Traits>& __is,
1262 basic_string<_CharT,_Traits,_Allocator>& __str, _CharT __delim)
1264 std::basic_istream<_CharT,_Traits>& __res = getline(__is,
1267 __str._M_invalidate_all();
1271 template<typename _CharT, typename _Traits, typename _Allocator>
1272 std::basic_istream<_CharT,_Traits>&
1273 getline(std::basic_istream<_CharT,_Traits>& __is,
1274 basic_string<_CharT,_Traits,_Allocator>& __str)
1276 std::basic_istream<_CharT,_Traits>& __res = getline(__is,
1278 __str._M_invalidate_all();
1282 typedef basic_string<char> string;
1284 #ifdef _GLIBCXX_USE_WCHAR_T
1285 typedef basic_string<wchar_t> wstring;
1288 template<typename _CharT, typename _Traits, typename _Allocator>
1289 struct _Insert_range_from_self_is_safe<
1290 __gnu_debug::basic_string<_CharT, _Traits, _Allocator> >
1291 { enum { __value = 1 }; };
1293 } // namespace __gnu_debug