29 #ifndef _GLIBCXX_DEBUG_STRING 30 #define _GLIBCXX_DEBUG_STRING 1 40 template<
typename _CharT,
typename _Traits = std::
char_traits<_CharT>,
41 typename _Allocator = std::allocator<_CharT> >
44 basic_string<_CharT, _Traits, _Allocator>,
45 _Allocator, _Safe_sequence, bool(_GLIBCXX_USE_CXX11_ABI)>,
55 typedef _Traits traits_type;
56 typedef typename _Traits::char_type value_type;
57 typedef _Allocator allocator_type;
58 typedef typename _Base::size_type size_type;
59 typedef typename _Base::difference_type difference_type;
60 typedef typename _Base::reference reference;
61 typedef typename _Base::const_reference const_reference;
62 typedef typename _Base::pointer pointer;
63 typedef typename _Base::const_pointer const_pointer;
66 typename _Base::iterator, basic_string>
iterator;
76 #if __cplusplus >= 201103L 77 noexcept(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())
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)
401 __glibcxx_check_valid_range(__first, __last);
411 push_back(_CharT __c)
418 assign(
const basic_string& __x)
425 #if __cplusplus >= 201103L 427 assign(basic_string&& __x)
428 noexcept(noexcept(std::declval<_Base&>().assign(std::move(__x))))
437 assign(
const basic_string& __str, size_type __pos, size_type __n)
445 assign(
const _CharT* __s, size_type __n)
447 __glibcxx_check_string_len(__s, __n);
454 assign(
const _CharT* __s)
456 __glibcxx_check_string(__s);
463 assign(size_type __n, _CharT __c)
470 template<
typename _InputIterator>
472 assign(_InputIterator __first, _InputIterator __last)
474 __glibcxx_check_valid_range(__first, __last);
481 #if __cplusplus >= 201103L 492 insert(size_type __pos1,
const basic_string& __str)
500 insert(size_type __pos1,
const basic_string& __str,
501 size_type __pos2, size_type __n)
509 insert(size_type __pos,
const _CharT* __s, size_type __n)
511 __glibcxx_check_string(__s);
518 insert(size_type __pos,
const _CharT* __s)
520 __glibcxx_check_string(__s);
527 insert(size_type __pos, size_type __n, _CharT __c)
535 insert(iterator __p, _CharT __c)
540 return iterator(__res,
this);
544 insert(iterator __p, size_type __n, _CharT __c)
551 template<
typename _InputIterator>
553 insert(iterator __p, _InputIterator __first, _InputIterator __last)
561 #if __cplusplus >= 201103L 572 erase(size_type __pos = 0, size_type __n =
_Base::npos)
580 erase(iterator __position)
585 return iterator(__res,
this);
589 erase(iterator __first, iterator __last)
597 return iterator(__res,
this);
600 #if __cplusplus >= 201103L 604 __glibcxx_check_nonempty();
611 replace(size_type __pos1, size_type __n1,
const basic_string& __str)
619 replace(size_type __pos1, size_type __n1,
const basic_string& __str,
620 size_type __pos2, size_type __n2)
628 replace(size_type __pos, size_type __n1,
const _CharT* __s,
631 __glibcxx_check_string_len(__s, __n2);
638 replace(size_type __pos, size_type __n1,
const _CharT* __s)
640 __glibcxx_check_string(__s);
647 replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
655 replace(iterator __i1, iterator __i2,
const basic_string& __str)
664 replace(iterator __i1, iterator __i2,
const _CharT* __s, size_type __n)
667 __glibcxx_check_string_len(__s, __n);
674 replace(iterator __i1, iterator __i2,
const _CharT* __s)
677 __glibcxx_check_string(__s);
684 replace(iterator __i1, iterator __i2, size_type __n, _CharT __c)
692 template<
typename _InputIterator>
694 replace(iterator __i1, iterator __i2,
695 _InputIterator __j1, _InputIterator __j2)
698 __glibcxx_check_valid_range(__j1, __j2);
704 #if __cplusplus >= 201103L 705 basic_string& replace(iterator __i1, iterator __i2,
716 copy(_CharT* __s, size_type __n, size_type __pos = 0)
const 718 __glibcxx_check_string_len(__s, __n);
723 swap(basic_string& __x)
724 #if _GLIBCXX_USE_CXX11_ABI 734 c_str()
const _GLIBCXX_NOEXCEPT
742 data()
const _GLIBCXX_NOEXCEPT
752 find(
const basic_string& __str, size_type __pos = 0)
const 757 find(
const _CharT* __s, size_type __pos, size_type __n)
const 759 __glibcxx_check_string(__s);
764 find(
const _CharT* __s, size_type __pos = 0)
const 766 __glibcxx_check_string(__s);
771 find(_CharT __c, size_type __pos = 0)
const _GLIBCXX_NOEXCEPT
775 rfind(
const basic_string& __str, size_type __pos =
_Base::npos)
const 780 rfind(
const _CharT* __s, size_type __pos, size_type __n)
const 782 __glibcxx_check_string_len(__s, __n);
787 rfind(
const _CharT* __s, size_type __pos =
_Base::npos)
const 789 __glibcxx_check_string(__s);
794 rfind(_CharT __c, size_type __pos =
_Base::npos)
const _GLIBCXX_NOEXCEPT
798 find_first_of(
const basic_string& __str, size_type __pos = 0)
const 803 find_first_of(
const _CharT* __s, size_type __pos, size_type __n)
const 805 __glibcxx_check_string(__s);
810 find_first_of(
const _CharT* __s, size_type __pos = 0)
const 812 __glibcxx_check_string(__s);
817 find_first_of(_CharT __c, size_type __pos = 0)
const _GLIBCXX_NOEXCEPT
821 find_last_of(
const basic_string& __str,
822 size_type __pos =
_Base::npos)
const _GLIBCXX_NOEXCEPT
826 find_last_of(
const _CharT* __s, size_type __pos, size_type __n)
const 828 __glibcxx_check_string(__s);
833 find_last_of(
const _CharT* __s, size_type __pos =
_Base::npos)
const 835 __glibcxx_check_string(__s);
840 find_last_of(_CharT __c, size_type __pos =
_Base::npos)
const 845 find_first_not_of(
const basic_string& __str, size_type __pos = 0)
const 850 find_first_not_of(
const _CharT* __s, size_type __pos, size_type __n)
const 852 __glibcxx_check_string_len(__s, __n);
857 find_first_not_of(
const _CharT* __s, size_type __pos = 0)
const 859 __glibcxx_check_string(__s);
864 find_first_not_of(_CharT __c, size_type __pos = 0)
const _GLIBCXX_NOEXCEPT
868 find_last_not_of(
const basic_string& __str,
874 find_last_not_of(
const _CharT* __s, size_type __pos, size_type __n)
const 876 __glibcxx_check_string(__s);
881 find_last_not_of(
const _CharT* __s, size_type __pos =
_Base::npos)
const 883 __glibcxx_check_string(__s);
888 find_last_not_of(_CharT __c, size_type __pos =
_Base::npos)
const 893 substr(size_type __pos = 0, size_type __n =
_Base::npos)
const 897 compare(
const basic_string& __str)
const 901 compare(size_type __pos1, size_type __n1,
902 const basic_string& __str)
const 906 compare(size_type __pos1, size_type __n1,
const basic_string& __str,
907 size_type __pos2, size_type __n2)
const 911 compare(
const _CharT* __s)
const 913 __glibcxx_check_string(__s);
920 compare(size_type __pos1, size_type __n1,
const _CharT* __s)
const 922 __glibcxx_check_string(__s);
929 compare(size_type __pos1, size_type __n1,
const _CharT* __s,
930 size_type __n2)
const 932 __glibcxx_check_string_len(__s, __n2);
937 _M_base() _GLIBCXX_NOEXCEPT {
return *
this; }
940 _M_base()
const _GLIBCXX_NOEXCEPT {
return *
this; }
942 using _Safe::_M_invalidate_all;
945 template<
typename _CharT,
typename _Traits,
typename _Allocator>
951 template<
typename _CharT,
typename _Traits,
typename _Allocator>
953 operator+(
const _CharT* __lhs,
956 __glibcxx_check_string(__lhs);
960 template<
typename _CharT,
typename _Traits,
typename _Allocator>
962 operator+(_CharT __lhs,
966 template<
typename _CharT,
typename _Traits,
typename _Allocator>
971 __glibcxx_check_string(__rhs);
975 template<
typename _CharT,
typename _Traits,
typename _Allocator>
981 template<
typename _CharT,
typename _Traits,
typename _Allocator>
985 {
return __lhs._M_base() == __rhs._M_base(); }
987 template<
typename _CharT,
typename _Traits,
typename _Allocator>
989 operator==(
const _CharT* __lhs,
992 __glibcxx_check_string(__lhs);
993 return __lhs == __rhs._M_base();
996 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1001 __glibcxx_check_string(__rhs);
1002 return __lhs._M_base() == __rhs;
1005 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1009 {
return __lhs._M_base() != __rhs._M_base(); }
1011 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1013 operator!=(
const _CharT* __lhs,
1016 __glibcxx_check_string(__lhs);
1017 return __lhs != __rhs._M_base();
1020 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1023 const _CharT* __rhs)
1025 __glibcxx_check_string(__rhs);
1026 return __lhs._M_base() != __rhs;
1029 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1031 operator<(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1033 {
return __lhs._M_base() < __rhs._M_base(); }
1035 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1037 operator<(
const _CharT* __lhs,
1040 __glibcxx_check_string(__lhs);
1041 return __lhs < __rhs._M_base();
1044 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1046 operator<(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1047 const _CharT* __rhs)
1049 __glibcxx_check_string(__rhs);
1050 return __lhs._M_base() < __rhs;
1053 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1055 operator<=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1057 {
return __lhs._M_base() <= __rhs._M_base(); }
1059 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1061 operator<=(
const _CharT* __lhs,
1064 __glibcxx_check_string(__lhs);
1065 return __lhs <= __rhs._M_base();
1068 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1070 operator<=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1071 const _CharT* __rhs)
1073 __glibcxx_check_string(__rhs);
1074 return __lhs._M_base() <= __rhs;
1077 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1081 {
return __lhs._M_base() >= __rhs._M_base(); }
1083 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1085 operator>=(
const _CharT* __lhs,
1088 __glibcxx_check_string(__lhs);
1089 return __lhs >= __rhs._M_base();
1092 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1095 const _CharT* __rhs)
1097 __glibcxx_check_string(__rhs);
1098 return __lhs._M_base() >= __rhs;
1101 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1105 {
return __lhs._M_base() > __rhs._M_base(); }
1107 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1109 operator>(
const _CharT* __lhs,
1112 __glibcxx_check_string(__lhs);
1113 return __lhs > __rhs._M_base();
1116 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1119 const _CharT* __rhs)
1121 __glibcxx_check_string(__rhs);
1122 return __lhs._M_base() > __rhs;
1126 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1130 { __lhs.swap(__rhs); }
1132 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1134 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1136 {
return __os << __str._M_base(); }
1138 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1148 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1160 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1173 #ifdef _GLIBCXX_USE_WCHAR_T 1177 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1178 struct _Insert_range_from_self_is_safe<
1179 __gnu_debug::
basic_string<_CharT, _Traits, _Allocator> >
1180 {
enum { __value = 1 }; };
size_type rfind(const basic_string &__str, size_type __pos=npos) const noexcept
Find last position of a string.
size_type find_first_not_of(const basic_string &__str, size_type __pos=0) const noexcept
Find position of a character not in string.
basic_string & erase(size_type __pos=0, size_type __n=npos)
Remove characters.
static const size_type npos
Value returned by various member functions when they fail.
bool empty() const noexcept
Template class basic_ostream.
size_type size() const noexcept
Returns the number of characters in the string, not including any null-termination.
_Iterator & base() noexcept
Return the underlying iterator.
#define __glibcxx_check_insert_range(_Position, _First, _Last)
GNU debug classes for public use.
basic_string & append(const basic_string &__str)
Append a string to this string.
Class std::basic_string with safety/checking/debug instrumentation.
const _CharT * __check_string(const _CharT *__s, const _Integer &__n __attribute__((__unused__)))
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.
#define __glibcxx_check_erase(_Position)
size_type length() const noexcept
Returns the number of characters in the string, not including any null-termination.
#define __glibcxx_check_erase_range(_First, _Last)
void pop_back()
Remove the last character.
size_type find(const _CharT *__s, size_type __pos, size_type __n) const
Find position of a C substring.
_Siter_base< _Iterator >::iterator_type __base(_Iterator __it)
size_type find_first_of(const basic_string &__str, size_type __pos=0) const noexcept
Find position of a character of string.
Safe class dealing with some allocator dependent operations.
const _CharT * data() const noexcept
Return const pointer to contents.
void _M_invalidate_all() const
basic_string substr(size_type __pos=0, size_type __n=npos) const
Get a substring.
Base class for constructing a safe sequence type that tracks iterators that reference it...
size_type max_size() const noexcept
Returns the size() of the largest possible string.
Template class basic_istream.
void push_back(_CharT __c)
Append a single character.
const_reference at(size_type __n) const
Provides access to the data contained in the string.
void resize(size_type __n, _CharT __c)
Resizes the string to the specified number of characters.
size_type capacity() const noexcept
int compare(const basic_string &__str) const
Compare to a string.
void reserve(size_type __res_arg=0)
Attempt to preallocate enough memory for specified number of characters.
#define __glibcxx_check_insert(_Position)
void insert(iterator __p, size_type __n, _CharT __c)
Insert multiple characters.
size_type copy(_CharT *__s, size_type __n, size_type __pos=0) const
Copy substring into C 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.
void swap(basic_string &__s)
Swap contents with another string.
basic_string & replace(size_type __pos, size_type __n, const basic_string &__str)
Replace characters with value from another string.
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.