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;
76 _GLIBCXX_NOEXCEPT_IF(std::is_nothrow_default_constructible<_Base>::value)
84 #if __cplusplus < 201103L
94 const _Allocator& __a = _Allocator())
98 #if _GLIBCXX_USE_CXX11_ABI
100 :
_Base(__s, __a) { }
103 :
_Base(std::move(__s), __a) { }
110 :
_Base(std::move(__base)) { }
121 const _Allocator& __a = _Allocator())
122 :
_Base(__str, __pos, __n, __a) { }
125 const _Allocator& __a = _Allocator())
128 basic_string(
const _CharT* __s,
const _Allocator& __a = _Allocator())
130 { this->assign(__s); }
133 const _Allocator& __a = _Allocator())
134 :
_Base(__n, __c, __a) { }
136 template<
typename _InputIterator>
137 basic_string(_InputIterator __begin, _InputIterator __end,
138 const _Allocator& __a = _Allocator())
139 :
_Base(__gnu_debug::__base(__gnu_debug::__check_valid_range(__begin,
141 __gnu_debug::__base(__end), __a) { }
143 #if __cplusplus < 201103L
147 this->_M_safe() = __str;
160 operator=(
const _CharT* __s)
162 __glibcxx_check_string(__s);
169 operator=(_CharT __c)
176 #if __cplusplus >= 201103L
192 begin()
const _GLIBCXX_NOEXCEPT
200 end()
const _GLIBCXX_NOEXCEPT
208 rbegin()
const _GLIBCXX_NOEXCEPT
216 rend()
const _GLIBCXX_NOEXCEPT
219 #if __cplusplus >= 201103L
221 cbegin()
const noexcept
225 cend()
const noexcept
229 crbegin()
const noexcept
233 crend()
const noexcept
243 resize(size_type __n, _CharT __c)
250 resize(size_type __n)
251 { this->resize(__n, _CharT()); }
253 #if __cplusplus >= 201103L
255 shrink_to_fit() noexcept
284 operator[](size_type __pos)
const _GLIBCXX_NOEXCEPT
286 _GLIBCXX_DEBUG_VERIFY(__pos <= this->
size(),
287 _M_message(__gnu_debug::__msg_subscript_oob)
288 ._M_sequence(*
this,
"this")
289 ._M_integer(__pos,
"__pos")
290 ._M_integer(this->
size(),
"size"));
291 return _M_base()[__pos];
295 operator[](size_type __pos)
297 #if __cplusplus < 201103L && defined(_GLIBCXX_DEBUG_PEDANTIC)
298 __glibcxx_check_subscript(__pos);
301 _GLIBCXX_DEBUG_VERIFY(__pos <= this->
size(),
302 _M_message(__gnu_debug::__msg_subscript_oob)
303 ._M_sequence(*
this,
"this")
304 ._M_integer(__pos,
"__pos")
305 ._M_integer(this->
size(),
"size"));
307 return _M_base()[__pos];
312 #if __cplusplus >= 201103L
327 operator+=(
const _CharT* __s)
329 __glibcxx_check_string(__s);
336 operator+=(_CharT __c)
343 #if __cplusplus >= 201103L
362 append(
const basic_string& __str, size_type __pos, size_type __n)
370 append(
const _CharT* __s, size_type __n)
372 __glibcxx_check_string_len(__s, __n);
379 append(
const _CharT* __s)
381 __glibcxx_check_string(__s);
388 append(size_type __n, _CharT __c)
395 template<
typename _InputIterator>
397 append(_InputIterator __first, _InputIterator __last)
400 __glibcxx_check_valid_range2(__first, __last, __dist);
402 if (__dist.
second >= __dp_sign)
404 __gnu_debug::__unsafe(__last));
415 push_back(_CharT __c)
429 #if __cplusplus >= 201103L
432 noexcept(noexcept(std::declval<_Base&>().assign(std::move(__x))))
441 assign(
const basic_string& __str, size_type __pos, size_type __n)
449 assign(
const _CharT* __s, size_type __n)
451 __glibcxx_check_string_len(__s, __n);
458 assign(
const _CharT* __s)
460 __glibcxx_check_string(__s);
467 assign(size_type __n, _CharT __c)
474 template<
typename _InputIterator>
476 assign(_InputIterator __first, _InputIterator __last)
479 __glibcxx_check_valid_range2(__first, __last, __dist);
481 if (__dist.
second >= __dp_sign)
483 __gnu_debug::__unsafe(__last));
491 #if __cplusplus >= 201103L
511 size_type __pos2, size_type __n)
519 insert(size_type __pos,
const _CharT* __s, size_type __n)
521 __glibcxx_check_string(__s);
528 insert(size_type __pos,
const _CharT* __s)
530 __glibcxx_check_string(__s);
537 insert(size_type __pos, size_type __n, _CharT __c)
554 insert(
iterator __p, size_type __n, _CharT __c)
561 template<
typename _InputIterator>
563 insert(
iterator __p, _InputIterator __first, _InputIterator __last)
568 if (__dist.
second >= __dp_sign)
570 __gnu_debug::__unsafe(__last));
577 #if __cplusplus >= 201103L
588 erase(size_type __pos = 0, size_type __n =
_Base::npos)
616 #if __cplusplus >= 201103L
620 __glibcxx_check_nonempty();
627 replace(size_type __pos1, size_type __n1,
const basic_string& __str)
635 replace(size_type __pos1, size_type __n1,
const basic_string& __str,
636 size_type __pos2, size_type __n2)
644 replace(size_type __pos, size_type __n1,
const _CharT* __s,
647 __glibcxx_check_string_len(__s, __n2);
654 replace(size_type __pos, size_type __n1,
const _CharT* __s)
656 __glibcxx_check_string(__s);
663 replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
683 __glibcxx_check_string_len(__s, __n);
693 __glibcxx_check_string(__s);
708 template<
typename _InputIterator>
711 _InputIterator __j1, _InputIterator __j2)
716 __glibcxx_check_valid_range2(__j1, __j2, __dist);
718 if (__dist.
second >= __dp_sign)
720 __gnu_debug::__unsafe(__j1),
721 __gnu_debug::__unsafe(__j2));
729 #if __cplusplus >= 201103L
741 copy(_CharT* __s, size_type __n, size_type __pos = 0)
const
743 __glibcxx_check_string_len(__s, __n);
749 _GLIBCXX_NOEXCEPT_IF(std::__is_nothrow_swappable<_Base>::value)
757 c_str()
const _GLIBCXX_NOEXCEPT
765 data()
const _GLIBCXX_NOEXCEPT
775 find(
const basic_string& __str, size_type __pos = 0)
const
780 find(
const _CharT* __s, size_type __pos, size_type __n)
const
782 __glibcxx_check_string(__s);
787 find(
const _CharT* __s, size_type __pos = 0)
const
789 __glibcxx_check_string(__s);
794 find(_CharT __c, size_type __pos = 0)
const _GLIBCXX_NOEXCEPT
803 rfind(
const _CharT* __s, size_type __pos, size_type __n)
const
805 __glibcxx_check_string_len(__s, __n);
810 rfind(
const _CharT* __s, size_type __pos =
_Base::npos)
const
812 __glibcxx_check_string(__s);
817 rfind(_CharT __c, size_type __pos =
_Base::npos)
const _GLIBCXX_NOEXCEPT
821 find_first_of(
const basic_string& __str, size_type __pos = 0)
const
826 find_first_of(
const _CharT* __s, size_type __pos, size_type __n)
const
828 __glibcxx_check_string(__s);
833 find_first_of(
const _CharT* __s, size_type __pos = 0)
const
835 __glibcxx_check_string(__s);
840 find_first_of(_CharT __c, size_type __pos = 0)
const _GLIBCXX_NOEXCEPT
845 size_type __pos =
_Base::npos)
const _GLIBCXX_NOEXCEPT
849 find_last_of(
const _CharT* __s, size_type __pos, size_type __n)
const
851 __glibcxx_check_string(__s);
856 find_last_of(
const _CharT* __s, size_type __pos =
_Base::npos)
const
858 __glibcxx_check_string(__s);
863 find_last_of(_CharT __c, size_type __pos =
_Base::npos)
const
868 find_first_not_of(
const basic_string& __str, size_type __pos = 0)
const
873 find_first_not_of(
const _CharT* __s, size_type __pos, size_type __n)
const
875 __glibcxx_check_string_len(__s, __n);
880 find_first_not_of(
const _CharT* __s, size_type __pos = 0)
const
882 __glibcxx_check_string(__s);
887 find_first_not_of(_CharT __c, size_type __pos = 0)
const _GLIBCXX_NOEXCEPT
897 find_last_not_of(
const _CharT* __s, size_type __pos, size_type __n)
const
899 __glibcxx_check_string(__s);
904 find_last_not_of(
const _CharT* __s, size_type __pos =
_Base::npos)
const
906 __glibcxx_check_string(__s);
911 find_last_not_of(_CharT __c, size_type __pos =
_Base::npos)
const
916 substr(size_type __pos = 0, size_type __n =
_Base::npos)
const
924 compare(size_type __pos1, size_type __n1,
929 compare(size_type __pos1, size_type __n1,
const basic_string& __str,
930 size_type __pos2, size_type __n2)
const
934 compare(
const _CharT* __s)
const
936 __glibcxx_check_string(__s);
943 compare(size_type __pos1, size_type __n1,
const _CharT* __s)
const
945 __glibcxx_check_string(__s);
952 compare(size_type __pos1, size_type __n1,
const _CharT* __s,
953 size_type __n2)
const
955 __glibcxx_check_string_len(__s, __n2);
960 _M_base() _GLIBCXX_NOEXCEPT {
return *
this; }
963 _M_base()
const _GLIBCXX_NOEXCEPT {
return *
this; }
965 using _Safe::_M_invalidate_all;
968 template<
typename _CharT,
typename _Traits,
typename _Allocator>
974 template<
typename _CharT,
typename _Traits,
typename _Allocator>
975 inline basic_string<_CharT,_Traits,_Allocator>
976 operator+(
const _CharT* __lhs,
977 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
979 __glibcxx_check_string(__lhs);
980 return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs;
983 template<
typename _CharT,
typename _Traits,
typename _Allocator>
984 inline basic_string<_CharT,_Traits,_Allocator>
985 operator+(_CharT __lhs,
986 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
987 {
return basic_string<_CharT,_Traits,_Allocator>(1, __lhs) += __rhs; }
989 template<
typename _CharT,
typename _Traits,
typename _Allocator>
990 inline basic_string<_CharT,_Traits,_Allocator>
991 operator+(
const basic_string<_CharT,_Traits,_Allocator>& __lhs,
994 __glibcxx_check_string(__rhs);
995 return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs;
998 template<
typename _CharT,
typename _Traits,
typename _Allocator>
999 inline basic_string<_CharT,_Traits,_Allocator>
1000 operator+(
const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1002 {
return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs; }
1004 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1006 operator==(
const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1007 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1008 {
return __lhs._M_base() == __rhs._M_base(); }
1010 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1012 operator==(
const _CharT* __lhs,
1013 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1015 __glibcxx_check_string(__lhs);
1016 return __lhs == __rhs._M_base();
1019 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1021 operator==(
const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1022 const _CharT* __rhs)
1024 __glibcxx_check_string(__rhs);
1025 return __lhs._M_base() == __rhs;
1028 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1030 operator!=(
const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1031 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1032 {
return __lhs._M_base() != __rhs._M_base(); }
1034 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1036 operator!=(
const _CharT* __lhs,
1037 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1039 __glibcxx_check_string(__lhs);
1040 return __lhs != __rhs._M_base();
1043 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1045 operator!=(
const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1046 const _CharT* __rhs)
1048 __glibcxx_check_string(__rhs);
1049 return __lhs._M_base() != __rhs;
1052 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1054 operator<(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1055 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1056 {
return __lhs._M_base() < __rhs._M_base(); }
1058 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1060 operator<(
const _CharT* __lhs,
1061 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1063 __glibcxx_check_string(__lhs);
1064 return __lhs < __rhs._M_base();
1067 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1069 operator<(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1070 const _CharT* __rhs)
1072 __glibcxx_check_string(__rhs);
1073 return __lhs._M_base() < __rhs;
1076 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1078 operator<=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1079 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1080 {
return __lhs._M_base() <= __rhs._M_base(); }
1082 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1084 operator<=(
const _CharT* __lhs,
1085 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1087 __glibcxx_check_string(__lhs);
1088 return __lhs <= __rhs._M_base();
1091 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1093 operator<=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1094 const _CharT* __rhs)
1096 __glibcxx_check_string(__rhs);
1097 return __lhs._M_base() <= __rhs;
1100 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1102 operator>=(
const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1103 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1104 {
return __lhs._M_base() >= __rhs._M_base(); }
1106 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1108 operator>=(
const _CharT* __lhs,
1109 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1111 __glibcxx_check_string(__lhs);
1112 return __lhs >= __rhs._M_base();
1115 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1117 operator>=(
const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1118 const _CharT* __rhs)
1120 __glibcxx_check_string(__rhs);
1121 return __lhs._M_base() >= __rhs;
1124 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1126 operator>(
const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1127 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1128 {
return __lhs._M_base() > __rhs._M_base(); }
1130 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1132 operator>(
const _CharT* __lhs,
1133 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1135 __glibcxx_check_string(__lhs);
1136 return __lhs > __rhs._M_base();
1139 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1141 operator>(
const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1142 const _CharT* __rhs)
1144 __glibcxx_check_string(__rhs);
1145 return __lhs._M_base() > __rhs;
1149 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1151 swap(basic_string<_CharT,_Traits,_Allocator>& __lhs,
1152 basic_string<_CharT,_Traits,_Allocator>& __rhs)
1153 { __lhs.swap(__rhs); }
1155 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1157 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1158 const basic_string<_CharT, _Traits, _Allocator>& __str)
1159 {
return __os << __str._M_base(); }
1161 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1164 basic_string<_CharT,_Traits,_Allocator>& __str)
1167 __str._M_invalidate_all();
1171 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1174 basic_string<_CharT,_Traits,_Allocator>& __str, _CharT __delim)
1179 __str._M_invalidate_all();
1183 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1186 basic_string<_CharT,_Traits,_Allocator>& __str)
1190 __str._M_invalidate_all();
1194 typedef basic_string<char>
string;
1196 #ifdef _GLIBCXX_USE_WCHAR_T
1197 typedef basic_string<wchar_t>
wstring;
1200 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1201 struct _Insert_range_from_self_is_safe<
1202 __gnu_debug::basic_string<_CharT, _Traits, _Allocator> >
1203 {
enum { __value = 1 }; };
const _CharT * c_str() const noexcept
Return const pointer to null-terminated contents.
size_type find_first_of(const basic_string &__str, size_type __pos=0) const noexcept
Find position of a character of string.
Base class for constructing a safe sequence type that tracks iterators that reference it...
void insert(iterator __p, size_type __n, _CharT __c)
Insert multiple characters.
const _CharT * data() const noexcept
Return const pointer to contents.
basic_string substr(size_type __pos=0, size_type __n=npos) const
Get a substring.
void resize(size_type __n, _CharT __c)
Resizes the string to the specified number of characters.
#define __glibcxx_check_erase(_Position)
size_type copy(_CharT *__s, size_type __n, size_type __pos=0) const
Copy substring into C string.
Template class basic_istream.
basic_string & replace(size_type __pos, size_type __n, const basic_string &__str)
Replace characters with value from another string.
#define __glibcxx_check_insert_range(_Position, _First, _Last, _Dist)
#define __glibcxx_check_insert(_Position)
Struct holding two objects of arbitrary type.
Managing sequences of characters and character-like objects.
size_type capacity() const noexcept
basic_string< char > string
A string of char.
_Iterator & base() noexcept
Return the underlying iterator.
const _CharT * __check_string(const _CharT *__s, const _Integer &__n __attribute__((__unused__)))
basic_string & erase(size_type __pos=0, size_type __n=npos)
Remove characters.
int compare(const basic_string &__str) const
Compare to a string.
void swap(basic_string &__s)
Swap contents with another string.
Class std::basic_string with safety/checking/debug instrumentation.
basic_string< wchar_t > wstring
A string of wchar_t.
size_type rfind(const basic_string &__str, size_type __pos=npos) const noexcept
Find last position of a string.
size_type length() const noexcept
Returns the number of characters in the string, not including any null-termination.
size_type find(const _CharT *__s, size_type __pos, size_type __n) const
Find position of a C substring.
std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &__is, bitset< _Nb > &__x)
Global I/O operators for bitsets.
allocator_type get_allocator() const noexcept
Return copy of allocator used to construct this string.
static const size_type npos
Value returned by various member functions when they fail.
size_type max_size() const noexcept
Returns the size() of the largest possible string.
void reserve(size_type __res_arg=0)
Attempt to preallocate enough memory for specified number of characters.
void _M_invalidate_all() const
size_type size() const noexcept
Returns the number of characters in the string, not including any null-termination.
basic_istream< _CharT, _Traits > & getline(basic_istream< _CharT, _Traits > &__is, basic_string< _CharT, _Traits, _Alloc > &__str, _CharT __delim)
Read a line from stream into a string.
const_reference at(size_type __n) const
Provides access to the data contained in the string.
#define __glibcxx_check_erase_range(_First, _Last)
Safe class dealing with some allocator dependent operations.
basic_string & append(const basic_string &__str)
Append a string to this string.
Template class basic_ostream.
_T2 second
first is a copy of the first object
size_type find_last_of(const basic_string &__str, size_type __pos=npos) const noexcept
Find last position of a character of string.
void push_back(_CharT __c)
Append a single character.
bool empty() const noexcept
basic_string & assign(const basic_string &__str)
Set value to contents of another 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.
void pop_back()
Remove the last character.
size_type find_first_not_of(const basic_string &__str, size_type __pos=0) const noexcept
Find position of a character not in string.