39 #ifndef _BASIC_STRING_TCC
40 #define _BASIC_STRING_TCC 1
42 #pragma GCC system_header
44 #include <cxxabi-forced.h>
46 _GLIBCXX_BEGIN_NAMESPACE(std)
48 template<typename _CharT, typename _Traits, typename _Alloc>
49 const typename basic_string<_CharT, _Traits, _Alloc>::size_type
50 basic_string<_CharT, _Traits, _Alloc>::
51 _Rep::_S_max_size = (((npos - sizeof(_Rep_base))/sizeof(_CharT)) - 1) / 4;
53 template<typename _CharT, typename _Traits, typename _Alloc>
55 basic_string<_CharT, _Traits, _Alloc>::
56 _Rep::_S_terminal = _CharT();
58 template<typename _CharT, typename _Traits, typename _Alloc>
59 const typename basic_string<_CharT, _Traits, _Alloc>::size_type
60 basic_string<_CharT, _Traits, _Alloc>::npos;
64 template<typename _CharT, typename _Traits, typename _Alloc>
65 typename basic_string<_CharT, _Traits, _Alloc>::size_type
66 basic_string<_CharT, _Traits, _Alloc>::_Rep::_S_empty_rep_storage[
67 (sizeof(_Rep_base) + sizeof(_CharT) + sizeof(size_type) - 1) /
74 template<typename _CharT, typename _Traits, typename _Alloc>
75 template<typename _InIterator>
77 basic_string<_CharT, _Traits, _Alloc>::
78 _S_construct(_InIterator __beg, _InIterator __end, const _Alloc& __a,
81 #ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
82 if (__beg == __end && __a == _Alloc())
83 return _S_empty_rep()._M_refdata();
88 while (__beg != __end && __len <
sizeof(__buf) /
sizeof(_CharT))
90 __buf[__len++] = *__beg;
93 _Rep* __r = _Rep::_S_create(__len, size_type(0), __a);
94 _M_copy(__r->_M_refdata(), __buf, __len);
97 while (__beg != __end)
99 if (__len == __r->_M_capacity)
102 _Rep* __another = _Rep::_S_create(__len + 1, __len, __a);
103 _M_copy(__another->_M_refdata(), __r->_M_refdata(), __len);
104 __r->_M_destroy(__a);
107 __r->_M_refdata()[__len++] = *__beg;
113 __r->_M_destroy(__a);
114 __throw_exception_again;
116 __r->_M_set_length_and_sharable(__len);
117 return __r->_M_refdata();
120 template<
typename _CharT,
typename _Traits,
typename _Alloc>
121 template <
typename _InIterator>
123 basic_string<_CharT, _Traits, _Alloc>::
124 _S_construct(_InIterator __beg, _InIterator __end,
const _Alloc& __a,
125 forward_iterator_tag)
127 #ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
128 if (__beg == __end && __a == _Alloc())
129 return _S_empty_rep()._M_refdata();
132 if (__builtin_expect(__gnu_cxx::__is_null_pointer(__beg)
133 && __beg != __end, 0))
134 __throw_logic_error(__N(
"basic_string::_S_construct NULL not valid"));
136 const size_type __dnew =
static_cast<size_type
>(
std::distance(__beg,
139 _Rep* __r = _Rep::_S_create(__dnew, size_type(0), __a);
141 { _S_copy_chars(__r->_M_refdata(), __beg, __end); }
144 __r->_M_destroy(__a);
145 __throw_exception_again;
147 __r->_M_set_length_and_sharable(__dnew);
148 return __r->_M_refdata();
151 template<
typename _CharT,
typename _Traits,
typename _Alloc>
153 basic_string<_CharT, _Traits, _Alloc>::
154 _S_construct(size_type __n, _CharT __c,
const _Alloc& __a)
156 #ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
157 if (__n == 0 && __a == _Alloc())
158 return _S_empty_rep()._M_refdata();
161 _Rep* __r = _Rep::_S_create(__n, size_type(0), __a);
163 _M_assign(__r->_M_refdata(), __n, __c);
165 __r->_M_set_length_and_sharable(__n);
166 return __r->_M_refdata();
169 template<
typename _CharT,
typename _Traits,
typename _Alloc>
170 basic_string<_CharT, _Traits, _Alloc>::
172 : _M_dataplus(__str._M_rep()->_M_grab(_Alloc(__str.get_allocator()),
173 __str.get_allocator()),
174 __str.get_allocator())
177 template<
typename _CharT,
typename _Traits,
typename _Alloc>
180 : _M_dataplus(_S_construct(size_type(), _CharT(), __a), __a)
183 template<
typename _CharT,
typename _Traits,
typename _Alloc>
186 : _M_dataplus(_S_construct(__str._M_data()
187 + __str._M_check(__pos,
188 "basic_string::basic_string"),
189 __str._M_data() + __str._M_limit(__pos, __n)
190 + __pos, _Alloc()), _Alloc())
193 template<
typename _CharT,
typename _Traits,
typename _Alloc>
196 size_type __n,
const _Alloc& __a)
197 : _M_dataplus(_S_construct(__str._M_data()
198 + __str._M_check(__pos,
199 "basic_string::basic_string"),
200 __str._M_data() + __str._M_limit(__pos, __n)
205 template<
typename _CharT,
typename _Traits,
typename _Alloc>
208 : _M_dataplus(_S_construct(__s, __s + __n, __a), __a)
212 template<
typename _CharT,
typename _Traits,
typename _Alloc>
215 : _M_dataplus(_S_construct(__s, __s ? __s + traits_type::length(__s) :
216 __s + npos, __a), __a)
219 template<
typename _CharT,
typename _Traits,
typename _Alloc>
222 : _M_dataplus(_S_construct(__n, __c, __a), __a)
226 template<
typename _CharT,
typename _Traits,
typename _Alloc>
227 template<
typename _InputIterator>
229 basic_string(_InputIterator __beg, _InputIterator __end,
const _Alloc& __a)
230 : _M_dataplus(_S_construct(__beg, __end, __a), __a)
233 #ifdef __GXX_EXPERIMENTAL_CXX0X__
234 template<
typename _CharT,
typename _Traits,
typename _Alloc>
237 : _M_dataplus(_S_construct(__l.begin(), __l.end(), __a), __a)
241 template<
typename _CharT,
typename _Traits,
typename _Alloc>
246 if (_M_rep() != __str._M_rep())
249 const allocator_type __a = this->get_allocator();
250 _CharT* __tmp = __str._M_rep()->_M_grab(__a, __str.
get_allocator());
251 _M_rep()->_M_dispose(__a);
257 template<
typename _CharT,
typename _Traits,
typename _Alloc>
262 __glibcxx_requires_string_len(__s, __n);
263 _M_check_length(this->size(), __n,
"basic_string::assign");
264 if (_M_disjunct(__s) || _M_rep()->_M_is_shared())
265 return _M_replace_safe(size_type(0), this->size(), __s, __n);
269 const size_type __pos = __s - _M_data();
271 _M_copy(_M_data(), __s, __n);
273 _M_move(_M_data(), __s, __n);
274 _M_rep()->_M_set_length_and_sharable(__n);
279 template<
typename _CharT,
typename _Traits,
typename _Alloc>
286 _M_check_length(size_type(0), __n,
"basic_string::append");
287 const size_type __len = __n + this->size();
288 if (__len > this->capacity() || _M_rep()->_M_is_shared())
289 this->reserve(__len);
290 _M_assign(_M_data() + this->size(), __n, __c);
291 _M_rep()->_M_set_length_and_sharable(__len);
296 template<
typename _CharT,
typename _Traits,
typename _Alloc>
301 __glibcxx_requires_string_len(__s, __n);
304 _M_check_length(size_type(0), __n,
"basic_string::append");
305 const size_type __len = __n + this->size();
306 if (__len > this->capacity() || _M_rep()->_M_is_shared())
308 if (_M_disjunct(__s))
309 this->reserve(__len);
312 const size_type __off = __s - _M_data();
313 this->reserve(__len);
314 __s = _M_data() + __off;
317 _M_copy(_M_data() + this->size(), __s, __n);
318 _M_rep()->_M_set_length_and_sharable(__len);
323 template<
typename _CharT,
typename _Traits,
typename _Alloc>
328 const size_type __size = __str.
size();
331 const size_type __len = __size + this->size();
332 if (__len > this->capacity() || _M_rep()->_M_is_shared())
333 this->reserve(__len);
334 _M_copy(_M_data() + this->size(), __str._M_data(), __size);
335 _M_rep()->_M_set_length_and_sharable(__len);
340 template<
typename _CharT,
typename _Traits,
typename _Alloc>
345 __str._M_check(__pos,
"basic_string::append");
346 __n = __str._M_limit(__pos, __n);
349 const size_type __len = __n + this->size();
350 if (__len > this->capacity() || _M_rep()->_M_is_shared())
351 this->reserve(__len);
352 _M_copy(_M_data() + this->size(), __str._M_data() + __pos, __n);
353 _M_rep()->_M_set_length_and_sharable(__len);
358 template<
typename _CharT,
typename _Traits,
typename _Alloc>
361 insert(size_type __pos,
const _CharT* __s, size_type __n)
363 __glibcxx_requires_string_len(__s, __n);
364 _M_check(__pos,
"basic_string::insert");
365 _M_check_length(size_type(0), __n,
"basic_string::insert");
366 if (_M_disjunct(__s) || _M_rep()->_M_is_shared())
367 return _M_replace_safe(__pos, size_type(0), __s, __n);
371 const size_type __off = __s - _M_data();
372 _M_mutate(__pos, 0, __n);
373 __s = _M_data() + __off;
374 _CharT* __p = _M_data() + __pos;
375 if (__s + __n <= __p)
376 _M_copy(__p, __s, __n);
378 _M_copy(__p, __s + __n, __n);
381 const size_type __nleft = __p - __s;
382 _M_copy(__p, __s, __nleft);
383 _M_copy(__p + __nleft, __p + __n, __n - __nleft);
389 template<
typename _CharT,
typename _Traits,
typename _Alloc>
390 typename basic_string<_CharT, _Traits, _Alloc>::iterator
392 erase(iterator __first, iterator __last)
394 _GLIBCXX_DEBUG_PEDASSERT(__first >= _M_ibegin() && __first <= __last
395 && __last <= _M_iend());
400 const size_type __size = __last - __first;
403 const size_type __pos = __first - _M_ibegin();
404 _M_mutate(__pos, __size, size_type(0));
405 _M_rep()->_M_set_leaked();
406 return iterator(_M_data() + __pos);
412 template<
typename _CharT,
typename _Traits,
typename _Alloc>
415 replace(size_type __pos, size_type __n1,
const _CharT* __s,
418 __glibcxx_requires_string_len(__s, __n2);
419 _M_check(__pos,
"basic_string::replace");
420 __n1 = _M_limit(__pos, __n1);
421 _M_check_length(__n1, __n2,
"basic_string::replace");
423 if (_M_disjunct(__s) || _M_rep()->_M_is_shared())
424 return _M_replace_safe(__pos, __n1, __s, __n2);
425 else if ((__left = __s + __n2 <= _M_data() + __pos)
426 || _M_data() + __pos + __n1 <= __s)
429 size_type __off = __s - _M_data();
430 __left ? __off : (__off += __n2 - __n1);
431 _M_mutate(__pos, __n1, __n2);
432 _M_copy(_M_data() + __pos, _M_data() + __off, __n2);
439 return _M_replace_safe(__pos, __n1, __tmp._M_data(), __n2);
443 template<
typename _CharT,
typename _Traits,
typename _Alloc>
448 const size_type __size =
sizeof(_Rep_base) +
449 (this->_M_capacity + 1) *
sizeof(_CharT);
450 _Raw_bytes_alloc(__a).deallocate(reinterpret_cast<char*>(
this), __size);
453 template<
typename _CharT,
typename _Traits,
typename _Alloc>
455 basic_string<_CharT, _Traits, _Alloc>::
458 #ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
459 if (_M_rep() == &_S_empty_rep())
462 if (_M_rep()->_M_is_shared())
464 _M_rep()->_M_set_leaked();
467 template<
typename _CharT,
typename _Traits,
typename _Alloc>
469 basic_string<_CharT, _Traits, _Alloc>::
470 _M_mutate(size_type __pos, size_type __len1, size_type __len2)
472 const size_type __old_size = this->size();
473 const size_type __new_size = __old_size + __len2 - __len1;
474 const size_type __how_much = __old_size - __pos - __len1;
476 if (__new_size > this->capacity() || _M_rep()->_M_is_shared())
479 const allocator_type __a = get_allocator();
480 _Rep* __r = _Rep::_S_create(__new_size, this->capacity(), __a);
483 _M_copy(__r->_M_refdata(), _M_data(), __pos);
485 _M_copy(__r->_M_refdata() + __pos + __len2,
486 _M_data() + __pos + __len1, __how_much);
488 _M_rep()->_M_dispose(__a);
489 _M_data(__r->_M_refdata());
491 else if (__how_much && __len1 != __len2)
494 _M_move(_M_data() + __pos + __len2,
495 _M_data() + __pos + __len1, __how_much);
497 _M_rep()->_M_set_length_and_sharable(__new_size);
500 template<
typename _CharT,
typename _Traits,
typename _Alloc>
505 if (__res != this->capacity() || _M_rep()->_M_is_shared())
508 if (__res < this->size())
509 __res = this->size();
510 const allocator_type __a = get_allocator();
511 _CharT* __tmp = _M_rep()->_M_clone(__a, __res - this->size());
512 _M_rep()->_M_dispose(__a);
517 template<
typename _CharT,
typename _Traits,
typename _Alloc>
522 if (_M_rep()->_M_is_leaked())
523 _M_rep()->_M_set_sharable();
524 if (__s._M_rep()->_M_is_leaked())
525 __s._M_rep()->_M_set_sharable();
528 _CharT* __tmp = _M_data();
529 _M_data(__s._M_data());
537 const basic_string __tmp2(__s._M_ibegin(), __s._M_iend(),
538 this->get_allocator());
544 template<
typename _CharT,
typename _Traits,
typename _Alloc>
547 _S_create(size_type __capacity, size_type __old_capacity,
548 const _Alloc& __alloc)
552 if (__capacity > _S_max_size)
553 __throw_length_error(__N(
"basic_string::_S_create"));
578 const size_type __pagesize = 4096;
579 const size_type __malloc_header_size = 4 *
sizeof(
void*);
587 if (__capacity > __old_capacity && __capacity < 2 * __old_capacity)
588 __capacity = 2 * __old_capacity;
593 size_type __size = (__capacity + 1) *
sizeof(_CharT) +
sizeof(_Rep);
595 const size_type __adj_size = __size + __malloc_header_size;
596 if (__adj_size > __pagesize && __capacity > __old_capacity)
598 const size_type __extra = __pagesize - __adj_size % __pagesize;
599 __capacity += __extra /
sizeof(_CharT);
601 if (__capacity > _S_max_size)
602 __capacity = _S_max_size;
603 __size = (__capacity + 1) *
sizeof(_CharT) +
sizeof(_Rep);
608 void* __place = _Raw_bytes_alloc(__alloc).allocate(__size);
609 _Rep *__p =
new (__place) _Rep;
610 __p->_M_capacity = __capacity;
618 __p->_M_set_sharable();
622 template<
typename _CharT,
typename _Traits,
typename _Alloc>
624 basic_string<_CharT, _Traits, _Alloc>::_Rep::
625 _M_clone(
const _Alloc& __alloc, size_type __res)
628 const size_type __requested_cap = this->_M_length + __res;
629 _Rep* __r = _Rep::_S_create(__requested_cap, this->_M_capacity,
632 _M_copy(__r->_M_refdata(), _M_refdata(), this->_M_length);
634 __r->_M_set_length_and_sharable(this->_M_length);
635 return __r->_M_refdata();
638 template<
typename _CharT,
typename _Traits,
typename _Alloc>
643 const size_type __size = this->size();
644 _M_check_length(__size, __n,
"basic_string::resize");
646 this->append(__n - __size, __c);
647 else if (__n < __size)
652 template<
typename _CharT,
typename _Traits,
typename _Alloc>
653 template<
typename _InputIterator>
657 _InputIterator __k2, __false_type)
660 const size_type __n1 = __i2 - __i1;
661 _M_check_length(__n1, __s.size(),
"basic_string::_M_replace_dispatch");
662 return _M_replace_safe(__i1 - _M_ibegin(), __n1, __s._M_data(),
666 template<
typename _CharT,
typename _Traits,
typename _Alloc>
667 basic_string<_CharT, _Traits, _Alloc>&
668 basic_string<_CharT, _Traits, _Alloc>::
669 _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2,
672 _M_check_length(__n1, __n2,
"basic_string::_M_replace_aux");
673 _M_mutate(__pos1, __n1, __n2);
675 _M_assign(_M_data() + __pos1, __n2, __c);
679 template<
typename _CharT,
typename _Traits,
typename _Alloc>
680 basic_string<_CharT, _Traits, _Alloc>&
681 basic_string<_CharT, _Traits, _Alloc>::
682 _M_replace_safe(size_type __pos1, size_type __n1,
const _CharT* __s,
685 _M_mutate(__pos1, __n1, __n2);
687 _M_copy(_M_data() + __pos1, __s, __n2);
691 template<
typename _CharT,
typename _Traits,
typename _Alloc>
692 basic_string<_CharT, _Traits, _Alloc>
696 __glibcxx_requires_string(__lhs);
698 typedef typename __string_type::size_type __size_type;
699 const __size_type __len = _Traits::length(__lhs);
701 __str.reserve(__len + __rhs.
size());
702 __str.append(__lhs, __len);
707 template<
typename _CharT,
typename _Traits,
typename _Alloc>
708 basic_string<_CharT, _Traits, _Alloc>
712 typedef typename __string_type::size_type __size_type;
714 const __size_type __len = __rhs.
size();
715 __str.reserve(__len + 1);
716 __str.append(__size_type(1), __lhs);
721 template<
typename _CharT,
typename _Traits,
typename _Alloc>
722 typename basic_string<_CharT, _Traits, _Alloc>::size_type
724 copy(_CharT* __s, size_type __n, size_type __pos)
const
726 _M_check(__pos,
"basic_string::copy");
727 __n = _M_limit(__pos, __n);
728 __glibcxx_requires_string_len(__s, __n);
730 _M_copy(__s, _M_data() + __pos, __n);
735 template<
typename _CharT,
typename _Traits,
typename _Alloc>
736 typename basic_string<_CharT, _Traits, _Alloc>::size_type
738 find(
const _CharT* __s, size_type __pos, size_type __n)
const
740 __glibcxx_requires_string_len(__s, __n);
741 const size_type __size = this->size();
742 const _CharT* __data = _M_data();
745 return __pos <= __size ? __pos : npos;
749 for (; __pos <= __size - __n; ++__pos)
750 if (traits_type::eq(__data[__pos], __s[0])
751 && traits_type::compare(__data + __pos + 1,
752 __s + 1, __n - 1) == 0)
758 template<
typename _CharT,
typename _Traits,
typename _Alloc>
759 typename basic_string<_CharT, _Traits, _Alloc>::size_type
761 find(_CharT __c, size_type __pos)
const
763 size_type __ret = npos;
764 const size_type __size = this->size();
767 const _CharT* __data = _M_data();
768 const size_type __n = __size - __pos;
769 const _CharT* __p = traits_type::find(__data + __pos, __n, __c);
771 __ret = __p - __data;
776 template<
typename _CharT,
typename _Traits,
typename _Alloc>
777 typename basic_string<_CharT, _Traits, _Alloc>::size_type
779 rfind(
const _CharT* __s, size_type __pos, size_type __n)
const
781 __glibcxx_requires_string_len(__s, __n);
782 const size_type __size = this->size();
785 __pos =
std::min(size_type(__size - __n), __pos);
786 const _CharT* __data = _M_data();
789 if (traits_type::compare(__data + __pos, __s, __n) == 0)
797 template<
typename _CharT,
typename _Traits,
typename _Alloc>
798 typename basic_string<_CharT, _Traits, _Alloc>::size_type
800 rfind(_CharT __c, size_type __pos)
const
802 size_type __size = this->size();
805 if (--__size > __pos)
807 for (++__size; __size-- > 0; )
808 if (traits_type::eq(_M_data()[__size], __c))
814 template<
typename _CharT,
typename _Traits,
typename _Alloc>
815 typename basic_string<_CharT, _Traits, _Alloc>::size_type
819 __glibcxx_requires_string_len(__s, __n);
820 for (; __n && __pos < this->size(); ++__pos)
822 const _CharT* __p = traits_type::find(__s, __n, _M_data()[__pos]);
829 template<
typename _CharT,
typename _Traits,
typename _Alloc>
830 typename basic_string<_CharT, _Traits, _Alloc>::size_type
834 __glibcxx_requires_string_len(__s, __n);
835 size_type __size = this->size();
838 if (--__size > __pos)
842 if (traits_type::find(__s, __n, _M_data()[__size]))
845 while (__size-- != 0);
850 template<
typename _CharT,
typename _Traits,
typename _Alloc>
851 typename basic_string<_CharT, _Traits, _Alloc>::size_type
855 __glibcxx_requires_string_len(__s, __n);
856 for (; __pos < this->size(); ++__pos)
857 if (!traits_type::find(__s, __n, _M_data()[__pos]))
862 template<
typename _CharT,
typename _Traits,
typename _Alloc>
863 typename basic_string<_CharT, _Traits, _Alloc>::size_type
867 for (; __pos < this->size(); ++__pos)
868 if (!traits_type::eq(_M_data()[__pos], __c))
873 template<
typename _CharT,
typename _Traits,
typename _Alloc>
874 typename basic_string<_CharT, _Traits, _Alloc>::size_type
878 __glibcxx_requires_string_len(__s, __n);
879 size_type __size = this->size();
882 if (--__size > __pos)
886 if (!traits_type::find(__s, __n, _M_data()[__size]))
894 template<
typename _CharT,
typename _Traits,
typename _Alloc>
895 typename basic_string<_CharT, _Traits, _Alloc>::size_type
899 size_type __size = this->size();
902 if (--__size > __pos)
906 if (!traits_type::eq(_M_data()[__size], __c))
914 template<
typename _CharT,
typename _Traits,
typename _Alloc>
919 _M_check(__pos,
"basic_string::compare");
920 __n = _M_limit(__pos, __n);
921 const size_type __osize = __str.
size();
922 const size_type __len =
std::min(__n, __osize);
923 int __r = traits_type::compare(_M_data() + __pos, __str.
data(), __len);
925 __r = _S_compare(__n, __osize);
929 template<
typename _CharT,
typename _Traits,
typename _Alloc>
933 size_type __pos2, size_type __n2)
const
935 _M_check(__pos1,
"basic_string::compare");
936 __str._M_check(__pos2,
"basic_string::compare");
937 __n1 = _M_limit(__pos1, __n1);
938 __n2 = __str._M_limit(__pos2, __n2);
939 const size_type __len =
std::min(__n1, __n2);
940 int __r = traits_type::compare(_M_data() + __pos1,
941 __str.
data() + __pos2, __len);
943 __r = _S_compare(__n1, __n2);
947 template<
typename _CharT,
typename _Traits,
typename _Alloc>
952 __glibcxx_requires_string(__s);
953 const size_type __size = this->size();
954 const size_type __osize = traits_type::length(__s);
955 const size_type __len =
std::min(__size, __osize);
956 int __r = traits_type::compare(_M_data(), __s, __len);
958 __r = _S_compare(__size, __osize);
962 template<
typename _CharT,
typename _Traits,
typename _Alloc>
965 compare(size_type __pos, size_type __n1,
const _CharT* __s)
const
967 __glibcxx_requires_string(__s);
968 _M_check(__pos,
"basic_string::compare");
969 __n1 = _M_limit(__pos, __n1);
970 const size_type __osize = traits_type::length(__s);
971 const size_type __len =
std::min(__n1, __osize);
972 int __r = traits_type::compare(_M_data() + __pos, __s, __len);
974 __r = _S_compare(__n1, __osize);
978 template<
typename _CharT,
typename _Traits,
typename _Alloc>
981 compare(size_type __pos, size_type __n1,
const _CharT* __s,
982 size_type __n2)
const
984 __glibcxx_requires_string_len(__s, __n2);
985 _M_check(__pos,
"basic_string::compare");
986 __n1 = _M_limit(__pos, __n1);
987 const size_type __len =
std::min(__n1, __n2);
988 int __r = traits_type::compare(_M_data() + __pos, __s, __len);
990 __r = _S_compare(__n1, __n2);
995 template<
typename _CharT,
typename _Traits,
typename _Alloc>
1002 typedef typename __istream_type::ios_base __ios_base;
1003 typedef typename __istream_type::int_type __int_type;
1004 typedef typename __string_type::size_type __size_type;
1006 typedef typename __ctype_type::ctype_base __ctype_base;
1008 __size_type __extracted = 0;
1009 typename __ios_base::iostate __err = __ios_base::goodbit;
1010 typename __istream_type::sentry __cerb(__in,
false);
1018 __size_type __len = 0;
1020 const __size_type __n = __w > 0 ?
static_cast<__size_type
>(__w)
1022 const __ctype_type& __ct = use_facet<__ctype_type>(__in.
getloc());
1023 const __int_type __eof = _Traits::eof();
1024 __int_type __c = __in.
rdbuf()->sgetc();
1026 while (__extracted < __n
1027 && !_Traits::eq_int_type(__c, __eof)
1028 && !__ct.is(__ctype_base::space,
1029 _Traits::to_char_type(__c)))
1031 if (__len ==
sizeof(__buf) /
sizeof(_CharT))
1033 __str.
append(__buf,
sizeof(__buf) /
sizeof(_CharT));
1036 __buf[__len++] = _Traits::to_char_type(__c);
1038 __c = __in.
rdbuf()->snextc();
1040 __str.
append(__buf, __len);
1042 if (_Traits::eq_int_type(__c, __eof))
1043 __err |= __ios_base::eofbit;
1048 __in._M_setstate(__ios_base::badbit);
1049 __throw_exception_again;
1056 __in._M_setstate(__ios_base::badbit);
1061 __err |= __ios_base::failbit;
1067 template<
typename _CharT,
typename _Traits,
typename _Alloc>
1068 basic_istream<_CharT, _Traits>&
1074 typedef typename __istream_type::ios_base __ios_base;
1075 typedef typename __istream_type::int_type __int_type;
1076 typedef typename __string_type::size_type __size_type;
1078 __size_type __extracted = 0;
1079 const __size_type __n = __str.
max_size();
1080 typename __ios_base::iostate __err = __ios_base::goodbit;
1081 typename __istream_type::sentry __cerb(__in,
true);
1087 const __int_type __idelim = _Traits::to_int_type(__delim);
1088 const __int_type __eof = _Traits::eof();
1089 __int_type __c = __in.
rdbuf()->sgetc();
1091 while (__extracted < __n
1092 && !_Traits::eq_int_type(__c, __eof)
1093 && !_Traits::eq_int_type(__c, __idelim))
1095 __str += _Traits::to_char_type(__c);
1097 __c = __in.
rdbuf()->snextc();
1100 if (_Traits::eq_int_type(__c, __eof))
1101 __err |= __ios_base::eofbit;
1102 else if (_Traits::eq_int_type(__c, __idelim))
1105 __in.
rdbuf()->sbumpc();
1108 __err |= __ios_base::failbit;
1112 __in._M_setstate(__ios_base::badbit);
1113 __throw_exception_again;
1120 __in._M_setstate(__ios_base::badbit);
1124 __err |= __ios_base::failbit;
1133 #if _GLIBCXX_EXTERN_TEMPLATE > 0
1134 extern template class basic_string<char>;
1136 basic_istream<char>&
1139 basic_ostream<char>&
1140 operator<<(basic_ostream<char>&,
const string&);
1142 basic_istream<char>&
1143 getline(basic_istream<char>&,
string&,
char);
1145 basic_istream<char>&
1146 getline(basic_istream<char>&,
string&);
1148 #ifdef _GLIBCXX_USE_WCHAR_T
1149 extern template class basic_string<wchar_t>;
1151 basic_istream<wchar_t>&
1152 operator>>(basic_istream<wchar_t>&, wstring&);
1154 basic_ostream<wchar_t>&
1155 operator<<(basic_ostream<wchar_t>&,
const wstring&);
1157 basic_istream<wchar_t>&
1158 getline(basic_istream<wchar_t>&, wstring&,
wchar_t);
1160 basic_istream<wchar_t>&
1161 getline(basic_istream<wchar_t>&, wstring&);
1165 _GLIBCXX_END_NAMESPACE