30 #ifndef _GLIBCXX_DEBUG_STRING
31 #define _GLIBCXX_DEBUG_STRING 1
40 template<
typename _CharT,
typename _Traits = std::
char_traits<_CharT>,
41 typename _Allocator = std::allocator<_CharT> >
52 typedef _Traits traits_type;
53 typedef typename _Traits::char_type value_type;
54 typedef _Allocator allocator_type;
55 typedef typename _Base::size_type size_type;
56 typedef typename _Base::difference_type difference_type;
57 typedef typename _Base::reference reference;
58 typedef typename _Base::const_reference const_reference;
59 typedef typename _Base::pointer pointer;
60 typedef typename _Base::const_pointer const_pointer;
73 explicit basic_string(
const _Allocator& __a = _Allocator())
90 const _Allocator& __a = _Allocator())
91 :
_Base(__str, __pos, __n, __a)
95 const _Allocator& __a = _Allocator())
99 basic_string(
const _CharT* __s,
const _Allocator& __a = _Allocator())
101 { this->assign(__s); }
104 const _Allocator& __a = _Allocator())
105 :
_Base(__n, __c, __a)
108 template<
typename _InputIterator>
109 basic_string(_InputIterator __begin, _InputIterator __end,
110 const _Allocator& __a = _Allocator())
116 #ifdef __GXX_EXPERIMENTAL_CXX0X__
118 :
_Base(std::move(__str))
122 const _Allocator& __a = _Allocator())
125 #endif // __GXX_EXPERIMENTAL_CXX0X__
132 *
static_cast<_Base*
>(
this) = __str;
138 operator=(
const _CharT* __s)
140 __glibcxx_check_string(__s);
141 *
static_cast<_Base*
>(
this) = __s;
147 operator=(_CharT __c)
149 *
static_cast<_Base*
>(
this) = __c;
154 #ifdef __GXX_EXPERIMENTAL_CXX0X__
158 *
static_cast<_Base*
>(
this) = std::move(__str);
166 *
static_cast<_Base*
>(
this) = __l;
170 #endif // __GXX_EXPERIMENTAL_CXX0X__
174 begin() _GLIBCXX_NOEXCEPT
178 begin()
const _GLIBCXX_NOEXCEPT
182 end() _GLIBCXX_NOEXCEPT
186 end()
const _GLIBCXX_NOEXCEPT
190 rbegin() _GLIBCXX_NOEXCEPT
194 rbegin()
const _GLIBCXX_NOEXCEPT
198 rend() _GLIBCXX_NOEXCEPT
202 rend()
const _GLIBCXX_NOEXCEPT
205 #ifdef __GXX_EXPERIMENTAL_CXX0X__
207 cbegin()
const noexcept
211 cend()
const noexcept
215 crbegin()
const noexcept
219 crend()
const noexcept
229 resize(size_type __n, _CharT __c)
236 resize(size_type __n)
237 { this->resize(__n, _CharT()); }
239 #ifdef __GXX_EXPERIMENTAL_CXX0X__
260 clear() _GLIBCXX_NOEXCEPT
270 operator[](size_type __pos)
const
272 _GLIBCXX_DEBUG_VERIFY(__pos <= this->
size(),
273 _M_message(__gnu_debug::__msg_subscript_oob)
274 ._M_sequence(*
this,
"this")
275 ._M_integer(__pos,
"__pos")
276 ._M_integer(this->
size(),
"size"));
277 return _M_base()[__pos];
281 operator[](size_type __pos)
283 #ifdef _GLIBCXX_DEBUG_PEDANTIC
284 __glibcxx_check_subscript(__pos);
287 _GLIBCXX_DEBUG_VERIFY(__pos <= this->
size(),
288 _M_message(__gnu_debug::__msg_subscript_oob)
289 ._M_sequence(*
this,
"this")
290 ._M_integer(__pos,
"__pos")
291 ._M_integer(this->
size(),
"size"));
293 return _M_base()[__pos];
298 #ifdef __GXX_EXPERIMENTAL_CXX0X__
313 operator+=(
const _CharT* __s)
315 __glibcxx_check_string(__s);
322 operator+=(_CharT __c)
329 #ifdef __GXX_EXPERIMENTAL_CXX0X__
337 #endif // __GXX_EXPERIMENTAL_CXX0X__
348 append(
const basic_string& __str, size_type __pos, size_type __n)
356 append(
const _CharT* __s, size_type __n)
358 __glibcxx_check_string_len(__s, __n);
365 append(
const _CharT* __s)
367 __glibcxx_check_string(__s);
374 append(size_type __n, _CharT __c)
381 template<
typename _InputIterator>
383 append(_InputIterator __first, _InputIterator __last)
385 __glibcxx_check_valid_range(__first, __last);
395 push_back(_CharT __c)
409 #ifdef __GXX_EXPERIMENTAL_CXX0X__
417 #endif // __GXX_EXPERIMENTAL_CXX0X__
420 assign(
const basic_string& __str, size_type __pos, size_type __n)
428 assign(
const _CharT* __s, size_type __n)
430 __glibcxx_check_string_len(__s, __n);
437 assign(
const _CharT* __s)
439 __glibcxx_check_string(__s);
446 assign(size_type __n, _CharT __c)
453 template<
typename _InputIterator>
455 assign(_InputIterator __first, _InputIterator __last)
457 __glibcxx_check_valid_range(__first, __last);
464 #ifdef __GXX_EXPERIMENTAL_CXX0X__
472 #endif // __GXX_EXPERIMENTAL_CXX0X__
484 size_type __pos2, size_type __n)
492 insert(size_type __pos,
const _CharT* __s, size_type __n)
494 __glibcxx_check_string(__s);
501 insert(size_type __pos,
const _CharT* __s)
503 __glibcxx_check_string(__s);
510 insert(size_type __pos, size_type __n, _CharT __c)
527 insert(
iterator __p, size_type __n, _CharT __c)
534 template<
typename _InputIterator>
536 insert(
iterator __p, _InputIterator __first, _InputIterator __last)
544 #ifdef __GXX_EXPERIMENTAL_CXX0X__
552 #endif // __GXX_EXPERIMENTAL_CXX0X__
555 erase(size_type __pos = 0, size_type __n =
_Base::npos)
583 #ifdef __GXX_EXPERIMENTAL_CXX0X__
587 __glibcxx_check_nonempty();
591 #endif // __GXX_EXPERIMENTAL_CXX0X__
594 replace(size_type __pos1, size_type __n1,
const basic_string& __str)
602 replace(size_type __pos1, size_type __n1,
const basic_string& __str,
603 size_type __pos2, size_type __n2)
611 replace(size_type __pos, size_type __n1,
const _CharT* __s,
614 __glibcxx_check_string_len(__s, __n2);
621 replace(size_type __pos, size_type __n1,
const _CharT* __s)
623 __glibcxx_check_string(__s);
630 replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
650 __glibcxx_check_string_len(__s, __n);
660 __glibcxx_check_string(__s);
675 template<
typename _InputIterator>
678 _InputIterator __j1, _InputIterator __j2)
681 __glibcxx_check_valid_range(__j1, __j2);
687 #ifdef __GXX_EXPERIMENTAL_CXX0X__
696 #endif // __GXX_EXPERIMENTAL_CXX0X__
699 copy(_CharT* __s, size_type __n, size_type __pos = 0)
const
701 __glibcxx_check_string_len(__s, __n);
716 c_str()
const _GLIBCXX_NOEXCEPT
724 data()
const _GLIBCXX_NOEXCEPT
734 find(
const basic_string& __str, size_type __pos = 0)
const
739 find(
const _CharT* __s, size_type __pos, size_type __n)
const
741 __glibcxx_check_string(__s);
746 find(
const _CharT* __s, size_type __pos = 0)
const
748 __glibcxx_check_string(__s);
753 find(_CharT __c, size_type __pos = 0)
const _GLIBCXX_NOEXCEPT
762 rfind(
const _CharT* __s, size_type __pos, size_type __n)
const
764 __glibcxx_check_string_len(__s, __n);
769 rfind(
const _CharT* __s, size_type __pos =
_Base::npos)
const
771 __glibcxx_check_string(__s);
776 rfind(_CharT __c, size_type __pos =
_Base::npos)
const _GLIBCXX_NOEXCEPT
780 find_first_of(
const basic_string& __str, size_type __pos = 0)
const
785 find_first_of(
const _CharT* __s, size_type __pos, size_type __n)
const
787 __glibcxx_check_string(__s);
792 find_first_of(
const _CharT* __s, size_type __pos = 0)
const
794 __glibcxx_check_string(__s);
799 find_first_of(_CharT __c, size_type __pos = 0)
const _GLIBCXX_NOEXCEPT
804 size_type __pos =
_Base::npos)
const _GLIBCXX_NOEXCEPT
808 find_last_of(
const _CharT* __s, size_type __pos, size_type __n)
const
810 __glibcxx_check_string(__s);
815 find_last_of(
const _CharT* __s, size_type __pos =
_Base::npos)
const
817 __glibcxx_check_string(__s);
822 find_last_of(_CharT __c, size_type __pos =
_Base::npos)
const
827 find_first_not_of(
const basic_string& __str, size_type __pos = 0)
const
832 find_first_not_of(
const _CharT* __s, size_type __pos, size_type __n)
const
834 __glibcxx_check_string_len(__s, __n);
839 find_first_not_of(
const _CharT* __s, size_type __pos = 0)
const
841 __glibcxx_check_string(__s);
846 find_first_not_of(_CharT __c, size_type __pos = 0)
const _GLIBCXX_NOEXCEPT
856 find_last_not_of(
const _CharT* __s, size_type __pos, size_type __n)
const
858 __glibcxx_check_string(__s);
863 find_last_not_of(
const _CharT* __s, size_type __pos =
_Base::npos)
const
865 __glibcxx_check_string(__s);
870 find_last_not_of(_CharT __c, size_type __pos =
_Base::npos)
const
875 substr(size_type __pos = 0, size_type __n =
_Base::npos)
const
883 compare(size_type __pos1, size_type __n1,
888 compare(size_type __pos1, size_type __n1,
const basic_string& __str,
889 size_type __pos2, size_type __n2)
const
893 compare(
const _CharT* __s)
const
895 __glibcxx_check_string(__s);
902 compare(size_type __pos1, size_type __n1,
const _CharT* __s)
const
904 __glibcxx_check_string(__s);
911 compare(size_type __pos1, size_type __n1,
const _CharT* __s,
912 size_type __n2)
const
914 __glibcxx_check_string_len(__s, __n2);
919 _M_base() _GLIBCXX_NOEXCEPT {
return *
this; }
922 _M_base()
const _GLIBCXX_NOEXCEPT {
return *
this; }
927 template<
typename _CharT,
typename _Traits,
typename _Allocator>
933 template<
typename _CharT,
typename _Traits,
typename _Allocator>
934 inline basic_string<_CharT,_Traits,_Allocator>
935 operator+(
const _CharT* __lhs,
936 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
938 __glibcxx_check_string(__lhs);
939 return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs;
942 template<
typename _CharT,
typename _Traits,
typename _Allocator>
943 inline basic_string<_CharT,_Traits,_Allocator>
944 operator+(_CharT __lhs,
945 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
946 {
return basic_string<_CharT,_Traits,_Allocator>(1, __lhs) += __rhs; }
948 template<
typename _CharT,
typename _Traits,
typename _Allocator>
949 inline basic_string<_CharT,_Traits,_Allocator>
950 operator+(
const basic_string<_CharT,_Traits,_Allocator>& __lhs,
953 __glibcxx_check_string(__rhs);
954 return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs;
957 template<
typename _CharT,
typename _Traits,
typename _Allocator>
958 inline basic_string<_CharT,_Traits,_Allocator>
959 operator+(
const basic_string<_CharT,_Traits,_Allocator>& __lhs,
961 {
return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs; }
963 template<
typename _CharT,
typename _Traits,
typename _Allocator>
965 operator==(
const basic_string<_CharT,_Traits,_Allocator>& __lhs,
966 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
967 {
return __lhs._M_base() == __rhs._M_base(); }
969 template<
typename _CharT,
typename _Traits,
typename _Allocator>
971 operator==(
const _CharT* __lhs,
972 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
974 __glibcxx_check_string(__lhs);
975 return __lhs == __rhs._M_base();
978 template<
typename _CharT,
typename _Traits,
typename _Allocator>
980 operator==(
const basic_string<_CharT,_Traits,_Allocator>& __lhs,
983 __glibcxx_check_string(__rhs);
984 return __lhs._M_base() == __rhs;
987 template<
typename _CharT,
typename _Traits,
typename _Allocator>
989 operator!=(
const basic_string<_CharT,_Traits,_Allocator>& __lhs,
990 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
991 {
return __lhs._M_base() != __rhs._M_base(); }
993 template<
typename _CharT,
typename _Traits,
typename _Allocator>
995 operator!=(
const _CharT* __lhs,
996 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
998 __glibcxx_check_string(__lhs);
999 return __lhs != __rhs._M_base();
1002 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1004 operator!=(
const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1005 const _CharT* __rhs)
1007 __glibcxx_check_string(__rhs);
1008 return __lhs._M_base() != __rhs;
1011 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1013 operator<(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1014 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1015 {
return __lhs._M_base() < __rhs._M_base(); }
1017 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1019 operator<(
const _CharT* __lhs,
1020 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1022 __glibcxx_check_string(__lhs);
1023 return __lhs < __rhs._M_base();
1026 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1028 operator<(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1029 const _CharT* __rhs)
1031 __glibcxx_check_string(__rhs);
1032 return __lhs._M_base() < __rhs;
1035 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1037 operator<=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1038 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1039 {
return __lhs._M_base() <= __rhs._M_base(); }
1041 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1043 operator<=(
const _CharT* __lhs,
1044 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1046 __glibcxx_check_string(__lhs);
1047 return __lhs <= __rhs._M_base();
1050 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1052 operator<=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1053 const _CharT* __rhs)
1055 __glibcxx_check_string(__rhs);
1056 return __lhs._M_base() <= __rhs;
1059 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1061 operator>=(
const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1062 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1063 {
return __lhs._M_base() >= __rhs._M_base(); }
1065 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1067 operator>=(
const _CharT* __lhs,
1068 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1070 __glibcxx_check_string(__lhs);
1071 return __lhs >= __rhs._M_base();
1074 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1076 operator>=(
const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1077 const _CharT* __rhs)
1079 __glibcxx_check_string(__rhs);
1080 return __lhs._M_base() >= __rhs;
1083 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1085 operator>(
const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1086 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1087 {
return __lhs._M_base() > __rhs._M_base(); }
1089 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1091 operator>(
const _CharT* __lhs,
1092 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1094 __glibcxx_check_string(__lhs);
1095 return __lhs > __rhs._M_base();
1098 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1100 operator>(
const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1101 const _CharT* __rhs)
1103 __glibcxx_check_string(__rhs);
1104 return __lhs._M_base() > __rhs;
1108 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1110 swap(basic_string<_CharT,_Traits,_Allocator>& __lhs,
1111 basic_string<_CharT,_Traits,_Allocator>& __rhs)
1112 { __lhs.swap(__rhs); }
1114 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1116 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1117 const basic_string<_CharT, _Traits, _Allocator>& __str)
1118 {
return __os << __str._M_base(); }
1120 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1123 basic_string<_CharT,_Traits,_Allocator>& __str)
1126 __str._M_invalidate_all();
1130 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1133 basic_string<_CharT,_Traits,_Allocator>& __str, _CharT __delim)
1138 __str._M_invalidate_all();
1142 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1145 basic_string<_CharT,_Traits,_Allocator>& __str)
1149 __str._M_invalidate_all();
1153 typedef basic_string<char> string;
1155 #ifdef _GLIBCXX_USE_WCHAR_T
1156 typedef basic_string<wchar_t> wstring;
_Siter_base< _Iterator >::iterator_type __base(_Iterator __it)
basic_string & replace(size_type __pos, size_type __n, const basic_string &__str)
Replace characters with value from another string.
Class std::basic_string with safety/checking/debug instrumentation.
void push_back(_CharT __c)
Append a single character.
bool empty() const _GLIBCXX_NOEXCEPT
int compare(const basic_string &__str) const
Compare to a string.
#define __glibcxx_check_erase_range(_First, _Last)
void _M_swap(_Safe_sequence_base &__x)
_Iterator base() const
Return the underlying iterator.
void swap(basic_string &__s)
Swap contents with another string.
size_type capacity() const _GLIBCXX_NOEXCEPT
const _CharT * c_str() const _GLIBCXX_NOEXCEPT
Return const pointer to null-terminated contents.
#define __glibcxx_check_erase(_Position)
void insert(iterator __p, size_type __n, _CharT __c)
Insert multiple characters.
Template class basic_ostream.This is the base class for all output streams. It provides text formatti...
basic_string & append(const basic_string &__str)
Append a string to this string.
void _M_invalidate_all() const
size_type size() const _GLIBCXX_NOEXCEPT
Returns the number of characters in the string, not including any null-termination.
size_type find_first_not_of(const basic_string &__str, size_type __pos=0) const _GLIBCXX_NOEXCEPT
Find position of a character not in string.
const _CharT * data() const _GLIBCXX_NOEXCEPT
Return const pointer to contents.
const_reference at(size_type __n) const
Provides access to the data contained in the string.
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.
size_type length() const _GLIBCXX_NOEXCEPT
Returns the number of characters in the string, not including any null-termination.
iterator begin() _GLIBCXX_NOEXCEPT
size_type find(const _CharT *__s, size_type __pos, size_type __n) const
Find position of a C substring.
size_type copy(_CharT *__s, size_type __n, size_type __pos=0) const
Copy substring into C string.
size_type find_last_of(const basic_string &__str, size_type __pos=npos) const _GLIBCXX_NOEXCEPT
Find last position of a character of string.
void reserve(size_type __res_arg=0)
Attempt to preallocate enough memory for specified number of characters.
basic_string & erase(size_type __pos=0, size_type __n=npos)
Remove characters.
void pop_back()
Remove the last character.
const _CharT * __check_string(const _CharT *__s, const _Integer &__n __attribute__((__unused__)))
basic_string()
Default constructor creates an empty string.
size_type find_last_not_of(const basic_string &__str, size_type __pos=npos) const _GLIBCXX_NOEXCEPT
Find last position of a character not in string.
size_type find_first_of(const basic_string &__str, size_type __pos=0) const _GLIBCXX_NOEXCEPT
Find position of a character of string.
Template class basic_istream.This is the base class for all input streams. It provides text formattin...
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.
Managing sequences of characters and character-like objects.
#define __glibcxx_check_insert_range(_Position, _First, _Last)
#define __glibcxx_check_insert(_Position)
void resize(size_type __n, _CharT __c)
Resizes the string to the specified number of characters.
size_type max_size() const _GLIBCXX_NOEXCEPT
Returns the size() of the largest possible string.
iterator end() _GLIBCXX_NOEXCEPT
bitset< _Nb > operator>>(size_t __position) const _GLIBCXX_NOEXCEPT
Self-explanatory.
Base class for constructing a safe sequence type that tracks iterators that reference it...
allocator_type get_allocator() const _GLIBCXX_NOEXCEPT
Return copy of allocator used to construct this string.
size_type rfind(const basic_string &__str, size_type __pos=npos) const _GLIBCXX_NOEXCEPT
Find last position of a string.
void clear() _GLIBCXX_NOEXCEPT
static const size_type npos
Value returned by various member functions when they fail.