29 #ifndef _GLIBCXX_DEBUG_STRING
30 #define _GLIBCXX_DEBUG_STRING 1
39 template<
typename _CharT,
typename _Traits = std::
char_traits<_CharT>,
40 typename _Allocator = std::allocator<_CharT> >
51 typedef _Traits traits_type;
52 typedef typename _Traits::char_type value_type;
53 typedef _Allocator allocator_type;
54 typedef typename _Base::size_type size_type;
55 typedef typename _Base::difference_type difference_type;
56 typedef typename _Base::reference reference;
57 typedef typename _Base::const_reference const_reference;
58 typedef typename _Base::pointer pointer;
59 typedef typename _Base::const_pointer const_pointer;
89 const _Allocator& __a = _Allocator())
90 : _Base(__str, __pos, __n, __a)
94 const _Allocator& __a = _Allocator())
98 basic_string(
const _CharT* __s,
const _Allocator& __a = _Allocator())
100 { this->assign(__s); }
103 const _Allocator& __a = _Allocator())
104 :
_Base(__n, __c, __a)
107 template<
typename _InputIterator>
109 const _Allocator& __a = _Allocator())
110 :
_Base(__gnu_debug::
__base(__gnu_debug::__check_valid_range(__begin,
112 __gnu_debug::
__base(__end), __a)
115 #if __cplusplus >= 201103L
117 : _Base(std::move(__str))
121 const _Allocator& __a = _Allocator())
131 *
static_cast<_Base*
>(
this) = __str;
137 operator=(
const _CharT* __s)
139 __glibcxx_check_string(__s);
140 *
static_cast<_Base*
>(
this) = __s;
146 operator=(_CharT __c)
148 *
static_cast<_Base*
>(
this) = __c;
153 #if __cplusplus >= 201103L
157 __glibcxx_check_self_move_assign(__str);
158 *
static_cast<_Base*
>(
this) = std::move(__str);
166 *
static_cast<_Base*
>(
this) = __l;
186 end() const _GLIBCXX_NOEXCEPT
193 const_reverse_iterator
201 const_reverse_iterator
205 #if __cplusplus >= 201103L
214 const_reverse_iterator
218 const_reverse_iterator
237 { this->
resize(__n, _CharT()); }
239 #if __cplusplus >= 201103L
272 _GLIBCXX_DEBUG_VERIFY(__pos <= this->
size(),
273 _M_message(__gnu_debug::__msg_subscript_oob)
274 ._M_sequence(*
this,
"this")
275 ._M_integer(__pos,
"__pos")
276 ._M_integer(this->
size(),
"size"));
277 return _M_base()[__pos];
283 #ifdef _GLIBCXX_DEBUG_PEDANTIC
284 __glibcxx_check_subscript(__pos);
287 _GLIBCXX_DEBUG_VERIFY(__pos <= this->
size(),
288 _M_message(__gnu_debug::__msg_subscript_oob)
289 ._M_sequence(*
this,
"this")
290 ._M_integer(__pos,
"__pos")
291 ._M_integer(this->
size(),
"size"));
293 return _M_base()[__pos];
298 #if __cplusplus >= 201103L
313 operator+=(
const _CharT* __s)
315 __glibcxx_check_string(__s);
322 operator+=(_CharT __c)
329 #if __cplusplus >= 201103L
348 append(
const basic_string& __str, size_type __pos, size_type __n)
356 append(
const _CharT* __s, size_type __n)
358 __glibcxx_check_string_len(__s, __n);
365 append(
const _CharT* __s)
367 __glibcxx_check_string(__s);
374 append(size_type __n, _CharT __c)
381 template<
typename _InputIterator>
383 append(_InputIterator __first, _InputIterator __last)
385 __glibcxx_check_valid_range(__first, __last);
409 #if __cplusplus >= 201103L
420 assign(
const basic_string& __str, size_type __pos, size_type __n)
428 assign(
const _CharT* __s, size_type __n)
430 __glibcxx_check_string_len(__s, __n);
437 assign(
const _CharT* __s)
439 __glibcxx_check_string(__s);
446 assign(size_type __n, _CharT __c)
453 template<
typename _InputIterator>
455 assign(_InputIterator __first, _InputIterator __last)
457 __glibcxx_check_valid_range(__first, __last);
464 #if __cplusplus >= 201103L
484 size_type __pos2, size_type __n)
492 insert(size_type __pos,
const _CharT* __s, size_type __n)
494 __glibcxx_check_string(__s);
501 insert(size_type __pos,
const _CharT* __s)
503 __glibcxx_check_string(__s);
510 insert(size_type __pos, size_type __n, _CharT __c)
518 insert(iterator __p, _CharT __c)
521 typename _Base::iterator __res =
_Base::insert(__p.base(), __c);
523 return iterator(__res,
this);
527 insert(iterator __p, size_type __n, _CharT __c)
534 template<
typename _InputIterator>
536 insert(iterator __p, _InputIterator __first, _InputIterator __last)
544 #if __cplusplus >= 201103L
563 erase(iterator __position)
566 typename _Base::iterator __res =
_Base::erase(__position.base());
568 return iterator(__res,
this);
572 erase(iterator __first, iterator __last)
577 typename _Base::iterator __res =
_Base::erase(__first.base(),
580 return iterator(__res,
this);
583 #if __cplusplus >= 201103L
587 __glibcxx_check_nonempty();
594 replace(size_type __pos1, size_type __n1,
const basic_string& __str)
602 replace(size_type __pos1, size_type __n1,
const basic_string& __str,
603 size_type __pos2, size_type __n2)
611 replace(size_type __pos, size_type __n1,
const _CharT* __s,
614 __glibcxx_check_string_len(__s, __n2);
621 replace(size_type __pos, size_type __n1,
const _CharT* __s)
623 __glibcxx_check_string(__s);
630 replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
638 replace(iterator __i1, iterator __i2,
const basic_string& __str)
647 replace(iterator __i1, iterator __i2,
const _CharT* __s, size_type __n)
650 __glibcxx_check_string_len(__s, __n);
657 replace(iterator __i1, iterator __i2,
const _CharT* __s)
660 __glibcxx_check_string(__s);
667 replace(iterator __i1, iterator __i2, size_type __n, _CharT __c)
675 template<
typename _InputIterator>
677 replace(iterator __i1, iterator __i2,
678 _InputIterator __j1, _InputIterator __j2)
681 __glibcxx_check_valid_range(__j1, __j2);
687 #if __cplusplus >= 201103L
699 copy(_CharT* __s, size_type __n, size_type __pos = 0)
const
701 __glibcxx_check_string_len(__s, __n);
734 find(
const basic_string& __str, size_type __pos = 0) const
739 find(
const _CharT* __s, size_type __pos, size_type __n)
const
741 __glibcxx_check_string(__s);
746 find(
const _CharT* __s, size_type __pos = 0)
const
748 __glibcxx_check_string(__s);
753 find(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
762 rfind(
const _CharT* __s, size_type __pos, size_type __n)
const
764 __glibcxx_check_string_len(__s, __n);
771 __glibcxx_check_string(__s);
776 rfind(_CharT __c, size_type __pos =
_Base::npos) const _GLIBCXX_NOEXCEPT
780 find_first_of(
const basic_string& __str, size_type __pos = 0) const
785 find_first_of(
const _CharT* __s, size_type __pos, size_type __n)
const
787 __glibcxx_check_string(__s);
792 find_first_of(
const _CharT* __s, size_type __pos = 0)
const
794 __glibcxx_check_string(__s);
799 find_first_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
804 size_type __pos =
_Base::npos) const _GLIBCXX_NOEXCEPT
808 find_last_of(
const _CharT* __s, size_type __pos, size_type __n)
const
810 __glibcxx_check_string(__s);
815 find_last_of(
const _CharT* __s, size_type __pos =
_Base::npos)
const
817 __glibcxx_check_string(__s);
827 find_first_not_of(
const basic_string& __str, size_type __pos = 0) const
832 find_first_not_of(
const _CharT* __s, size_type __pos, size_type __n)
const
834 __glibcxx_check_string_len(__s, __n);
839 find_first_not_of(
const _CharT* __s, size_type __pos = 0)
const
841 __glibcxx_check_string(__s);
846 find_first_not_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
856 find_last_not_of(
const _CharT* __s, size_type __pos, size_type __n)
const
858 __glibcxx_check_string(__s);
863 find_last_not_of(
const _CharT* __s, size_type __pos =
_Base::npos)
const
865 __glibcxx_check_string(__s);
883 compare(size_type __pos1, size_type __n1,
888 compare(size_type __pos1, size_type __n1,
const basic_string& __str,
889 size_type __pos2, size_type __n2)
const
893 compare(
const _CharT* __s)
const
895 __glibcxx_check_string(__s);
902 compare(size_type __pos1, size_type __n1,
const _CharT* __s)
const
904 __glibcxx_check_string(__s);
911 compare(size_type __pos1, size_type __n1,
const _CharT* __s,
912 size_type __n2)
const
914 __glibcxx_check_string_len(__s, __n2);
919 _M_base() _GLIBCXX_NOEXCEPT {
return *
this; }
922 _M_base() const _GLIBCXX_NOEXCEPT {
return *
this; }
927 template<
typename _CharT,
typename _Traits,
typename _Allocator>
928 inline basic_string<_CharT,_Traits,_Allocator>
929 operator+(
const basic_string<_CharT,_Traits,_Allocator>& __lhs,
930 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
931 {
return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs; }
933 template<
typename _CharT,
typename _Traits,
typename _Allocator>
934 inline basic_string<_CharT,_Traits,_Allocator>
935 operator+(
const _CharT* __lhs,
936 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
938 __glibcxx_check_string(__lhs);
939 return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs;
942 template<
typename _CharT,
typename _Traits,
typename _Allocator>
943 inline basic_string<_CharT,_Traits,_Allocator>
944 operator+(_CharT __lhs,
945 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
946 {
return basic_string<_CharT,_Traits,_Allocator>(1, __lhs) += __rhs; }
948 template<
typename _CharT,
typename _Traits,
typename _Allocator>
949 inline basic_string<_CharT,_Traits,_Allocator>
950 operator+(
const basic_string<_CharT,_Traits,_Allocator>& __lhs,
953 __glibcxx_check_string(__rhs);
954 return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs;
957 template<
typename _CharT,
typename _Traits,
typename _Allocator>
958 inline basic_string<_CharT,_Traits,_Allocator>
959 operator+(
const basic_string<_CharT,_Traits,_Allocator>& __lhs,
961 {
return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs; }
963 template<
typename _CharT,
typename _Traits,
typename _Allocator>
965 operator==(
const basic_string<_CharT,_Traits,_Allocator>& __lhs,
966 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
967 {
return __lhs._M_base() == __rhs._M_base(); }
969 template<
typename _CharT,
typename _Traits,
typename _Allocator>
971 operator==(
const _CharT* __lhs,
972 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
974 __glibcxx_check_string(__lhs);
975 return __lhs == __rhs._M_base();
978 template<
typename _CharT,
typename _Traits,
typename _Allocator>
980 operator==(
const basic_string<_CharT,_Traits,_Allocator>& __lhs,
983 __glibcxx_check_string(__rhs);
984 return __lhs._M_base() == __rhs;
987 template<
typename _CharT,
typename _Traits,
typename _Allocator>
989 operator!=(
const basic_string<_CharT,_Traits,_Allocator>& __lhs,
990 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
991 {
return __lhs._M_base() != __rhs._M_base(); }
993 template<
typename _CharT,
typename _Traits,
typename _Allocator>
995 operator!=(
const _CharT* __lhs,
996 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
998 __glibcxx_check_string(__lhs);
999 return __lhs != __rhs._M_base();
1002 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1004 operator!=(
const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1005 const _CharT* __rhs)
1007 __glibcxx_check_string(__rhs);
1008 return __lhs._M_base() != __rhs;
1011 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1013 operator<(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1014 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1015 {
return __lhs._M_base() < __rhs._M_base(); }
1017 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1019 operator<(
const _CharT* __lhs,
1020 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1022 __glibcxx_check_string(__lhs);
1023 return __lhs < __rhs._M_base();
1026 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1028 operator<(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1029 const _CharT* __rhs)
1031 __glibcxx_check_string(__rhs);
1032 return __lhs._M_base() < __rhs;
1035 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1037 operator<=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1038 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1039 {
return __lhs._M_base() <= __rhs._M_base(); }
1041 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1043 operator<=(
const _CharT* __lhs,
1044 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1046 __glibcxx_check_string(__lhs);
1047 return __lhs <= __rhs._M_base();
1050 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1052 operator<=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1053 const _CharT* __rhs)
1055 __glibcxx_check_string(__rhs);
1056 return __lhs._M_base() <= __rhs;
1059 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1061 operator>=(
const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1062 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1063 {
return __lhs._M_base() >= __rhs._M_base(); }
1065 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1067 operator>=(
const _CharT* __lhs,
1068 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1070 __glibcxx_check_string(__lhs);
1071 return __lhs >= __rhs._M_base();
1074 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1076 operator>=(
const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1077 const _CharT* __rhs)
1079 __glibcxx_check_string(__rhs);
1080 return __lhs._M_base() >= __rhs;
1083 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1085 operator>(
const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1086 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1087 {
return __lhs._M_base() > __rhs._M_base(); }
1089 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1091 operator>(
const _CharT* __lhs,
1092 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1094 __glibcxx_check_string(__lhs);
1095 return __lhs > __rhs._M_base();
1098 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1100 operator>(
const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1101 const _CharT* __rhs)
1103 __glibcxx_check_string(__rhs);
1104 return __lhs._M_base() > __rhs;
1108 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1110 swap(basic_string<_CharT,_Traits,_Allocator>& __lhs,
1111 basic_string<_CharT,_Traits,_Allocator>& __rhs)
1112 { __lhs.swap(__rhs); }
1114 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1116 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1117 const basic_string<_CharT, _Traits, _Allocator>& __str)
1118 {
return __os << __str._M_base(); }
1120 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1123 basic_string<_CharT,_Traits,_Allocator>& __str)
1126 __str._M_invalidate_all();
1130 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1133 basic_string<_CharT,_Traits,_Allocator>& __str, _CharT __delim)
1138 __str._M_invalidate_all();
1142 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1145 basic_string<_CharT,_Traits,_Allocator>& __str)
1149 __str._M_invalidate_all();
1153 typedef basic_string<char>
string;
1155 #ifdef _GLIBCXX_USE_WCHAR_T
1156 typedef basic_string<wchar_t>
wstring;