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, false>,
54 typedef _Traits traits_type;
55 typedef typename _Traits::char_type value_type;
56 typedef _Allocator allocator_type;
57 typedef typename _Base::size_type size_type;
58 typedef typename _Base::difference_type difference_type;
59 typedef typename _Base::reference reference;
60 typedef typename _Base::const_reference const_reference;
61 typedef typename _Base::pointer pointer;
62 typedef typename _Base::const_pointer const_pointer;
75 explicit basic_string(
const _Allocator& __a = _Allocator())
79 #if __cplusplus < 201103L
89 const _Allocator& __a = _Allocator())
104 const _Allocator& __a = _Allocator())
105 :
_Base(__str, __pos, __n, __a) { }
108 const _Allocator& __a = _Allocator())
111 basic_string(
const _CharT* __s,
const _Allocator& __a = _Allocator())
113 { this->assign(__s); }
116 const _Allocator& __a = _Allocator())
117 :
_Base(__n, __c, __a) { }
119 template<
typename _InputIterator>
120 basic_string(_InputIterator __begin, _InputIterator __end,
121 const _Allocator& __a = _Allocator())
126 #if __cplusplus < 201103L
130 this->_M_safe() = __str;
143 operator=(
const _CharT* __s)
145 __glibcxx_check_string(__s);
152 operator=(_CharT __c)
159 #if __cplusplus >= 201103L
175 begin()
const _GLIBCXX_NOEXCEPT
183 end()
const _GLIBCXX_NOEXCEPT
191 rbegin()
const _GLIBCXX_NOEXCEPT
199 rend()
const _GLIBCXX_NOEXCEPT
202 #if __cplusplus >= 201103L
204 cbegin()
const noexcept
208 cend()
const noexcept
212 crbegin()
const noexcept
216 crend()
const noexcept
226 resize(size_type __n, _CharT __c)
233 resize(size_type __n)
234 { this->resize(__n, _CharT()); }
236 #if __cplusplus >= 201103L
238 shrink_to_fit() noexcept
267 operator[](size_type __pos)
const _GLIBCXX_NOEXCEPT
269 _GLIBCXX_DEBUG_VERIFY(__pos <= this->
size(),
270 _M_message(__gnu_debug::__msg_subscript_oob)
271 ._M_sequence(*
this,
"this")
272 ._M_integer(__pos,
"__pos")
273 ._M_integer(this->
size(),
"size"));
274 return _M_base()[__pos];
278 operator[](size_type __pos)
280 #ifdef _GLIBCXX_DEBUG_PEDANTIC
281 __glibcxx_check_subscript(__pos);
284 _GLIBCXX_DEBUG_VERIFY(__pos <= this->
size(),
285 _M_message(__gnu_debug::__msg_subscript_oob)
286 ._M_sequence(*
this,
"this")
287 ._M_integer(__pos,
"__pos")
288 ._M_integer(this->
size(),
"size"));
290 return _M_base()[__pos];
295 #if __cplusplus >= 201103L
310 operator+=(
const _CharT* __s)
312 __glibcxx_check_string(__s);
319 operator+=(_CharT __c)
326 #if __cplusplus >= 201103L
345 append(
const basic_string& __str, size_type __pos, size_type __n)
353 append(
const _CharT* __s, size_type __n)
355 __glibcxx_check_string_len(__s, __n);
362 append(
const _CharT* __s)
364 __glibcxx_check_string(__s);
371 append(size_type __n, _CharT __c)
378 template<
typename _InputIterator>
380 append(_InputIterator __first, _InputIterator __last)
382 __glibcxx_check_valid_range(__first, __last);
392 push_back(_CharT __c)
406 #if __cplusplus >= 201103L
417 assign(
const basic_string& __str, size_type __pos, size_type __n)
425 assign(
const _CharT* __s, size_type __n)
427 __glibcxx_check_string_len(__s, __n);
434 assign(
const _CharT* __s)
436 __glibcxx_check_string(__s);
443 assign(size_type __n, _CharT __c)
450 template<
typename _InputIterator>
452 assign(_InputIterator __first, _InputIterator __last)
454 __glibcxx_check_valid_range(__first, __last);
461 #if __cplusplus >= 201103L
481 size_type __pos2, size_type __n)
489 insert(size_type __pos,
const _CharT* __s, size_type __n)
491 __glibcxx_check_string(__s);
498 insert(size_type __pos,
const _CharT* __s)
500 __glibcxx_check_string(__s);
507 insert(size_type __pos, size_type __n, _CharT __c)
524 insert(
iterator __p, size_type __n, _CharT __c)
531 template<
typename _InputIterator>
533 insert(
iterator __p, _InputIterator __first, _InputIterator __last)
541 #if __cplusplus >= 201103L
552 erase(size_type __pos = 0, size_type __n =
_Base::npos)
580 #if __cplusplus >= 201103L
584 __glibcxx_check_nonempty();
591 replace(size_type __pos1, size_type __n1,
const basic_string& __str)
599 replace(size_type __pos1, size_type __n1,
const basic_string& __str,
600 size_type __pos2, size_type __n2)
608 replace(size_type __pos, size_type __n1,
const _CharT* __s,
611 __glibcxx_check_string_len(__s, __n2);
618 replace(size_type __pos, size_type __n1,
const _CharT* __s)
620 __glibcxx_check_string(__s);
627 replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
647 __glibcxx_check_string_len(__s, __n);
657 __glibcxx_check_string(__s);
672 template<
typename _InputIterator>
675 _InputIterator __j1, _InputIterator __j2)
678 __glibcxx_check_valid_range(__j1, __j2);
684 #if __cplusplus >= 201103L
696 copy(_CharT* __s, size_type __n, size_type __pos = 0)
const
698 __glibcxx_check_string_len(__s, __n);
711 c_str()
const _GLIBCXX_NOEXCEPT
719 data()
const _GLIBCXX_NOEXCEPT
729 find(
const basic_string& __str, size_type __pos = 0)
const
734 find(
const _CharT* __s, size_type __pos, size_type __n)
const
736 __glibcxx_check_string(__s);
741 find(
const _CharT* __s, size_type __pos = 0)
const
743 __glibcxx_check_string(__s);
748 find(_CharT __c, size_type __pos = 0)
const _GLIBCXX_NOEXCEPT
757 rfind(
const _CharT* __s, size_type __pos, size_type __n)
const
759 __glibcxx_check_string_len(__s, __n);
764 rfind(
const _CharT* __s, size_type __pos =
_Base::npos)
const
766 __glibcxx_check_string(__s);
771 rfind(_CharT __c, size_type __pos =
_Base::npos)
const _GLIBCXX_NOEXCEPT
775 find_first_of(
const basic_string& __str, size_type __pos = 0)
const
780 find_first_of(
const _CharT* __s, size_type __pos, size_type __n)
const
782 __glibcxx_check_string(__s);
787 find_first_of(
const _CharT* __s, size_type __pos = 0)
const
789 __glibcxx_check_string(__s);
794 find_first_of(_CharT __c, size_type __pos = 0)
const _GLIBCXX_NOEXCEPT
799 size_type __pos =
_Base::npos)
const _GLIBCXX_NOEXCEPT
803 find_last_of(
const _CharT* __s, size_type __pos, size_type __n)
const
805 __glibcxx_check_string(__s);
810 find_last_of(
const _CharT* __s, size_type __pos =
_Base::npos)
const
812 __glibcxx_check_string(__s);
817 find_last_of(_CharT __c, size_type __pos =
_Base::npos)
const
822 find_first_not_of(
const basic_string& __str, size_type __pos = 0)
const
827 find_first_not_of(
const _CharT* __s, size_type __pos, size_type __n)
const
829 __glibcxx_check_string_len(__s, __n);
834 find_first_not_of(
const _CharT* __s, size_type __pos = 0)
const
836 __glibcxx_check_string(__s);
841 find_first_not_of(_CharT __c, size_type __pos = 0)
const _GLIBCXX_NOEXCEPT
851 find_last_not_of(
const _CharT* __s, size_type __pos, size_type __n)
const
853 __glibcxx_check_string(__s);
858 find_last_not_of(
const _CharT* __s, size_type __pos =
_Base::npos)
const
860 __glibcxx_check_string(__s);
865 find_last_not_of(_CharT __c, size_type __pos =
_Base::npos)
const
870 substr(size_type __pos = 0, size_type __n =
_Base::npos)
const
878 compare(size_type __pos1, size_type __n1,
883 compare(size_type __pos1, size_type __n1,
const basic_string& __str,
884 size_type __pos2, size_type __n2)
const
888 compare(
const _CharT* __s)
const
890 __glibcxx_check_string(__s);
897 compare(size_type __pos1, size_type __n1,
const _CharT* __s)
const
899 __glibcxx_check_string(__s);
906 compare(size_type __pos1, size_type __n1,
const _CharT* __s,
907 size_type __n2)
const
909 __glibcxx_check_string_len(__s, __n2);
914 _M_base() _GLIBCXX_NOEXCEPT {
return *
this; }
917 _M_base()
const _GLIBCXX_NOEXCEPT {
return *
this; }
919 using _Safe::_M_invalidate_all;
922 template<
typename _CharT,
typename _Traits,
typename _Allocator>
928 template<
typename _CharT,
typename _Traits,
typename _Allocator>
929 inline basic_string<_CharT,_Traits,_Allocator>
930 operator+(
const _CharT* __lhs,
931 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
933 __glibcxx_check_string(__lhs);
934 return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs;
937 template<
typename _CharT,
typename _Traits,
typename _Allocator>
938 inline basic_string<_CharT,_Traits,_Allocator>
939 operator+(_CharT __lhs,
940 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
941 {
return basic_string<_CharT,_Traits,_Allocator>(1, __lhs) += __rhs; }
943 template<
typename _CharT,
typename _Traits,
typename _Allocator>
944 inline basic_string<_CharT,_Traits,_Allocator>
945 operator+(
const basic_string<_CharT,_Traits,_Allocator>& __lhs,
948 __glibcxx_check_string(__rhs);
949 return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs;
952 template<
typename _CharT,
typename _Traits,
typename _Allocator>
953 inline basic_string<_CharT,_Traits,_Allocator>
954 operator+(
const basic_string<_CharT,_Traits,_Allocator>& __lhs,
956 {
return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs; }
958 template<
typename _CharT,
typename _Traits,
typename _Allocator>
960 operator==(
const basic_string<_CharT,_Traits,_Allocator>& __lhs,
961 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
962 {
return __lhs._M_base() == __rhs._M_base(); }
964 template<
typename _CharT,
typename _Traits,
typename _Allocator>
966 operator==(
const _CharT* __lhs,
967 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
969 __glibcxx_check_string(__lhs);
970 return __lhs == __rhs._M_base();
973 template<
typename _CharT,
typename _Traits,
typename _Allocator>
975 operator==(
const basic_string<_CharT,_Traits,_Allocator>& __lhs,
978 __glibcxx_check_string(__rhs);
979 return __lhs._M_base() == __rhs;
982 template<
typename _CharT,
typename _Traits,
typename _Allocator>
984 operator!=(
const basic_string<_CharT,_Traits,_Allocator>& __lhs,
985 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
986 {
return __lhs._M_base() != __rhs._M_base(); }
988 template<
typename _CharT,
typename _Traits,
typename _Allocator>
990 operator!=(
const _CharT* __lhs,
991 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
993 __glibcxx_check_string(__lhs);
994 return __lhs != __rhs._M_base();
997 template<
typename _CharT,
typename _Traits,
typename _Allocator>
999 operator!=(
const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1000 const _CharT* __rhs)
1002 __glibcxx_check_string(__rhs);
1003 return __lhs._M_base() != __rhs;
1006 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1008 operator<(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1009 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1010 {
return __lhs._M_base() < __rhs._M_base(); }
1012 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1014 operator<(
const _CharT* __lhs,
1015 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1017 __glibcxx_check_string(__lhs);
1018 return __lhs < __rhs._M_base();
1021 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1023 operator<(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1024 const _CharT* __rhs)
1026 __glibcxx_check_string(__rhs);
1027 return __lhs._M_base() < __rhs;
1030 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1032 operator<=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1033 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1034 {
return __lhs._M_base() <= __rhs._M_base(); }
1036 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1038 operator<=(
const _CharT* __lhs,
1039 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1041 __glibcxx_check_string(__lhs);
1042 return __lhs <= __rhs._M_base();
1045 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1047 operator<=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
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,
1057 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1058 {
return __lhs._M_base() >= __rhs._M_base(); }
1060 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1062 operator>=(
const _CharT* __lhs,
1063 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
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,
1081 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1082 {
return __lhs._M_base() > __rhs._M_base(); }
1084 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1086 operator>(
const _CharT* __lhs,
1087 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
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;
1103 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1105 swap(basic_string<_CharT,_Traits,_Allocator>& __lhs,
1106 basic_string<_CharT,_Traits,_Allocator>& __rhs)
1107 { __lhs.swap(__rhs); }
1109 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1111 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1112 const basic_string<_CharT, _Traits, _Allocator>& __str)
1113 {
return __os << __str._M_base(); }
1115 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1118 basic_string<_CharT,_Traits,_Allocator>& __str)
1121 __str._M_invalidate_all();
1125 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1128 basic_string<_CharT,_Traits,_Allocator>& __str, _CharT __delim)
1133 __str._M_invalidate_all();
1137 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1140 basic_string<_CharT,_Traits,_Allocator>& __str)
1144 __str._M_invalidate_all();
1148 typedef basic_string<char>
string;
1150 #ifdef _GLIBCXX_USE_WCHAR_T
1151 typedef basic_string<wchar_t>
wstring;
1154 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1155 struct _Insert_range_from_self_is_safe<
1156 __gnu_debug::basic_string<_CharT, _Traits, _Allocator> >
1157 {
enum { __value = 1 }; };
void _M_invalidate_all() const
const _CharT * __check_string(const _CharT *__s, const _Integer &__n __attribute__((__unused__)))
size_type size() const noexcept
Returns the number of characters in the string, not including any null-termination.
_Siter_base< _Iterator >::iterator_type __base(_Iterator __it)
size_type find(const _CharT *__s, size_type __pos, size_type __n) const
Find position of a C substring.
basic_string & append(const basic_string &__str)
Append a string to 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.
const_reference at(size_type __n) const
Provides access to the data contained in the string.
Template class basic_ostream.
void push_back(_CharT __c)
Append a single character.
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.
#define __glibcxx_check_insert(_Position)
size_type find_first_of(const basic_string &__str, size_type __pos=0) const noexcept
Find position of a character of string.
_Iterator & base() noexcept
Return the underlying iterator.
bool empty() const noexcept
void insert(iterator __p, size_type __n, _CharT __c)
Insert multiple characters.
const _CharT * c_str() const noexcept
Return const pointer to null-terminated contents.
size_type find_last_of(const basic_string &__str, size_type __pos=npos) const noexcept
Find last position of a character of string.
void resize(size_type __n, _CharT __c)
Resizes the string to the specified number of characters.
const _CharT * data() const noexcept
Return const pointer to contents.
bitset< _Nb > operator>>(size_t __position) const noexcept
Self-explanatory.
basic_string substr(size_type __pos=0, size_type __n=npos) const
Get a substring.
basic_string & assign(const basic_string &__str)
Set value to contents of another string.
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.
Managing sequences of characters and character-like objects.
basic_string< wchar_t > wstring
A string of wchar_t.
void swap(basic_filebuf< _CharT, _Traits > &__x, basic_filebuf< _CharT, _Traits > &__y)
Swap specialization for filebufs.
basic_string & erase(size_type __pos=0, size_type __n=npos)
Remove characters.
int compare(const basic_string &__str) const
Compare to a string.
#define __glibcxx_check_insert_range(_Position, _First, _Last)
size_type copy(_CharT *__s, size_type __n, size_type __pos=0) const
Copy substring into C string.
basic_string & replace(size_type __pos, size_type __n, const basic_string &__str)
Replace characters with value from another string.
size_type capacity() const noexcept
size_type length() const noexcept
Returns the number of characters in the string, not including any null-termination.
Base class for constructing a safe sequence type that tracks iterators that reference it...
void reserve(size_type __res_arg=0)
Attempt to preallocate enough memory for specified number of characters.
#define __glibcxx_check_erase(_Position)
allocator_type get_allocator() const noexcept
Return copy of allocator used to construct this string.
Class std::basic_string with safety/checking/debug instrumentation.
#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.
Safe class dealing with some allocator dependent operations.
void swap(basic_string &__s)
Swap contents with another string.
basic_string< char > string
A string of char.
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.