30 #ifndef _GLIBCXX_DEBUG_STRING
31 #define _GLIBCXX_DEBUG_STRING 1
39 template<
typename _CharT,
typename _Traits = std::
char_traits<_CharT>,
40 typename _Allocator = std::allocator<_CharT> >
51 typedef _Traits traits_type;
52 typedef typename _Traits::char_type value_type;
53 typedef _Allocator allocator_type;
54 typedef typename _Base::size_type size_type;
55 typedef typename _Base::difference_type difference_type;
56 typedef typename _Base::reference reference;
57 typedef typename _Base::const_reference const_reference;
58 typedef typename _Base::pointer pointer;
59 typedef typename _Base::const_pointer const_pointer;
64 basic_string> const_iterator;
72 explicit basic_string(
const _Allocator& __a = _Allocator())
77 basic_string(
const _Base& __base) : _Base(__base), _Safe_base() { }
81 basic_string(
const basic_string& __str)
82 : _Base(__str, 0,
_Base::npos, __str.get_allocator()), _Safe_base()
87 basic_string(
const basic_string& __str, size_type __pos,
89 const _Allocator& __a = _Allocator())
90 : _Base(__str, __pos, __n, __a)
93 basic_string(
const _CharT* __s, size_type __n,
94 const _Allocator& __a = _Allocator())
98 basic_string(
const _CharT* __s,
const _Allocator& __a = _Allocator())
100 { this->assign(__s); }
102 basic_string(size_type __n, _CharT __c,
103 const _Allocator& __a = _Allocator())
104 : _Base(__n, __c, __a)
107 template<
typename _InputIterator>
108 basic_string(_InputIterator __begin, _InputIterator __end,
109 const _Allocator& __a = _Allocator())
110 : _Base(__gnu_debug::__check_valid_range(__begin, __end), __end, __a)
113 #ifdef __GXX_EXPERIMENTAL_CXX0X__
114 basic_string(initializer_list<_CharT> __l,
const _Alloc& __a = _Alloc())
117 #endif // __GXX_EXPERIMENTAL_CXX0X__
122 operator=(
const basic_string& __str)
124 *
static_cast<_Base*
>(
this) = __str;
125 this->_M_invalidate_all();
130 operator=(
const _CharT* __s)
132 __glibcxx_check_string(__s);
133 *
static_cast<_Base*
>(
this) = __s;
134 this->_M_invalidate_all();
139 operator=(_CharT __c)
141 *
static_cast<_Base*
>(
this) = __c;
142 this->_M_invalidate_all();
146 #ifdef __GXX_EXPERIMENTAL_CXX0X__
148 operator=(initializer_list<_CharT> __l)
150 *
static_cast<_Base*
>(
this) = __l;
151 this->_M_invalidate_all();
154 #endif // __GXX_EXPERIMENTAL_CXX0X__
171 {
return const_iterator(
_Base::end(),
this); }
175 {
return reverse_iterator(end()); }
177 const_reverse_iterator
179 {
return const_reverse_iterator(end()); }
183 {
return reverse_iterator(begin()); }
185 const_reverse_iterator
187 {
return const_reverse_iterator(begin()); }
195 resize(size_type __n, _CharT __c)
198 this->_M_invalidate_all();
202 resize(size_type __n)
203 { this->resize(__n, _CharT()); }
212 this->_M_invalidate_all();
219 operator[](size_type __pos)
const
222 _M_message(__gnu_debug::__msg_subscript_oob)
223 ._M_sequence(*
this,
"this")
224 ._M_integer(__pos,
"__pos")
225 ._M_integer(this->size(),
"size"));
226 return _M_base()[__pos];
230 operator[](size_type __pos)
232 #ifdef _GLIBCXX_DEBUG_PEDANTIC
233 __glibcxx_check_subscript(__pos);
237 _M_message(__gnu_debug::__msg_subscript_oob)
238 ._M_sequence(*
this,
"this")
239 ._M_integer(__pos,
"__pos")
240 ._M_integer(this->size(),
"size"));
242 return _M_base()[__pos];
249 operator+=(
const basic_string& __str)
252 this->_M_invalidate_all();
257 operator+=(
const _CharT* __s)
259 __glibcxx_check_string(__s);
261 this->_M_invalidate_all();
266 operator+=(_CharT __c)
269 this->_M_invalidate_all();
273 #ifdef __GXX_EXPERIMENTAL_CXX0X__
275 operator+=(initializer_list<_CharT> __l)
278 this->_M_invalidate_all();
281 #endif // __GXX_EXPERIMENTAL_CXX0X__
284 append(
const basic_string& __str)
287 this->_M_invalidate_all();
292 append(
const basic_string& __str, size_type __pos, size_type __n)
295 this->_M_invalidate_all();
300 append(
const _CharT* __s, size_type __n)
302 __glibcxx_check_string_len(__s, __n);
304 this->_M_invalidate_all();
309 append(
const _CharT* __s)
311 __glibcxx_check_string(__s);
313 this->_M_invalidate_all();
318 append(size_type __n, _CharT __c)
321 this->_M_invalidate_all();
325 template<
typename _InputIterator>
327 append(_InputIterator __first, _InputIterator __last)
329 __glibcxx_check_valid_range(__first, __last);
331 this->_M_invalidate_all();
338 push_back(_CharT __c)
341 this->_M_invalidate_all();
345 assign(
const basic_string& __x)
348 this->_M_invalidate_all();
353 assign(
const basic_string& __str, size_type __pos, size_type __n)
356 this->_M_invalidate_all();
361 assign(
const _CharT* __s, size_type __n)
363 __glibcxx_check_string_len(__s, __n);
365 this->_M_invalidate_all();
370 assign(
const _CharT* __s)
372 __glibcxx_check_string(__s);
374 this->_M_invalidate_all();
379 assign(size_type __n, _CharT __c)
382 this->_M_invalidate_all();
386 template<
typename _InputIterator>
388 assign(_InputIterator __first, _InputIterator __last)
390 __glibcxx_check_valid_range(__first, __last);
392 this->_M_invalidate_all();
396 #ifdef __GXX_EXPERIMENTAL_CXX0X__
398 assign(initializer_list<_CharT> __l)
401 this->_M_invalidate_all();
404 #endif // __GXX_EXPERIMENTAL_CXX0X__
407 insert(size_type __pos1,
const basic_string& __str)
410 this->_M_invalidate_all();
415 insert(size_type __pos1,
const basic_string& __str,
416 size_type __pos2, size_type __n)
419 this->_M_invalidate_all();
424 insert(size_type __pos,
const _CharT* __s, size_type __n)
426 __glibcxx_check_string(__s);
428 this->_M_invalidate_all();
433 insert(size_type __pos,
const _CharT* __s)
435 __glibcxx_check_string(__s);
437 this->_M_invalidate_all();
442 insert(size_type __pos, size_type __n, _CharT __c)
445 this->_M_invalidate_all();
450 insert(iterator __p, _CharT __c)
453 typename _Base::iterator __res =
_Base::insert(__p.base(), __c);
454 this->_M_invalidate_all();
455 return iterator(__res,
this);
459 insert(iterator __p, size_type __n, _CharT __c)
463 this->_M_invalidate_all();
466 template<
typename _InputIterator>
468 insert(iterator __p, _InputIterator __first, _InputIterator __last)
472 this->_M_invalidate_all();
475 #ifdef __GXX_EXPERIMENTAL_CXX0X__
477 insert(iterator __p, initializer_list<_CharT> __l)
480 this->_M_invalidate_all();
482 #endif // __GXX_EXPERIMENTAL_CXX0X__
485 erase(size_type __pos = 0, size_type __n =
_Base::npos)
488 this->_M_invalidate_all();
493 erase(iterator __position)
496 typename _Base::iterator __res =
_Base::erase(__position.base());
497 this->_M_invalidate_all();
498 return iterator(__res,
this);
502 erase(iterator __first, iterator __last)
507 typename _Base::iterator __res =
_Base::erase(__first.base(),
509 this->_M_invalidate_all();
510 return iterator(__res,
this);
514 replace(size_type __pos1, size_type __n1,
const basic_string& __str)
517 this->_M_invalidate_all();
522 replace(size_type __pos1, size_type __n1,
const basic_string& __str,
523 size_type __pos2, size_type __n2)
526 this->_M_invalidate_all();
531 replace(size_type __pos, size_type __n1,
const _CharT* __s,
534 __glibcxx_check_string_len(__s, __n2);
536 this->_M_invalidate_all();
541 replace(size_type __pos, size_type __n1,
const _CharT* __s)
543 __glibcxx_check_string(__s);
545 this->_M_invalidate_all();
550 replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
553 this->_M_invalidate_all();
558 replace(iterator __i1, iterator __i2,
const basic_string& __str)
562 this->_M_invalidate_all();
567 replace(iterator __i1, iterator __i2,
const _CharT* __s, size_type __n)
570 __glibcxx_check_string_len(__s, __n);
572 this->_M_invalidate_all();
577 replace(iterator __i1, iterator __i2,
const _CharT* __s)
580 __glibcxx_check_string(__s);
582 this->_M_invalidate_all();
587 replace(iterator __i1, iterator __i2, size_type __n, _CharT __c)
591 this->_M_invalidate_all();
595 template<
typename _InputIterator>
597 replace(iterator __i1, iterator __i2,
598 _InputIterator __j1, _InputIterator __j2)
601 __glibcxx_check_valid_range(__j1, __j2);
603 this->_M_invalidate_all();
607 #ifdef __GXX_EXPERIMENTAL_CXX0X__
608 basic_string& replace(iterator __i1, iterator __i2,
609 initializer_list<_CharT> __l)
613 this->_M_invalidate_all();
616 #endif // __GXX_EXPERIMENTAL_CXX0X__
619 copy(_CharT* __s, size_type __n, size_type __pos = 0)
const
621 __glibcxx_check_string_len(__s, __n);
626 swap(basic_string<_CharT,_Traits,_Allocator>& __x)
630 this->_M_invalidate_all();
631 __x._M_invalidate_all();
639 this->_M_invalidate_all();
647 this->_M_invalidate_all();
654 find(
const basic_string& __str, size_type __pos = 0)
const
658 find(
const _CharT* __s, size_type __pos, size_type __n)
const
660 __glibcxx_check_string(__s);
665 find(
const _CharT* __s, size_type __pos = 0)
const
667 __glibcxx_check_string(__s);
672 find(_CharT __c, size_type __pos = 0)
const
676 rfind(
const basic_string& __str, size_type __pos =
_Base::npos)
const
680 rfind(
const _CharT* __s, size_type __pos, size_type __n)
const
682 __glibcxx_check_string_len(__s, __n);
687 rfind(
const _CharT* __s, size_type __pos =
_Base::npos)
const
689 __glibcxx_check_string(__s);
694 rfind(_CharT __c, size_type __pos =
_Base::npos)
const
698 find_first_of(
const basic_string& __str, size_type __pos = 0)
const
702 find_first_of(
const _CharT* __s, size_type __pos, size_type __n)
const
704 __glibcxx_check_string(__s);
709 find_first_of(
const _CharT* __s, size_type __pos = 0)
const
711 __glibcxx_check_string(__s);
716 find_first_of(_CharT __c, size_type __pos = 0)
const
720 find_last_of(
const basic_string& __str,
725 find_last_of(
const _CharT* __s, size_type __pos, size_type __n)
const
727 __glibcxx_check_string(__s);
732 find_last_of(
const _CharT* __s, size_type __pos =
_Base::npos)
const
734 __glibcxx_check_string(__s);
739 find_last_of(_CharT __c, size_type __pos =
_Base::npos)
const
743 find_first_not_of(
const basic_string& __str, size_type __pos = 0)
const
747 find_first_not_of(
const _CharT* __s, size_type __pos, size_type __n)
const
749 __glibcxx_check_string_len(__s, __n);
754 find_first_not_of(
const _CharT* __s, size_type __pos = 0)
const
756 __glibcxx_check_string(__s);
761 find_first_not_of(_CharT __c, size_type __pos = 0)
const
765 find_last_not_of(
const basic_string& __str,
770 find_last_not_of(
const _CharT* __s, size_type __pos, size_type __n)
const
772 __glibcxx_check_string(__s);
777 find_last_not_of(
const _CharT* __s, size_type __pos =
_Base::npos)
const
779 __glibcxx_check_string(__s);
784 find_last_not_of(_CharT __c, size_type __pos =
_Base::npos)
const
788 substr(size_type __pos = 0, size_type __n =
_Base::npos)
const
792 compare(
const basic_string& __str)
const
796 compare(size_type __pos1, size_type __n1,
797 const basic_string& __str)
const
801 compare(size_type __pos1, size_type __n1,
const basic_string& __str,
802 size_type __pos2, size_type __n2)
const
806 compare(
const _CharT* __s)
const
808 __glibcxx_check_string(__s);
815 compare(size_type __pos1, size_type __n1,
const _CharT* __s)
const
817 __glibcxx_check_string(__s);
824 compare(size_type __pos1, size_type __n1,
const _CharT* __s,
825 size_type __n2)
const
827 __glibcxx_check_string_len(__s, __n2);
832 _M_base() {
return *
this; }
835 _M_base()
const {
return *
this; }
840 template<
typename _CharT,
typename _Traits,
typename _Allocator>
841 inline basic_string<_CharT,_Traits,_Allocator>
842 operator+(
const basic_string<_CharT,_Traits,_Allocator>& __lhs,
843 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
844 {
return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs; }
846 template<
typename _CharT,
typename _Traits,
typename _Allocator>
847 inline basic_string<_CharT,_Traits,_Allocator>
848 operator+(
const _CharT* __lhs,
849 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
851 __glibcxx_check_string(__lhs);
852 return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs;
855 template<
typename _CharT,
typename _Traits,
typename _Allocator>
856 inline basic_string<_CharT,_Traits,_Allocator>
857 operator+(_CharT __lhs,
858 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
859 {
return basic_string<_CharT,_Traits,_Allocator>(1, __lhs) += __rhs; }
861 template<
typename _CharT,
typename _Traits,
typename _Allocator>
862 inline basic_string<_CharT,_Traits,_Allocator>
863 operator+(
const basic_string<_CharT,_Traits,_Allocator>& __lhs,
866 __glibcxx_check_string(__rhs);
867 return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs;
870 template<
typename _CharT,
typename _Traits,
typename _Allocator>
871 inline basic_string<_CharT,_Traits,_Allocator>
872 operator+(
const basic_string<_CharT,_Traits,_Allocator>& __lhs,
874 {
return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs; }
876 template<
typename _CharT,
typename _Traits,
typename _Allocator>
878 operator==(
const basic_string<_CharT,_Traits,_Allocator>& __lhs,
879 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
880 {
return __lhs._M_base() == __rhs._M_base(); }
882 template<
typename _CharT,
typename _Traits,
typename _Allocator>
884 operator==(
const _CharT* __lhs,
885 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
887 __glibcxx_check_string(__lhs);
888 return __lhs == __rhs._M_base();
891 template<
typename _CharT,
typename _Traits,
typename _Allocator>
893 operator==(
const basic_string<_CharT,_Traits,_Allocator>& __lhs,
896 __glibcxx_check_string(__rhs);
897 return __lhs._M_base() == __rhs;
900 template<
typename _CharT,
typename _Traits,
typename _Allocator>
902 operator!=(
const basic_string<_CharT,_Traits,_Allocator>& __lhs,
903 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
904 {
return __lhs._M_base() != __rhs._M_base(); }
906 template<
typename _CharT,
typename _Traits,
typename _Allocator>
908 operator!=(
const _CharT* __lhs,
909 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
911 __glibcxx_check_string(__lhs);
912 return __lhs != __rhs._M_base();
915 template<
typename _CharT,
typename _Traits,
typename _Allocator>
917 operator!=(
const basic_string<_CharT,_Traits,_Allocator>& __lhs,
920 __glibcxx_check_string(__rhs);
921 return __lhs._M_base() != __rhs;
924 template<
typename _CharT,
typename _Traits,
typename _Allocator>
926 operator<(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
927 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
928 {
return __lhs._M_base() < __rhs._M_base(); }
930 template<
typename _CharT,
typename _Traits,
typename _Allocator>
932 operator<(
const _CharT* __lhs,
933 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
935 __glibcxx_check_string(__lhs);
936 return __lhs < __rhs._M_base();
939 template<
typename _CharT,
typename _Traits,
typename _Allocator>
941 operator<(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
944 __glibcxx_check_string(__rhs);
945 return __lhs._M_base() < __rhs;
948 template<
typename _CharT,
typename _Traits,
typename _Allocator>
950 operator<=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
951 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
952 {
return __lhs._M_base() <= __rhs._M_base(); }
954 template<
typename _CharT,
typename _Traits,
typename _Allocator>
956 operator<=(
const _CharT* __lhs,
957 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
959 __glibcxx_check_string(__lhs);
960 return __lhs <= __rhs._M_base();
963 template<
typename _CharT,
typename _Traits,
typename _Allocator>
965 operator<=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
968 __glibcxx_check_string(__rhs);
969 return __lhs._M_base() <= __rhs;
972 template<
typename _CharT,
typename _Traits,
typename _Allocator>
974 operator>=(
const basic_string<_CharT,_Traits,_Allocator>& __lhs,
975 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
976 {
return __lhs._M_base() >= __rhs._M_base(); }
978 template<
typename _CharT,
typename _Traits,
typename _Allocator>
980 operator>=(
const _CharT* __lhs,
981 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
983 __glibcxx_check_string(__lhs);
984 return __lhs >= __rhs._M_base();
987 template<
typename _CharT,
typename _Traits,
typename _Allocator>
989 operator>=(
const basic_string<_CharT,_Traits,_Allocator>& __lhs,
992 __glibcxx_check_string(__rhs);
993 return __lhs._M_base() >= __rhs;
996 template<
typename _CharT,
typename _Traits,
typename _Allocator>
998 operator>(
const basic_string<_CharT,_Traits,_Allocator>& __lhs,
999 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1000 {
return __lhs._M_base() > __rhs._M_base(); }
1002 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1004 operator>(
const _CharT* __lhs,
1005 const basic_string<_CharT,_Traits,_Allocator>& __rhs)
1007 __glibcxx_check_string(__lhs);
1008 return __lhs > __rhs._M_base();
1011 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1013 operator>(
const basic_string<_CharT,_Traits,_Allocator>& __lhs,
1014 const _CharT* __rhs)
1016 __glibcxx_check_string(__rhs);
1017 return __lhs._M_base() > __rhs;
1021 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1023 swap(basic_string<_CharT,_Traits,_Allocator>& __lhs,
1024 basic_string<_CharT,_Traits,_Allocator>& __rhs)
1025 { __lhs.swap(__rhs); }
1027 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1029 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1030 const basic_string<_CharT, _Traits, _Allocator>& __str)
1031 {
return __os << __str._M_base(); }
1033 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1036 basic_string<_CharT,_Traits,_Allocator>& __str)
1039 __str._M_invalidate_all();
1043 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1046 basic_string<_CharT,_Traits,_Allocator>& __str, _CharT __delim)
1051 __str._M_invalidate_all();
1055 template<
typename _CharT,
typename _Traits,
typename _Allocator>
1058 basic_string<_CharT,_Traits,_Allocator>& __str)
1062 __str._M_invalidate_all();
1066 typedef basic_string<char> string;
1068 #ifdef _GLIBCXX_USE_WCHAR_T
1069 typedef basic_string<wchar_t> wstring;
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
Find last position of a character not in string.
size_type capacity() const
#define __glibcxx_check_insert_range(_Position, _First, _Last)
#define __glibcxx_check_erase(_Position)
void reserve(size_type __res_arg=0)
Attempt to preallocate enough memory for specified number of characters.
allocator_type get_allocator() const
Return copy of allocator used to construct this string.
#define _GLIBCXX_DEBUG_VERIFY(_Condition, _ErrorMessage)
const _CharT * c_str() const
Return const pointer to null-terminated contents.
void insert(iterator __p, size_type __n, _CharT __c)
Insert multiple characters.
size_type length() const
Returns the number of characters in the string, not including any null-termination.
size_type find_last_of(const basic_string &__str, size_type __pos=npos) const
Find last position of a character of string.
size_type find_first_of(const basic_string &__str, size_type __pos=0) const
Find position of a character of string.
size_type find(const _CharT *__s, size_type __pos, size_type __n) const
Find position of a C substring.
const _CharT * data() const
Return const pointer to contents.
Base class for constructing a "safe" sequence type that tracks iterators that reference it...
void resize(size_type __n, _CharT __c)
Resizes the string to the specified number of characters.
size_type max_size() const
Returns the size() of the largest possible string.
size_type size() const
Returns the number of characters in the string, not including any null-termination.
void _M_invalidate_all() const
void swap(basic_string &__s)
Swap contents with another string.
Controlling output.This is the base class for all output streams. It provides text formatting of all ...
const _CharT * __check_string(const _CharT *__s, const _Integer &__n __attribute__((__unused__)))
void push_back(_CharT __c)
Append a single character.
#define __glibcxx_check_erase_range(_First, _Last)
basic_string & replace(size_type __pos, size_type __n, const basic_string &__str)
Replace characters with value from another string.
basic_string substr(size_type __pos=0, size_type __n=npos) const
Get a substring.
const_reference at(size_type __n) const
Provides access to the data contained in the string.
size_type rfind(const basic_string &__str, size_type __pos=npos) const
Find last position of a string.
static const size_type npos
Value returned by various member functions when they fail.
size_type find_first_not_of(const basic_string &__str, size_type __pos=0) const
Find position of a character not in string.
size_type copy(_CharT *__s, size_type __n, size_type __pos=0) const
Copy substring into C string.
#define __glibcxx_check_insert(_Position)
basic_string & erase(size_type __pos=0, size_type __n=npos)
Remove characters.
basic_string & append(const basic_string &__str)
Append a string to this string.
Controlling input.This is the base class for all input streams. It provides text formatting of all bu...
Managing sequences of characters and character-like objects.
int compare(const basic_string &__str) const
Compare to a string.