33# pragma warning (push)
34# pragma warning (disable: 4345)
41#ifndef _RWSTD_NO_STATIC_CONST_MEMBER_INIT
42# if !defined (_RWSTD_MSVC) || _RWSTD_MSVC > 1300
47# ifndef _RWSTD_NO_STRING_NPOS_TYPE
49template <
class _CharT,
class _Traits,
class _Allocator>
50const typename basic_string<_CharT, _Traits, _Allocator>::size_type
51basic_string<_CharT, _Traits, _Allocator>::
56template <
class _CharT,
class _Traits,
class _Allocator>
58basic_string<_CharT, _Traits, _Allocator>::
66#ifndef _RWSTD_NO_COLLAPSE_TEMPLATE_STATICS
68template <
class _CharT,
class _Traits,
class _Allocator>
69_RW::__null_ref<_CharT, _Traits, _Allocator>
70basic_string<_CharT, _Traits, _Allocator>::
76template <
class _CharT,
class _Traits,
class _Allocator>
77typename basic_string<_CharT, _Traits, _Allocator>::_C_string_ref_type*
78basic_string<_CharT, _Traits, _Allocator>::
79_C_get_rep (size_type __cap, size_type __len)
81 if (__cap > max_size ()) {
86 _RWSTD_FUNC (
"basic_string::_C_get_rep (size_type, "
93 _RWSTD_FUNC (
"basic_string::_C_get_rep (size_type, "
103 _C_string_ref_type*
const __ret =
107 allocate ( __cap +
sizeof (_C_string_ref_type)
108 /
sizeof (value_type) + 2))));
112 new (__ret) _C_string_ref_type ();
115 __ret->_C_init (__cap, __len);
118 construct (__ret->data () + __len, value_type ()));
124template <
class _CharT,
class _Traits,
class _Allocator>
125basic_string<_CharT, _Traits, _Allocator>::
126basic_string (
const basic_string &__s, size_type __pos, size_type __n,
127 const allocator_type& __alloc )
128 : allocator_type (__alloc)
133 "basic_string&, size_type, size_type)"),
134 __pos, __s.size ()));
136 size_type __slen = __s.size () - __pos;
137 size_type __rlen = __n < __slen ? __n : __slen;
138 size_type __nlen = __n == npos ? 0 : __n;
139 size_type __maxlen = __nlen > __rlen ? __nlen : __rlen;
141 _C_data = _C_get_rep (_C_grow (size_type (), __maxlen),
144 _C_data = _C_get_rep (__maxlen, __rlen)->data ();
146 traits_type::copy (_C_data, &__s._C_data [__pos], __rlen);
150template <
class _CharT,
class _Traits,
class _Allocator>
151basic_string<_CharT, _Traits, _Allocator>::
152basic_string (size_type __n, value_type __c,
153 const allocator_type &__alloc )
154 : allocator_type (__alloc)
158 _RWSTD_FUNC (
"basic_string::basic_string (size_type, "
163 _C_data = _C_get_rep (_C_grow (size_type (), __n), __n)->data ();
165 _C_data = _C_nullref ()->data ();
167 traits_type::assign (_C_data, __n, __c);
171template <
class _CharT,
class _Traits,
class _Allocator>
172basic_string<_CharT, _Traits, _Allocator>::
173basic_string (const_pointer __s, size_type __n,
174 const allocator_type &__alloc )
175 : allocator_type (__alloc)
181 _RWSTD_FUNC (
"basic_string::basic_string (const_pointer,"
182 "size_type, const allocator_type&)"),
186 _C_get_rep (_C_grow (size_type (), __n), __n)->data ()
187 : _C_nullref ()->data ();
190 traits_type::copy (_C_data, __s, __n);
194template <
class _CharT,
class _Traits,
class _Allocator>
195basic_string<_CharT, _Traits, _Allocator>::
196basic_string (const_pointer __s,
197 const allocator_type &__alloc )
198 : allocator_type (__alloc)
202 const size_type __n = traits_type::length (__s);
205 _C_get_rep (_C_grow (size_type (), __n), __n)->data ()
206 : _C_nullref ()->data ();
208 traits_type::copy (_C_data, __s, __n);
212template <
class _CharT,
class _Traits,
class _Allocator>
213basic_string<_CharT, _Traits, _Allocator>::
214basic_string (const_pointer __first, const_pointer __last,
215 const allocator_type &__alloc )
216 : allocator_type (__alloc)
218 const size_type __n = size_type (__last - __first);
221 _C_get_rep (_C_grow (size_type (), __n), __n)->data ()
222 : _C_nullref ()->data ();
224 traits_type::copy (_C_data, __first, __n);
228template <
class _CharT,
class _Traits,
class _Allocator>
229basic_string<_CharT, _Traits, _Allocator>&
230basic_string<_CharT, _Traits, _Allocator>::
231operator= (
const basic_string &__rhs)
233 if (size_type (0) < size_type (__rhs._C_pref ()->_C_get_ref ())) {
235 __rhs._C_pref ()->_C_inc_ref ();
236 _C_unlink (__rhs._C_data);
238 else if (
this != &__rhs)
240 replace (size_type (),
size (), __rhs.data (), __rhs.size ());
246template <
class _CharT,
class _Traits,
class _Allocator>
247basic_string<_CharT, _Traits, _Allocator>&
248basic_string<_CharT, _Traits, _Allocator>::
249assign (
const basic_string &__str, size_type __pos, size_type __n)
253 _RWSTD_FUNC (
"basic_string::assign (basic_string&, "
254 "size_type, size_type)"),
255 __pos, __str.size ()));
257 const size_type __rlen = _C_min (__str.size () - __pos, __n);
259 return replace (size_type (),
size (), __str, __pos, __rlen);
263template <
class _CharT,
class _Traits,
class _Allocator>
264basic_string<_CharT, _Traits, _Allocator>&
265basic_string<_CharT, _Traits, _Allocator>::
266insert (size_type __pos1,
267 const basic_string& __str, size_type __pos2, size_type __n)
271 _RWSTD_FUNC (
"basic_string::insert (size_type, const "
272 "basic_string&, size_type, size_type)"),
273 __pos1 >
size () ? __pos1:__pos2, __str.size ()));
275 const size_type __rlen = _C_min (__str.size () - __pos2, __n);
279 _RWSTD_FUNC (
"basic_string::insert (size_type, const "
280 "basic_string&, size_type, size_type)"),
281 size (), max_size () - __rlen));
283 return replace (__pos1, size_type (), __str, __pos2, __n);
287template <
class _CharT,
class _Traits,
class _Allocator>
288basic_string<_CharT, _Traits, _Allocator>&
289basic_string<_CharT, _Traits, _Allocator>::
290insert (size_type __pos1,
const basic_string &__str)
294 _RWSTD_FUNC (
"basic_string::insert (size_type, const "
301 "const basic_string&)"),
302 size (), max_size () - __str.size ()));
304 return replace (__pos1, size_type (), __str);
308template <
class _CharT,
class _Traits,
class _Allocator>
309basic_string<_CharT, _Traits, _Allocator>&
310basic_string<_CharT, _Traits, _Allocator>::
311replace (size_type __pos1, size_type __n1, const_pointer __s, size_type __n2)
313 const size_type __size0 =
size ();
316 __n2 = traits_type::length (__s);
320 _RWSTD_FUNC (
"basic_string::replace (size_type, size_type"
321 ", const_pointer, size_type)"),
322 __pos1, __size0 > __n2 ? __size0 : __n2));
325 const size_type __xlen = _C_min (__n1, __size0 - __pos1);
329 _RWSTD_FUNC (
"basic_string::replace (size_type, size_type"
330 ", const_pointer, size_type)"),
335 _RWSTD_FUNC (
"basic_string::replace (size_type, size_type"
336 ", const_pointer, size_type)"),
337 __size0 - __xlen, max_size () - __n2));
340 const size_type __size1 = __size0 - __xlen + __n2;
345 const size_type __rem = __size0 - __xlen - __pos1;
349 if ( size_type (1) < size_type (_C_pref ()->_C_get_ref ())
350 || capacity () < __size1
351 || __s >=
data () && __s <
data () + __size0) {
354 const size_type __cap = _C_grow (__size0, __size1);
356 const pointer __data = _C_get_rep (__cap, __size1)->data ();
358 traits_type::copy (__data, _C_data, __pos1);
360 traits_type::copy (__data + __pos1, __s, __n2);
362 traits_type::copy (__data + __pos1 + __n2,
363 _C_data + __pos1 + __n1, __rem);
370 const pointer __beg = _C_data + __pos1;
372 traits_type::move (__beg + __n2, __beg + __n1, __rem);
374 traits_type::copy (__beg, __s, __n2);
376 traits_type::assign (_C_data [__size1], value_type ());
378 _C_pref ()->_C_size._C_size = __size1;
390template <
class _CharT,
class _Traits,
class _Allocator>
391basic_string<_CharT, _Traits, _Allocator>&
392basic_string<_CharT, _Traits, _Allocator>::
393replace (size_type __pos, size_type __len, size_type __count, value_type __val)
398 const size_type __size0 =
size ();
403 "size_type, size_type, value_type)"),
406 const size_type __xlen = _C_min (__size0 - __pos, __len);
411 "size_type, size_type, value_type)"),
412 __size0 - __xlen, max_size () - __count));
415 const size_type __size1 = __size0 - __xlen + __count;
420 const size_type __rem = __size0 - __xlen - __pos;
423 if ( capacity () < __size1
424 || size_type (1) < size_type (_C_pref ()->_C_get_ref ())) {
427 const size_type __cap = _C_grow (__size0, __size1);
429 const pointer __data = _C_get_rep (__cap, __size1)->data ();
431 traits_type::copy (__data, _C_data, __pos);
433 traits_type::assign (__data + __pos, __count, __val);
435 traits_type::copy (__data + (__pos + __count),
436 _C_data + (__pos + __len), __rem);
443 const pointer __beg = _C_data + __pos;
445 traits_type::move (__beg + __count, __beg + __len, __rem);
447 traits_type::assign (__beg, __count, __val);
450 traits_type::assign (_C_data [__size1], value_type ());
452 _C_pref ()->_C_size._C_size = __size1;
464#ifdef _RWSTD_NO_STRING_OUTLINED_MEMBER_TEMPLATES
467template <
class _CharT,
class _Traits,
class _Alloc,
468 class _StringIter,
class _InputIter>
469_STD::basic_string<_CharT, _Traits, _Alloc>&
470__rw_replace (_STD::basic_string<_CharT, _Traits, _Alloc> &__s,
471 _StringIter __first1, _StringIter __last1,
472 _InputIter __first2, _InputIter __last2) {
474 typedef _Traits traits_type;
475 typedef typename traits_type::char_type value_type;
476 typedef _Alloc allocator_type;
477 typedef typename allocator_type::size_type size_type;
479 typedef _STD::basic_string<_CharT, _Traits, _Alloc> _C_string_type;
481 typedef _RW::__string_ref<value_type, traits_type, allocator_type>
487template<
class _CharT,
class _Traits,
class _Allocator>
488template<
class _InputIter>
489basic_string<_CharT, _Traits, _Allocator>&
490basic_string<_CharT, _Traits, _Allocator>::
491replace (iterator __first1, iterator __last1,
492 _InputIter __first2, _InputIter __last2,
void*)
494 typedef basic_string _C_string_type;
496 basic_string &__s = *
this;
501 __s._C_make_iter (__s._C_data + __s.size ()));
505 if (__first2 == __last2) {
506 if (__first1 == __last1)
509 const size_type __pos = __s._C_off (__first1);
510 const size_type __n = __s._C_off (__first1, __last1);
511 return __s.replace (__pos, __n, size_type (), value_type ());
517 return __s.__replace_aux (__first1, __last1, __first2, __last2);
520 typename _C_string_type::iterator __first3 = __s3.begin ();
522 for ( ; !(__first2 == __last2); ++__first2, ++__first3) {
524 const size_type __off = __s3._C_off (__first3);
529 "iterator, InputIterator, "
531 __s3._C_off (__first3), __s3.max_size ()));
534 if (__s3.end () == __first3) {
536 const size_type __cap = __s3._C_grow (__s3.size (), size_type ());
539 _C_string_ref_type *__tmp = __s3._C_get_rep (__cap, __cap);
542 traits_type::copy (__tmp->data (), __s3._C_data, __off);
543 __s3._C_unlink (__tmp->data ());
544 __first3 = __s3._C_make_iter (__s3._C_data + __off);
548 traits_type::assign (*__first3, *__first2);
551 const size_type __size = __s3._C_off (__first3);
552 traits_type::assign (__s3._C_data [__size], value_type ());
553 __s3._C_pref ()->_C_size._C_size = __size;
555 return __s.__replace_aux (__first1, __last1, __s3.begin (), __s3.end ());
562#ifdef _RWSTD_NO_STRING_OUTLINED_MEMBER_TEMPLATES
565template <
class _CharT,
class _Traits,
class _Alloc,
566 class _StringIter,
class _InputIter>
567_STD::basic_string<_CharT, _Traits, _Alloc>&
568__rw_replace_aux (_STD::basic_string<_CharT, _Traits, _Alloc> &__s,
569 _StringIter __first1, _StringIter __last1,
570 _InputIter __first2, _InputIter __last2)
572 typedef _Traits traits_type;
573 typedef typename traits_type::char_type value_type;
574 typedef _Alloc allocator_type;
575 typedef typename allocator_type::size_type size_type;
576 typedef typename allocator_type::difference_type difference_type;
577 typedef typename allocator_type::pointer pointer;
578 typedef typename allocator_type::const_pointer const_pointer;
579 typedef typename allocator_type::const_reference const_reference;
581 typedef _RW::__string_ref<value_type, traits_type, allocator_type>
586template<
class _CharT,
class _Traits,
class _Allocator>
587template<
class _InputIter>
588basic_string<_CharT, _Traits, _Allocator>&
589basic_string<_CharT, _Traits, _Allocator>::
590__replace_aux (iterator __first1, iterator __last1,
591 _InputIter __first2, _InputIter __last2)
593 basic_string &__s = *
this;
602 const size_type __n2 =
_DISTANCE (__first2, __last2, size_type);
603 const size_type __n = __s._C_off (__first1, __last1);
604 const size_type __pos = __s._C_off (__first1);
605 const size_type __ssize = __s.size ();
609 _RWSTD_FUNC (
"basic_string::__replace_aux (iterator, "
610 "iterator, InputIterator, InputIterator)"),
613 size_type __slen = __ssize - __pos;
614 size_type __xlen = __n < __slen ? __n : __slen;
618 _RWSTD_FUNC (
"basic_string::__replace_aux (iterator, "
619 "iterator, InputIterator, InputIterator)"),
620 __ssize - __xlen, __s.max_size () - __n2));
622 size_type __len = __ssize - __xlen + __n2;
626 __s._C_unlink (__s._C_nullref ()->data ());
631 size_type __rem = __ssize - __xlen - __pos;
633 if ( __s.capacity () < __len
634 || size_type (1) < size_type (__s._C_pref ()->_C_get_ref ()))
637 const size_type __cap = __s._C_grow (__ssize, __len);
639 _C_string_ref_type * __temp = __s._C_get_rep (__cap, __len);
641 traits_type::copy (__temp->data (), __s._C_data, __pos);
642 for (__d = 0; __d < __n2; __d++)
643 traits_type::assign (*(__temp->data ()+__pos + __d),
646 traits_type::copy (__temp->data () + __pos + __n2,
647 __s._C_data + __pos + __n, __rem);
648 __s._C_unlink (__temp->data ());
653 traits_type::move (__s._C_data + __pos + __n2,
654 __s._C_data + __pos + __n,
657 for (__d = 0; __d < __n2; __d++)
658 traits_type::assign (*(__s._C_data + __pos + __d),
661 __s._C_pref ()->_C_size._C_size = __len;
662 traits_type::assign (__s._C_data [__len], value_type ());
669template <
class _CharT,
class _Traits,
class _Allocator>
670typename basic_string<_CharT, _Traits, _Allocator>::size_type
671basic_string<_CharT, _Traits, _Allocator>::
672copy (pointer __s, size_type __n, size_type __pos)
const
676 _RWSTD_FUNC (
"basic_string::copy (pointer, size_type, "
680 const size_type __rlen = _C_min (
size () - __pos, __n);
682 traits_type::copy (__s, _C_data + __pos, __rlen);
688template <
class _CharT,
class _Traits,
class _Allocator>
689typename basic_string<_CharT, _Traits, _Allocator>::size_type
690basic_string<_CharT, _Traits, _Allocator>::
691find (const_pointer __seq, size_type __off, size_type __len)
const
693 const size_type __size =
size ();
700 const const_pointer __end = _C_data + __size;
701 const const_pointer __seq_end = __seq + __len;
706 const_pointer __first = const_pointer ();
708 for (const_pointer __next = _C_data + __off; ; __next = __first) {
712 const size_type __ext = size_type (__end - __next);
717 __first = const_pointer ();
719 for (const_pointer __n = __next, __s = __seq; ; ++__n, ++__s) {
721 if (__seq_end == __s)
722 return size_type (__next - _C_data);
724 if (traits_type::eq (*__n, *__s)) {
725 if (const_pointer () == __first && __n != __next && traits_type::eq (*__n, *__seq))
729 if (const_pointer () == __first) {
733 __first = traits_type::find (__n, __end - __n, *__seq);
735 if (const_pointer () == __first)
747template <
class _CharT,
class _Traits,
class _Allocator>
748typename basic_string<_CharT, _Traits, _Allocator>::size_type
749basic_string<_CharT, _Traits, _Allocator>::
750rfind (const_pointer __s, size_type __pos, size_type __n)
const
757 size_type __slen =
size () - __n;
758 size_type __xpos_start = __slen < __pos ? __slen : __pos;
760 for (size_type __xpos = __xpos_start + 1; __xpos != 0 ; __xpos--) {
761 if (!traits_type::compare (_C_data + __xpos - 1, __s, __n))
769template <
class _CharT,
class _Traits,
class _Allocator>
770typename basic_string<_CharT, _Traits, _Allocator>::size_type
771basic_string<_CharT, _Traits, _Allocator>::
772find_first_of (const_pointer __s, size_type __pos, size_type __n)
const
776 for (size_type __xpos = __pos; __xpos <
size () ; __xpos++) {
777 for (size_type __i = 0; __i < __n ; __i++)
778 if (traits_type::eq (_C_data [__xpos], __s [__i]))
786template <
class _CharT,
class _Traits,
class _Allocator>
787typename basic_string<_CharT, _Traits, _Allocator>::size_type
788basic_string<_CharT, _Traits, _Allocator>::
789find_last_of (const_pointer __s, size_type __pos, size_type __n)
const
794 size_type __slen =
size () - 1;
795 size_type __xpos_start = __pos < __slen ? __pos : __slen;
796 for (size_type __xpos = __xpos_start+1; __xpos != 0 ; __xpos--) {
797 for (size_type __i = 0; __i < __n ; __i++)
798 if (traits_type::eq (_C_data [__xpos - 1], __s [__i]))
807template <
class _CharT,
class _Traits,
class _Allocator>
808typename basic_string<_CharT, _Traits, _Allocator>::size_type
809basic_string<_CharT, _Traits, _Allocator>::
810find_first_not_of (const_pointer __s, size_type __pos, size_type __n)
const
814 for (size_type __xpos = __pos; __xpos <
size () ; __xpos++) {
815 bool __found =
false;
816 for (size_type __i = 0; __i < __n ; __i++) {
817 if (traits_type::eq (_C_data [__xpos], __s [__i])) {
830template <
class _CharT,
class _Traits,
class _Allocator>
831typename basic_string<_CharT, _Traits, _Allocator>::size_type
832basic_string<_CharT, _Traits, _Allocator>::
833find_last_not_of (const_pointer __s, size_type __pos, size_type __n)
const
838 size_type __slen =
size () - 1;
839 size_type __xpos_start = __pos < __slen ? __pos : __slen;
840 for (size_type __xpos = __xpos_start + 1; __xpos != 0 ; __xpos--) {
841 bool __found =
false;
842 for (size_type __i = 0; __i < __n ; __i++) {
843 if (traits_type::eq (_C_data [__xpos - 1], __s [__i])) {
857template <
class _CharT,
class _Traits,
class _Allocator>
858basic_string<_CharT, _Traits, _Allocator>
859basic_string<_CharT, _Traits, _Allocator>::
860substr (size_type __pos, size_type __n)
const
868 size_type __slen =
size () - __pos;
869 size_type __rlen = __n < __slen ? __n : __slen;
870 return basic_string (_C_data + __pos, __rlen);
874template <
class _CharT,
class _Traits,
class _Allocator>
875int basic_string<_CharT, _Traits, _Allocator>::
876compare (size_type __pos1, size_type __n1,
877 const basic_string& __str, size_type __pos2, size_type __n2)
const
882 "size_type, const basic_string&, "
883 "size_type, size_type) const"),
884 __pos2, __str.size ()));
886 if (__str.size () - __pos2 < __n2)
887 __n2 = __str.size () - __pos2;
889 return compare (__pos1, __n1, __str.c_str () + __pos2, __n2);
893template <
class _CharT,
class _Traits,
class _Allocator>
894int basic_string<_CharT, _Traits, _Allocator>::
895compare (size_type __pos, size_type __n1,
896 const_pointer __s, size_type __n2)
const
901 "size_type, const const_pointer, "
905 if (
size () - __pos < __n1)
906 __n1 =
size () - __pos;
907 size_type __rlen = __n1 < __n2 ? __n1 : __n2;
908 int __res = traits_type::compare (_C_data + __pos, __s, __rlen);
911 __res = (__n1 < __n2) ? -1 : (__n1 != __n2);
921# pragma warning (pop)
#define _RWSTD_REQUIRES(pred, args)
#define _RWSTD_VALUE_ALLOC(ignore, object, call)
#define _RWSTD_STATIC_CAST(T, x)
#define _RWSTD_NAMESPACE(name)
#define _RWSTD_FUNC(ignore)
#define _RWSTD_ASSERT(ignore)
#define _DISTANCE(first, last, ignore)
#define _RWSTD_ASSERT_RANGE(ign1, ign2)
#define _RWSTD_ITERATOR_CATEGORY(iterT, ignore)
#define _RWSTD_ERROR_LENGTH_ERROR
#define _RWSTD_ERROR_OUT_OF_RANGE