29 #ifndef _GLIBCXX_DEBUG_STRING
30 #define _GLIBCXX_DEBUG_STRING 1
32 #pragma GCC system_header
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()
47 template<
typename _CharT,
typename _Integer>
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);
63 template<
typename _CharT>
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__)
84 template<
typename _CharT,
typename _Traits = std::
char_traits<_CharT>,
85 typename _Allocator = std::allocator<_CharT> >
88 basic_string<_CharT, _Traits, _Allocator>,
89 _Allocator, _Safe_sequence, bool(_GLIBCXX_USE_CXX11_ABI)>,
97 template<
typename _ItT,
typename _SeqT,
typename _CatT>
98 friend class ::__gnu_debug::_Safe_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;
135 #if __cplusplus < 201103L
145 const _Allocator& __a = _Allocator())
149 #if _GLIBCXX_USE_CXX11_ABI
151 :
_Base(__s, __a) { }
172 const _Allocator& __a = _Allocator())
173 :
_Base(__str, __pos, __n, __a) { }
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); }
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())
191 __glibcxx_check_valid_constructor_range(__begin, __end)),
194 #if __cplusplus < 201103L
198 this->_M_safe() = __str;
211 operator=(
const _CharT* __s)
213 __glibcxx_check_string(__s);
220 operator=(_CharT __c)
227 #if __cplusplus >= 201103L
243 begin()
const _GLIBCXX_NOEXCEPT
251 end()
const _GLIBCXX_NOEXCEPT
259 rbegin()
const _GLIBCXX_NOEXCEPT
267 rend()
const _GLIBCXX_NOEXCEPT
270 #if __cplusplus >= 201103L
272 cbegin()
const noexcept
276 cend()
const noexcept
280 crbegin()
const noexcept
284 crend()
const noexcept
294 resize(size_type __n, _CharT __c)
301 resize(size_type __n)
302 { this->resize(__n, _CharT()); }
304 #if __cplusplus >= 201103L
306 shrink_to_fit() noexcept
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)
348 #if __cplusplus < 201103L && defined(_GLIBCXX_DEBUG_PEDANTIC)
349 __glibcxx_check_subscript(__pos);
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
378 operator+=(
const _CharT* __s)
380 __glibcxx_check_string(__s);
387 operator+=(_CharT __c)
394 #if __cplusplus >= 201103L
413 append(
const basic_string& __str, size_type __pos, size_type __n)
421 append(
const _CharT* __s, size_type __n)
423 __glibcxx_check_string_len(__s, __n);
430 append(
const _CharT* __s)
432 __glibcxx_check_string(__s);
439 append(size_type __n, _CharT __c)
446 template<
typename _InputIterator>
448 append(_InputIterator __first, _InputIterator __last)
451 __glibcxx_check_valid_range2(__first, __last, __dist);
453 if (__dist.
second >= __dp_sign)
455 __gnu_debug::__unsafe(__last));
466 push_back(_CharT __c)
480 #if __cplusplus >= 201103L
483 noexcept(noexcept(std::declval<_Base&>().assign(
std::move(__x))))
492 assign(
const basic_string& __str, size_type __pos, size_type __n)
500 assign(
const _CharT* __s, size_type __n)
502 __glibcxx_check_string_len(__s, __n);
509 assign(
const _CharT* __s)
511 __glibcxx_check_string(__s);
518 assign(size_type __n, _CharT __c)
525 template<
typename _InputIterator>
527 assign(_InputIterator __first, _InputIterator __last)
530 __glibcxx_check_valid_range2(__first, __last, __dist);
532 if (__dist.
second >= __dp_sign)
534 __gnu_debug::__unsafe(__last));
542 #if __cplusplus >= 201103L
562 size_type __pos2, size_type __n)
570 insert(size_type __pos,
const _CharT* __s, size_type __n)
572 __glibcxx_check_string(__s);
579 insert(size_type __pos,
const _CharT* __s)
581 __glibcxx_check_string(__s);
588 insert(size_type __pos, size_type __n, _CharT __c)
601 return iterator(__res,
this);
604 #if __cplusplus >= 201103L
609 #if _GLIBCXX_USE_CXX11_ABI
614 typename _Base::iterator __res =
_Base::begin() + __offset;
617 return iterator(__res,
this);
621 insert(
iterator __p, size_type __n, _CharT __c)
629 template<
typename _InputIterator>
632 _InputIterator __first, _InputIterator __last)
637 typename _Base::iterator __res;
638 #if _GLIBCXX_USE_CXX11_ABI
639 if (__dist.
second >= __dp_sign)
641 __gnu_debug::__unsafe(__last));
650 return iterator(__res,
this);
653 #if __cplusplus >= 201103L
658 #if _GLIBCXX_USE_CXX11_ABI
666 return iterator(__res,
this);
671 erase(size_type __pos = 0, size_type __n =
_Base::npos)
684 return iterator(__res,
this);
696 return iterator(__res,
this);
699 #if __cplusplus >= 201103L
703 __glibcxx_check_nonempty();
710 replace(size_type __pos1, size_type __n1,
const basic_string& __str)
718 replace(size_type __pos1, size_type __n1,
const basic_string& __str,
719 size_type __pos2, size_type __n2)
727 replace(size_type __pos, size_type __n1,
const _CharT* __s,
730 __glibcxx_check_string_len(__s, __n2);
737 replace(size_type __pos, size_type __n1,
const _CharT* __s)
739 __glibcxx_check_string(__s);
746 replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
765 const _CharT* __s, size_type __n)
768 __glibcxx_check_string_len(__s, __n);
779 __glibcxx_check_string(__s);
787 size_type __n, _CharT __c)
795 template<
typename _InputIterator>
798 _InputIterator __j1, _InputIterator __j2)
803 __glibcxx_check_valid_range2(__j1, __j2, __dist);
805 if (__dist.
second >= __dp_sign)
807 __gnu_debug::__unsafe(__j1),
808 __gnu_debug::__unsafe(__j2));
816 #if __cplusplus >= 201103L
829 copy(_CharT* __s, size_type __n, size_type __pos = 0)
const
831 __glibcxx_check_string_len(__s, __n);
837 _GLIBCXX_NOEXCEPT_IF(std::__is_nothrow_swappable<_Base>::value)
845 c_str()
const _GLIBCXX_NOEXCEPT
853 data()
const _GLIBCXX_NOEXCEPT
863 find(
const basic_string& __str, size_type __pos = 0)
const
868 find(
const _CharT* __s, size_type __pos, size_type __n)
const
870 __glibcxx_check_string(__s);
875 find(
const _CharT* __s, size_type __pos = 0)
const
877 __glibcxx_check_string(__s);
882 find(_CharT __c, size_type __pos = 0)
const _GLIBCXX_NOEXCEPT
891 rfind(
const _CharT* __s, size_type __pos, size_type __n)
const
893 __glibcxx_check_string_len(__s, __n);
898 rfind(
const _CharT* __s, size_type __pos =
_Base::npos)
const
900 __glibcxx_check_string(__s);
905 rfind(_CharT __c, size_type __pos =
_Base::npos)
const _GLIBCXX_NOEXCEPT
909 find_first_of(
const basic_string& __str, size_type __pos = 0)
const
914 find_first_of(
const _CharT* __s, size_type __pos, size_type __n)
const
916 __glibcxx_check_string(__s);
921 find_first_of(
const _CharT* __s, size_type __pos = 0)
const
923 __glibcxx_check_string(__s);
928 find_first_of(_CharT __c, size_type __pos = 0)
const _GLIBCXX_NOEXCEPT
933 size_type __pos =
_Base::npos)
const _GLIBCXX_NOEXCEPT
937 find_last_of(
const _CharT* __s, size_type __pos, size_type __n)
const
939 __glibcxx_check_string(__s);
944 find_last_of(
const _CharT* __s, size_type __pos =
_Base::npos)
const
946 __glibcxx_check_string(__s);
951 find_last_of(_CharT __c, size_type __pos =
_Base::npos)
const
956 find_first_not_of(
const basic_string& __str, size_type __pos = 0)
const
961 find_first_not_of(
const _CharT* __s, size_type __pos, size_type __n)
const
963 __glibcxx_check_string_len(__s, __n);
968 find_first_not_of(
const _CharT* __s, size_type __pos = 0)
const
970 __glibcxx_check_string(__s);
975 find_first_not_of(_CharT __c, size_type __pos = 0)
const _GLIBCXX_NOEXCEPT
985 find_last_not_of(
const _CharT* __s, size_type __pos, size_type __n)
const
987 __glibcxx_check_string(__s);
992 find_last_not_of(
const _CharT* __s, size_type __pos =
_Base::npos)
const
994 __glibcxx_check_string(__s);
999 find_last_not_of(_CharT __c, size_type __pos =
_Base::npos)
const
1004 substr(size_type __pos = 0, size_type __n =
_Base::npos)
const
1012 compare(size_type __pos1, size_type __n1,
1017 compare(size_type __pos1, size_type __n1,
const basic_string& __str,
1018 size_type __pos2, size_type __n2)
const
1022 compare(
const _CharT* __s)
const
1024 __glibcxx_check_string(__s);
1031 compare(size_type __pos1, size_type __n1,
const _CharT* __s)
const
1033 __glibcxx_check_string(__s);
1040 compare(size_type __pos1, size_type __n1,
const _CharT* __s,
1041 size_type __n2)
const
1043 __glibcxx_check_string_len(__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>
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>
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>
1246 const basic_string<_CharT, _Traits, _Allocator>& __str)
1247 {
return __os << __str._M_base(); }
1249 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1252 basic_string<_CharT,_Traits,_Allocator>& __str)
1255 __str._M_invalidate_all();
1259 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1262 basic_string<_CharT,_Traits,_Allocator>& __str, _CharT __delim)
1267 __str._M_invalidate_all();
1271 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1274 basic_string<_CharT,_Traits,_Allocator>& __str)
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 }; };