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;
78 _GLIBCXX_NOEXCEPT_IF(std::is_nothrow_default_constructible<_Base>::value)
86 #if __cplusplus < 201103L
96 const _Allocator& __a = _Allocator())
100 #if _GLIBCXX_USE_CXX11_ABI
102 :
_Base(__s, __a) { }
105 :
_Base(std::move(__s), __a) { }
112 :
_Base(std::move(__base)) { }
123 const _Allocator& __a = _Allocator())
124 :
_Base(__str, __pos, __n, __a) { }
127 const _Allocator& __a = _Allocator())
130 basic_string(
const _CharT* __s,
const _Allocator& __a = _Allocator())
132 { this->assign(__s); }
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
149 this->_M_safe() = __str;
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
210 rbegin()
const _GLIBCXX_NOEXCEPT
218 rend()
const _GLIBCXX_NOEXCEPT
221 #if __cplusplus >= 201103L
223 cbegin()
const noexcept
227 cend()
const noexcept
231 crbegin()
const noexcept
235 crend()
const noexcept
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
329 operator+=(
const _CharT* __s)
331 __glibcxx_check_string(__s);
338 operator+=(_CharT __c)
345 #if __cplusplus >= 201103L
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)
431 #if __cplusplus >= 201103L
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
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)
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)
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)
685 __glibcxx_check_string_len(__s, __n);
695 __glibcxx_check_string(__s);
710 template<
typename _InputIterator>
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
743 copy(_CharT* __s, size_type __n, size_type __pos = 0)
const
745 __glibcxx_check_string_len(__s, __n);
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
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
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
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
926 compare(size_type __pos1, size_type __n1,
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>
977 inline basic_string<_CharT,_Traits,_Allocator>
978 operator+(
const _CharT* __lhs,
979 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
981 __glibcxx_check_string(__lhs);
982 return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs;
985 template<
typename _CharT,
typename _Traits,
typename _Allocator>
986 inline basic_string<_CharT,_Traits,_Allocator>
987 operator+(_CharT __lhs,
988 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
989 {
return basic_string<_CharT,_Traits,_Allocator>(1, __lhs) += __rhs; }
991 template<
typename _CharT,
typename _Traits,
typename _Allocator>
992 inline basic_string<_CharT,_Traits,_Allocator>
993 operator+(
const basic_string<_CharT,_Traits,_Allocator>& __lhs,
996 __glibcxx_check_string(__rhs);
997 return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs;
1000 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1001 inline basic_string<_CharT,_Traits,_Allocator>
1002 operator+(
const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1004 {
return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __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;
1102 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1104 operator>=(
const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1105 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1106 {
return __lhs._M_base() >= __rhs._M_base(); }
1108 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1110 operator>=(
const _CharT* __lhs,
1111 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1113 __glibcxx_check_string(__lhs);
1114 return __lhs >= __rhs._M_base();
1117 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1119 operator>=(
const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1120 const _CharT* __rhs)
1122 __glibcxx_check_string(__rhs);
1123 return __lhs._M_base() >= __rhs;
1126 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1128 operator>(
const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1129 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1130 {
return __lhs._M_base() > __rhs._M_base(); }
1132 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1134 operator>(
const _CharT* __lhs,
1135 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1137 __glibcxx_check_string(__lhs);
1138 return __lhs > __rhs._M_base();
1141 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1143 operator>(
const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1144 const _CharT* __rhs)
1146 __glibcxx_check_string(__rhs);
1147 return __lhs._M_base() > __rhs;
1151 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1153 swap(basic_string<_CharT,_Traits,_Allocator>& __lhs,
1154 basic_string<_CharT,_Traits,_Allocator>& __rhs)
1155 { __lhs.swap(__rhs); }
1157 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1159 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1160 const basic_string<_CharT, _Traits, _Allocator>& __str)
1161 {
return __os << __str._M_base(); }
1163 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1166 basic_string<_CharT,_Traits,_Allocator>& __str)
1169 __str._M_invalidate_all();
1173 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1176 basic_string<_CharT,_Traits,_Allocator>& __str, _CharT __delim)
1181 __str._M_invalidate_all();
1185 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1188 basic_string<_CharT,_Traits,_Allocator>& __str)
1192 __str._M_invalidate_all();
1196 typedef basic_string<char>
string;
1198 #ifdef _GLIBCXX_USE_WCHAR_T
1199 typedef basic_string<wchar_t>
wstring;
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 }; };
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 length() const noexcept
Returns the number of characters in the string, not including any null-termination.
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.
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.
_Iterator & base() noexcept
Return the underlying iterator.
size_type find_first_of(const basic_string &__str, size_type __pos=0) const noexcept
Find position of a character of string.
basic_string & assign(const basic_string &__str)
Set value to contents of another string.
void insert(iterator __p, size_type __n, _CharT __c)
Insert multiple characters.
basic_string< wchar_t > wstring
A string of wchar_t.
#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_last_of(const basic_string &__str, size_type __pos=npos) const noexcept
Find last position of a character of string.
#define __glibcxx_check_insert(_Position)
int compare(const basic_string &__str) const
Compare to a string.
size_type find(const _CharT *__s, size_type __pos, size_type __n) const noexcept
Find position of a C substring.
Safe class dealing with some allocator dependent operations.
std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &__is, bitset< _Nb > &__x)
Global I/O operators for bitsets.
Managing sequences of characters and character-like objects.
basic_string & append(const basic_string &__str)
Append a string to this string.
Template class basic_ostream.
void pop_back()
Remove the last character.
Class std::basic_string with safety/checking/debug instrumentation.
size_type max_size() const noexcept
Returns the size() of the largest possible string.
const _CharT * data() const noexcept
Return const pointer to contents.
void reserve(size_type __res_arg=0)
Attempt to preallocate enough memory for specified number of characters.
size_type capacity() const noexcept
basic_string< char > string
A string of char.
void resize(size_type __n, _CharT __c)
Resizes the string to the specified number of characters.
size_type copy(_CharT *__s, size_type __n, size_type __pos=0) const
Copy substring into C 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.
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 find_last_not_of(const basic_string &__str, size_type __pos=npos) const noexcept
Find last position of a character not in string.
size_type size() const noexcept
Returns the number of characters in the string, not including any null-termination.
_T2 second
first is a copy of the first object
Template class basic_istream.
basic_string & erase(size_type __pos=0, size_type __n=npos)
Remove characters.
void push_back(_CharT __c)
Append a single character.
void swap(basic_string &__s)
Swap contents with another string.
static const size_type npos
Value returned by various member functions when they fail.
bool empty() const noexcept
Struct holding two objects of arbitrary type.
Base class for constructing a safe sequence type that tracks iterators that reference it...
basic_string substr(size_type __pos=0, size_type __n=npos) const
Get a substring.
#define __glibcxx_check_erase(_Position)