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;
117 typename _Base::iterator, basic_string>
iterator;
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;
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;
160 basic_string(_Base&&
__base) noexcept
161 : _Base(std::move(
__base)) { }
165 basic_string(
const _Base&
__base)
170 basic_string(
const basic_string& __str, size_type __pos,
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())
191 __glibcxx_check_valid_constructor_range(__begin, __end)),
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);
220 operator=(_CharT __c)
227 #if __cplusplus >= 201103L 243 begin()
const _GLIBCXX_NOEXCEPT
251 end()
const _GLIBCXX_NOEXCEPT
252 {
return const_iterator(
_Base::end(),
this); }
256 {
return reverse_iterator(end()); }
258 const_reverse_iterator
259 rbegin()
const _GLIBCXX_NOEXCEPT
260 {
return const_reverse_iterator(end()); }
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
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()); }
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 370 operator+=(
const basic_string& __str)
378 operator+=(
const _CharT* __s)
380 __glibcxx_check_string(__s);
387 operator+=(_CharT __c)
394 #if __cplusplus >= 201103L 405 append(
const basic_string& __str)
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)
473 assign(
const basic_string& __x)
480 #if __cplusplus >= 201103L 482 assign(basic_string&& __x)
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 553 insert(size_type __pos1,
const basic_string& __str)
561 insert(size_type __pos1,
const basic_string& __str,
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)
596 insert(__const_iterator __p, _CharT __c)
601 return iterator(__res,
this);
604 #if __cplusplus >= 201103L 606 insert(const_iterator __p, size_type __n, _CharT __c)
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>
631 insert(__const_iterator __p,
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)
679 erase(iterator __position)
684 return iterator(__res,
this);
688 erase(iterator __first, iterator __last)
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)
754 replace(__const_iterator __i1, __const_iterator __i2,
755 const basic_string& __str)
764 replace(__const_iterator __i1, __const_iterator __i2,
765 const _CharT* __s, size_type __n)
768 __glibcxx_check_string_len(__s, __n);
775 replace(__const_iterator __i1, __const_iterator __i2,
779 __glibcxx_check_string(__s);
786 replace(__const_iterator __i1, __const_iterator __i2,
787 size_type __n, _CharT __c)
795 template<
typename _InputIterator>
797 replace(__const_iterator __i1, __const_iterator __i2,
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 818 replace(__const_iterator __i1, __const_iterator __i2,
829 copy(_CharT* __s, size_type __n, size_type __pos = 0)
const 831 __glibcxx_check_string_len(__s, __n);
836 swap(basic_string& __x)
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
886 rfind(
const basic_string& __str, size_type __pos =
_Base::npos)
const 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
932 find_last_of(
const basic_string& __str,
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
979 find_last_not_of(
const basic_string& __str,
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 1008 compare(
const basic_string& __str)
const 1012 compare(size_type __pos1, size_type __n1,
1013 const basic_string& __str)
const 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>
1064 operator+(
const _CharT* __lhs,
1067 __glibcxx_check_string(__lhs);
1071 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1073 operator+(_CharT __lhs,
1077 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1080 const _CharT* __rhs)
1082 __glibcxx_check_string(__rhs);
1086 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1092 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1096 {
return __lhs._M_base() == __rhs._M_base(); }
1098 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1100 operator==(
const _CharT* __lhs,
1103 __glibcxx_check_string(__lhs);
1104 return __lhs == __rhs._M_base();
1107 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1110 const _CharT* __rhs)
1112 __glibcxx_check_string(__rhs);
1113 return __lhs._M_base() == __rhs;
1116 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1120 {
return __lhs._M_base() != __rhs._M_base(); }
1122 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1124 operator!=(
const _CharT* __lhs,
1127 __glibcxx_check_string(__lhs);
1128 return __lhs != __rhs._M_base();
1131 template<
typename _CharT,
typename _Traits,
typename _Allocator>
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,
1144 {
return __lhs._M_base() < __rhs._M_base(); }
1146 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1148 operator<(
const _CharT* __lhs,
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,
1168 {
return __lhs._M_base() <= __rhs._M_base(); }
1170 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1172 operator<=(
const _CharT* __lhs,
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>
1192 {
return __lhs._M_base() >= __rhs._M_base(); }
1194 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1196 operator>=(
const _CharT* __lhs,
1199 __glibcxx_check_string(__lhs);
1200 return __lhs >= __rhs._M_base();
1203 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1206 const _CharT* __rhs)
1208 __glibcxx_check_string(__rhs);
1209 return __lhs._M_base() >= __rhs;
1212 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1216 {
return __lhs._M_base() > __rhs._M_base(); }
1218 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1220 operator>(
const _CharT* __lhs,
1223 __glibcxx_check_string(__lhs);
1224 return __lhs > __rhs._M_base();
1227 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1230 const _CharT* __rhs)
1232 __glibcxx_check_string(__rhs);
1233 return __lhs._M_base() > __rhs;
1237 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1241 { __lhs.swap(__rhs); }
1243 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1245 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1247 {
return __os << __str._M_base(); }
1249 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1259 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1271 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1284 #ifdef _GLIBCXX_USE_WCHAR_T 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 }; };
Template class basic_istream.
Class std::basic_string with safety/checking/debug instrumentation.
size_type find_first_not_of(const basic_string &__str, size_type __pos=0) const noexcept
Find position of a character not in string.
Base class for constructing a safe sequence type that tracks iterators that reference it...
size_type copy(_CharT *__s, size_type __n, size_type __pos=0) const
Copy substring into C string.
void swap(basic_string &__s) noexcept(/*conditional */)
Swap contents with another string.
const _CharT * __check_string(const _CharT *__s, _Integer __n __attribute__((__unused__)), const char *__file __attribute__((__unused__)), unsigned int __line __attribute__((__unused__)), const char *__function __attribute__((__unused__)))
#define __glibcxx_check_erase_range(_First, _Last)
size_type rfind(const basic_string &__str, size_type __pos=npos) const noexcept
Find last position of a string.
size_type find_first_of(const basic_string &__str, size_type __pos=0) const noexcept
Find position of a character of string.
int compare(const basic_string &__str) const
Compare to a string.
size_type find_last_not_of(const basic_string &__str, size_type __pos=npos) const noexcept
Find last position of a character not in string.
Managing sequences of characters and character-like objects.
const _CharT * data() const noexcept
Return const pointer to contents.
basic_string & append(const basic_string &__str)
Append a string to this string.
_T2 second
first is a copy of the first object
basic_string substr(size_type __pos=0, size_type __n=npos) const
Get a substring.
Template class basic_ostream.
void reserve(size_type __res_arg=0)
Attempt to preallocate enough memory for specified number of characters.
is_nothrow_default_constructible
void insert(iterator __p, size_type __n, _CharT __c)
Insert multiple characters.
#define __glibcxx_check_insert(_Position)
_GLIBCXX_NODISCARD bool empty() const noexcept
size_type capacity() const noexcept
_Iterator & base() noexcept
Return the underlying iterator.
size_type size() const noexcept
Returns the number of characters in the string, not including any null-termination.
const _CharT * c_str() const noexcept
Return const pointer to null-terminated contents.
allocator_type get_allocator() const noexcept
Return copy of allocator used to construct this string.
size_type max_size() const noexcept
Returns the size() of the largest possible string.
const_iterator cbegin() const noexcept
#define __glibcxx_check_insert_range(_Position, _First, _Last, _Dist)
Safe class dealing with some allocator dependent operations.
const_reference at(size_type __n) const
Provides access to the data contained in the string.
_Iterator __base(_Iterator __it)
Struct holding two objects of arbitrary type.
void push_back(_CharT __c)
Append a single character.
basic_string & erase(size_type __pos=0, size_type __n=npos)
Remove characters.
basic_string & assign(const basic_string &__str)
Set value to contents of another string.
size_type find_last_of(const basic_string &__str, size_type __pos=npos) const noexcept
Find last position of a character of string.
void pop_back()
Remove the last character.
void resize(size_type __n, _CharT __c)
Resizes the string to the specified number of characters.
GNU debug classes for public use.
#define __glibcxx_check_erase(_Position)
size_type length() const noexcept
Returns the number of characters in the string, not including any null-termination.
static const size_type npos
Value returned by various member functions when they fail.
size_type find(const _CharT *__s, size_type __pos, size_type __n) const noexcept
Find position of a C substring.
void _M_invalidate_all() const
basic_string & replace(size_type __pos, size_type __n, const basic_string &__str)
Replace characters with value from another string.