29 #ifndef _GLIBCXX_DEBUG_STRING 30 #define _GLIBCXX_DEBUG_STRING 1 32 #pragma GCC system_header 42 template<
typename _CharT,
typename _Traits = std::
char_traits<_CharT>,
43 typename _Allocator = std::allocator<_CharT> >
46 basic_string<_CharT, _Traits, _Allocator>,
47 _Allocator, _Safe_sequence, bool(_GLIBCXX_USE_CXX11_ABI)>,
57 typedef _Traits traits_type;
58 typedef typename _Traits::char_type value_type;
59 typedef _Allocator allocator_type;
60 typedef typename _Base::size_type size_type;
61 typedef typename _Base::difference_type difference_type;
62 typedef typename _Base::reference reference;
63 typedef typename _Base::const_reference const_reference;
64 typedef typename _Base::pointer pointer;
65 typedef typename _Base::const_pointer const_pointer;
68 typename _Base::iterator, basic_string>
iterator;
78 _GLIBCXX_NOEXCEPT_IF(std::is_nothrow_default_constructible<_Base>::value)
83 basic_string(
const _Allocator& __a) _GLIBCXX_NOEXCEPT
86 #if __cplusplus < 201103L 87 basic_string(
const basic_string& __str)
92 basic_string(
const basic_string&) =
default;
93 basic_string(basic_string&&) =
default;
96 const _Allocator& __a = _Allocator())
100 #if _GLIBCXX_USE_CXX11_ABI 101 basic_string(
const basic_string& __s,
const _Allocator& __a)
102 : _Base(__s, __a) { }
104 basic_string(basic_string&& __s,
const _Allocator& __a)
105 : _Base(std::move(__s), __a) { }
108 ~basic_string() =
default;
111 basic_string(_Base&& __base) noexcept
112 : _Base(std::move(__base)) { }
116 basic_string(
const _Base& __base)
121 basic_string(
const basic_string& __str, size_type __pos,
123 const _Allocator& __a = _Allocator())
124 : _Base(__str, __pos, __n, __a) { }
126 basic_string(
const _CharT* __s, size_type __n,
127 const _Allocator& __a = _Allocator())
130 basic_string(
const _CharT* __s,
const _Allocator& __a = _Allocator())
132 { this->assign(__s); }
134 basic_string(size_type __n, _CharT __c,
135 const _Allocator& __a = _Allocator())
136 : _Base(__n, __c, __a) { }
138 template<
typename _InputIterator>
139 basic_string(_InputIterator __begin, _InputIterator __end,
140 const _Allocator& __a = _Allocator())
141 : _Base(__gnu_debug::__base(__gnu_debug::__check_valid_range(__begin,
143 __gnu_debug::__base(__end), __a) { }
145 #if __cplusplus < 201103L 147 operator=(
const basic_string& __str)
149 this->_M_safe() = __str;
155 operator=(
const basic_string&) =
default;
158 operator=(basic_string&&) =
default;
162 operator=(
const _CharT* __s)
164 __glibcxx_check_string(__s);
171 operator=(_CharT __c)
178 #if __cplusplus >= 201103L 194 begin()
const _GLIBCXX_NOEXCEPT
202 end()
const _GLIBCXX_NOEXCEPT
203 {
return const_iterator(
_Base::end(),
this); }
207 {
return reverse_iterator(end()); }
209 const_reverse_iterator
210 rbegin()
const _GLIBCXX_NOEXCEPT
211 {
return const_reverse_iterator(end()); }
215 {
return reverse_iterator(begin()); }
217 const_reverse_iterator
218 rend()
const _GLIBCXX_NOEXCEPT
219 {
return const_reverse_iterator(begin()); }
221 #if __cplusplus >= 201103L 223 cbegin()
const noexcept
227 cend()
const noexcept
228 {
return const_iterator(
_Base::end(),
this); }
230 const_reverse_iterator
231 crbegin()
const noexcept
232 {
return const_reverse_iterator(end()); }
234 const_reverse_iterator
235 crend()
const noexcept
236 {
return const_reverse_iterator(begin()); }
245 resize(size_type __n, _CharT __c)
252 resize(size_type __n)
253 { this->resize(__n, _CharT()); }
255 #if __cplusplus >= 201103L 257 shrink_to_fit() noexcept
286 operator[](size_type __pos)
const _GLIBCXX_NOEXCEPT
288 _GLIBCXX_DEBUG_VERIFY(__pos <= this->
size(),
289 _M_message(__gnu_debug::__msg_subscript_oob)
290 ._M_sequence(*
this,
"this")
291 ._M_integer(__pos,
"__pos")
292 ._M_integer(this->
size(),
"size"));
293 return _M_base()[__pos];
297 operator[](size_type __pos)
299 #if __cplusplus < 201103L && defined(_GLIBCXX_DEBUG_PEDANTIC) 300 __glibcxx_check_subscript(__pos);
303 _GLIBCXX_DEBUG_VERIFY(__pos <= this->
size(),
304 _M_message(__gnu_debug::__msg_subscript_oob)
305 ._M_sequence(*
this,
"this")
306 ._M_integer(__pos,
"__pos")
307 ._M_integer(this->
size(),
"size"));
309 return _M_base()[__pos];
314 #if __cplusplus >= 201103L 321 operator+=(
const basic_string& __str)
329 operator+=(
const _CharT* __s)
331 __glibcxx_check_string(__s);
338 operator+=(_CharT __c)
345 #if __cplusplus >= 201103L 356 append(
const basic_string& __str)
364 append(
const basic_string& __str, size_type __pos, size_type __n)
372 append(
const _CharT* __s, size_type __n)
374 __glibcxx_check_string_len(__s, __n);
381 append(
const _CharT* __s)
383 __glibcxx_check_string(__s);
390 append(size_type __n, _CharT __c)
397 template<
typename _InputIterator>
399 append(_InputIterator __first, _InputIterator __last)
402 __glibcxx_check_valid_range2(__first, __last, __dist);
404 if (__dist.
second >= __dp_sign)
406 __gnu_debug::__unsafe(__last));
417 push_back(_CharT __c)
424 assign(
const basic_string& __x)
431 #if __cplusplus >= 201103L 433 assign(basic_string&& __x)
434 noexcept(noexcept(std::declval<_Base&>().assign(std::move(__x))))
443 assign(
const basic_string& __str, size_type __pos, size_type __n)
451 assign(
const _CharT* __s, size_type __n)
453 __glibcxx_check_string_len(__s, __n);
460 assign(
const _CharT* __s)
462 __glibcxx_check_string(__s);
469 assign(size_type __n, _CharT __c)
476 template<
typename _InputIterator>
478 assign(_InputIterator __first, _InputIterator __last)
481 __glibcxx_check_valid_range2(__first, __last, __dist);
483 if (__dist.
second >= __dp_sign)
485 __gnu_debug::__unsafe(__last));
493 #if __cplusplus >= 201103L 504 insert(size_type __pos1,
const basic_string& __str)
512 insert(size_type __pos1,
const basic_string& __str,
513 size_type __pos2, size_type __n)
521 insert(size_type __pos,
const _CharT* __s, size_type __n)
523 __glibcxx_check_string(__s);
530 insert(size_type __pos,
const _CharT* __s)
532 __glibcxx_check_string(__s);
539 insert(size_type __pos, size_type __n, _CharT __c)
547 insert(iterator __p, _CharT __c)
552 return iterator(__res,
this);
556 insert(iterator __p, size_type __n, _CharT __c)
563 template<
typename _InputIterator>
565 insert(iterator __p, _InputIterator __first, _InputIterator __last)
568 __glibcxx_check_insert_range2(__p, __first, __last, __dist);
570 if (__dist.
second >= __dp_sign)
572 __gnu_debug::__unsafe(__last));
579 #if __cplusplus >= 201103L 590 erase(size_type __pos = 0, size_type __n =
_Base::npos)
598 erase(iterator __position)
603 return iterator(__res,
this);
607 erase(iterator __first, iterator __last)
615 return iterator(__res,
this);
618 #if __cplusplus >= 201103L 622 __glibcxx_check_nonempty();
629 replace(size_type __pos1, size_type __n1,
const basic_string& __str)
637 replace(size_type __pos1, size_type __n1,
const basic_string& __str,
638 size_type __pos2, size_type __n2)
646 replace(size_type __pos, size_type __n1,
const _CharT* __s,
649 __glibcxx_check_string_len(__s, __n2);
656 replace(size_type __pos, size_type __n1,
const _CharT* __s)
658 __glibcxx_check_string(__s);
665 replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
673 replace(iterator __i1, iterator __i2,
const basic_string& __str)
682 replace(iterator __i1, iterator __i2,
const _CharT* __s, size_type __n)
685 __glibcxx_check_string_len(__s, __n);
692 replace(iterator __i1, iterator __i2,
const _CharT* __s)
695 __glibcxx_check_string(__s);
702 replace(iterator __i1, iterator __i2, size_type __n, _CharT __c)
710 template<
typename _InputIterator>
712 replace(iterator __i1, iterator __i2,
713 _InputIterator __j1, _InputIterator __j2)
718 __glibcxx_check_valid_range2(__j1, __j2, __dist);
720 if (__dist.
second >= __dp_sign)
722 __gnu_debug::__unsafe(__j1),
723 __gnu_debug::__unsafe(__j2));
731 #if __cplusplus >= 201103L 732 basic_string& replace(iterator __i1, iterator __i2,
743 copy(_CharT* __s, size_type __n, size_type __pos = 0)
const 745 __glibcxx_check_string_len(__s, __n);
750 swap(basic_string& __x)
751 _GLIBCXX_NOEXCEPT_IF(std::__is_nothrow_swappable<_Base>::value)
759 c_str()
const _GLIBCXX_NOEXCEPT
767 data()
const _GLIBCXX_NOEXCEPT
777 find(
const basic_string& __str, size_type __pos = 0)
const 782 find(
const _CharT* __s, size_type __pos, size_type __n)
const 784 __glibcxx_check_string(__s);
789 find(
const _CharT* __s, size_type __pos = 0)
const 791 __glibcxx_check_string(__s);
796 find(_CharT __c, size_type __pos = 0)
const _GLIBCXX_NOEXCEPT
800 rfind(
const basic_string& __str, size_type __pos =
_Base::npos)
const 805 rfind(
const _CharT* __s, size_type __pos, size_type __n)
const 807 __glibcxx_check_string_len(__s, __n);
812 rfind(
const _CharT* __s, size_type __pos =
_Base::npos)
const 814 __glibcxx_check_string(__s);
819 rfind(_CharT __c, size_type __pos =
_Base::npos)
const _GLIBCXX_NOEXCEPT
823 find_first_of(
const basic_string& __str, size_type __pos = 0)
const 828 find_first_of(
const _CharT* __s, size_type __pos, size_type __n)
const 830 __glibcxx_check_string(__s);
835 find_first_of(
const _CharT* __s, size_type __pos = 0)
const 837 __glibcxx_check_string(__s);
842 find_first_of(_CharT __c, size_type __pos = 0)
const _GLIBCXX_NOEXCEPT
846 find_last_of(
const basic_string& __str,
847 size_type __pos =
_Base::npos)
const _GLIBCXX_NOEXCEPT
851 find_last_of(
const _CharT* __s, size_type __pos, size_type __n)
const 853 __glibcxx_check_string(__s);
858 find_last_of(
const _CharT* __s, size_type __pos =
_Base::npos)
const 860 __glibcxx_check_string(__s);
865 find_last_of(_CharT __c, size_type __pos =
_Base::npos)
const 870 find_first_not_of(
const basic_string& __str, size_type __pos = 0)
const 875 find_first_not_of(
const _CharT* __s, size_type __pos, size_type __n)
const 877 __glibcxx_check_string_len(__s, __n);
882 find_first_not_of(
const _CharT* __s, size_type __pos = 0)
const 884 __glibcxx_check_string(__s);
889 find_first_not_of(_CharT __c, size_type __pos = 0)
const _GLIBCXX_NOEXCEPT
893 find_last_not_of(
const basic_string& __str,
899 find_last_not_of(
const _CharT* __s, size_type __pos, size_type __n)
const 901 __glibcxx_check_string(__s);
906 find_last_not_of(
const _CharT* __s, size_type __pos =
_Base::npos)
const 908 __glibcxx_check_string(__s);
913 find_last_not_of(_CharT __c, size_type __pos =
_Base::npos)
const 918 substr(size_type __pos = 0, size_type __n =
_Base::npos)
const 922 compare(
const basic_string& __str)
const 926 compare(size_type __pos1, size_type __n1,
927 const basic_string& __str)
const 931 compare(size_type __pos1, size_type __n1,
const basic_string& __str,
932 size_type __pos2, size_type __n2)
const 936 compare(
const _CharT* __s)
const 938 __glibcxx_check_string(__s);
945 compare(size_type __pos1, size_type __n1,
const _CharT* __s)
const 947 __glibcxx_check_string(__s);
954 compare(size_type __pos1, size_type __n1,
const _CharT* __s,
955 size_type __n2)
const 957 __glibcxx_check_string_len(__s, __n2);
962 _M_base() _GLIBCXX_NOEXCEPT {
return *
this; }
965 _M_base()
const _GLIBCXX_NOEXCEPT {
return *
this; }
967 using _Safe::_M_invalidate_all;
970 template<
typename _CharT,
typename _Traits,
typename _Allocator>
976 template<
typename _CharT,
typename _Traits,
typename _Allocator>
978 operator+(
const _CharT* __lhs,
981 __glibcxx_check_string(__lhs);
985 template<
typename _CharT,
typename _Traits,
typename _Allocator>
987 operator+(_CharT __lhs,
991 template<
typename _CharT,
typename _Traits,
typename _Allocator>
996 __glibcxx_check_string(__rhs);
1000 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1006 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1010 {
return __lhs._M_base() == __rhs._M_base(); }
1012 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1014 operator==(
const _CharT* __lhs,
1017 __glibcxx_check_string(__lhs);
1018 return __lhs == __rhs._M_base();
1021 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1024 const _CharT* __rhs)
1026 __glibcxx_check_string(__rhs);
1027 return __lhs._M_base() == __rhs;
1030 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1034 {
return __lhs._M_base() != __rhs._M_base(); }
1036 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1038 operator!=(
const _CharT* __lhs,
1041 __glibcxx_check_string(__lhs);
1042 return __lhs != __rhs._M_base();
1045 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1048 const _CharT* __rhs)
1050 __glibcxx_check_string(__rhs);
1051 return __lhs._M_base() != __rhs;
1054 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1056 operator<(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1058 {
return __lhs._M_base() < __rhs._M_base(); }
1060 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1062 operator<(
const _CharT* __lhs,
1065 __glibcxx_check_string(__lhs);
1066 return __lhs < __rhs._M_base();
1069 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1071 operator<(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1072 const _CharT* __rhs)
1074 __glibcxx_check_string(__rhs);
1075 return __lhs._M_base() < __rhs;
1078 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1080 operator<=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1082 {
return __lhs._M_base() <= __rhs._M_base(); }
1084 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1086 operator<=(
const _CharT* __lhs,
1089 __glibcxx_check_string(__lhs);
1090 return __lhs <= __rhs._M_base();
1093 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1095 operator<=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1096 const _CharT* __rhs)
1098 __glibcxx_check_string(__rhs);
1099 return __lhs._M_base() <= __rhs;
1102 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1106 {
return __lhs._M_base() >= __rhs._M_base(); }
1108 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1110 operator>=(
const _CharT* __lhs,
1113 __glibcxx_check_string(__lhs);
1114 return __lhs >= __rhs._M_base();
1117 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1120 const _CharT* __rhs)
1122 __glibcxx_check_string(__rhs);
1123 return __lhs._M_base() >= __rhs;
1126 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1130 {
return __lhs._M_base() > __rhs._M_base(); }
1132 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1134 operator>(
const _CharT* __lhs,
1137 __glibcxx_check_string(__lhs);
1138 return __lhs > __rhs._M_base();
1141 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1144 const _CharT* __rhs)
1146 __glibcxx_check_string(__rhs);
1147 return __lhs._M_base() > __rhs;
1151 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1155 { __lhs.swap(__rhs); }
1157 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1159 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1161 {
return __os << __str._M_base(); }
1163 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1173 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1185 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1198 #ifdef _GLIBCXX_USE_WCHAR_T 1202 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1203 struct _Insert_range_from_self_is_safe<
1204 __gnu_debug::
basic_string<_CharT, _Traits, _Allocator> >
1205 {
enum { __value = 1 }; };
Managing sequences of characters and character-like objects.
size_type rfind(const basic_string &__str, size_type __pos=npos) const noexcept
Find last position of a string.
void insert(iterator __p, size_type __n, _CharT __c)
Insert multiple characters.
#define __glibcxx_check_erase_range(_First, _Last)
basic_string & replace(size_type __pos, size_type __n, const basic_string &__str)
Replace characters with value from another string.
size_type length() const noexcept
Returns the number of characters in the string, not including any null-termination.
void swap(basic_string &__s)
Swap contents with another string.
Template class basic_ostream.
const _CharT * c_str() const noexcept
Return const pointer to null-terminated contents.
size_type size() const noexcept
Returns the number of characters in the string, not including any null-termination.
bool empty() const noexcept
Base class for constructing a safe sequence type that tracks iterators that reference it...
static const size_type npos
Value returned by various member functions when they fail.
basic_string substr(size_type __pos=0, size_type __n=npos) const
Get a substring.
size_type copy(_CharT *__s, size_type __n, size_type __pos=0) const
Copy substring into C string.
basic_string & erase(size_type __pos=0, size_type __n=npos)
Remove characters.
void reserve(size_type __res_arg=0)
Attempt to preallocate enough memory for specified number of characters.
basic_string & append(const basic_string &__str)
Append a string to this string.
_T2 second
first is a copy of the first object
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.
_Iterator & base() noexcept
Return the underlying iterator.
void resize(size_type __n, _CharT __c)
Resizes the string to the specified number of characters.
Safe class dealing with some allocator dependent operations.
basic_string & assign(const basic_string &__str)
Set value to contents of another string.
#define __glibcxx_check_insert(_Position)
int compare(const basic_string &__str) const
Compare to a string.
Class std::basic_string with safety/checking/debug instrumentation.
Struct holding two objects of arbitrary type.
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.
void _M_invalidate_all() const
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.
const_reference at(size_type __n) const
Provides access to the data contained in the string.
const _CharT * __check_string(const _CharT *__s, const _Integer &__n __attribute__((__unused__)))
size_type find_first_of(const basic_string &__str, size_type __pos=0) const noexcept
Find position of a character of string.
size_type find(const _CharT *__s, size_type __pos, size_type __n) const noexcept
Find position of a C substring.
GNU debug classes for public use.
const _CharT * data() const noexcept
Return const pointer to contents.
Template class basic_istream.
size_type find_first_not_of(const basic_string &__str, size_type __pos=0) const noexcept
Find position of a character not in string.
void push_back(_CharT __c)
Append a single character.
size_type capacity() const noexcept
#define __glibcxx_check_erase(_Position)