Install gcc-4.4.0-tdm-1-core-2.tar.gz
[msysgit.git] / mingw / lib / gcc / mingw32 / 4.3.3 / include / c++ / ext / vstring.tcc
blob8d5b1b5e7752e86b33dcbe261db0bb91cb8177a4
1 // Versatile string -*- C++ -*-
3 // Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library.  This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
9 // any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING.  If not, write to the Free
18 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19 // USA.
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction.  Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License.  This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
30 /** @file ext/vstring.tcc
31  *  This file is a GNU extension to the Standard C++ Library.
32  *  This is an internal header file, included by other library headers.
33  *  You should not attempt to use it directly.
34  */
36 #ifndef _VSTRING_TCC
37 #define _VSTRING_TCC 1
39 #pragma GCC system_header
41 #include <cxxabi-forced.h>
43 _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
45   template<typename _CharT, typename _Traits, typename _Alloc,
46            template <typename, typename, typename> class _Base>
47     const typename __versa_string<_CharT, _Traits, _Alloc, _Base>::size_type
48     __versa_string<_CharT, _Traits, _Alloc, _Base>::npos;
50   template<typename _CharT, typename _Traits, typename _Alloc,
51            template <typename, typename, typename> class _Base>
52     void
53     __versa_string<_CharT, _Traits, _Alloc, _Base>::
54     resize(size_type __n, _CharT __c)
55     {
56       const size_type __size = this->size();
57       if (__size < __n)
58         this->append(__n - __size, __c);
59       else if (__n < __size)
60         this->_M_erase(__n, __size - __n);
61     }
63   template<typename _CharT, typename _Traits, typename _Alloc,
64            template <typename, typename, typename> class _Base>
65     __versa_string<_CharT, _Traits, _Alloc, _Base>&
66     __versa_string<_CharT, _Traits, _Alloc, _Base>::
67     _M_append(const _CharT* __s, size_type __n)
68     {
69       const size_type __len = __n + this->size();
71       if (__len <= this->capacity() && !this->_M_is_shared())
72         {
73           if (__n)
74             this->_S_copy(this->_M_data() + this->size(), __s, __n);
75         }
76       else
77         this->_M_mutate(this->size(), size_type(0), __s, __n);
79       this->_M_set_length(__len);
80       return *this;
81     }
83   template<typename _CharT, typename _Traits, typename _Alloc,
84            template <typename, typename, typename> class _Base>
85     template<typename _InputIterator>
86       __versa_string<_CharT, _Traits, _Alloc, _Base>&
87       __versa_string<_CharT, _Traits, _Alloc, _Base>::
88       _M_replace_dispatch(iterator __i1, iterator __i2, _InputIterator __k1,
89                           _InputIterator __k2, std::__false_type)
90       {
91         const __versa_string __s(__k1, __k2);
92         const size_type __n1 = __i2 - __i1;
93         return _M_replace(__i1 - _M_ibegin(), __n1, __s._M_data(),
94                           __s.size());
95       }
97   template<typename _CharT, typename _Traits, typename _Alloc,
98            template <typename, typename, typename> class _Base>
99     __versa_string<_CharT, _Traits, _Alloc, _Base>&
100     __versa_string<_CharT, _Traits, _Alloc, _Base>::
101     _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2,
102                    _CharT __c)
103     {
104       _M_check_length(__n1, __n2, "__versa_string::_M_replace_aux");
106       const size_type __old_size = this->size();
107       const size_type __new_size = __old_size + __n2 - __n1;
109       if (__new_size <= this->capacity() && !this->_M_is_shared())
110         {
111           _CharT* __p = this->_M_data() + __pos1;
113           const size_type __how_much = __old_size - __pos1 - __n1;
114           if (__how_much && __n1 != __n2)
115             this->_S_move(__p + __n2, __p + __n1, __how_much);
116         }
117       else
118         this->_M_mutate(__pos1, __n1, 0, __n2);
120       if (__n2)
121         this->_S_assign(this->_M_data() + __pos1, __n2, __c);
123       this->_M_set_length(__new_size);
124       return *this;
125     }
127   template<typename _CharT, typename _Traits, typename _Alloc,
128            template <typename, typename, typename> class _Base>
129     __versa_string<_CharT, _Traits, _Alloc, _Base>&
130     __versa_string<_CharT, _Traits, _Alloc, _Base>::
131     _M_replace(size_type __pos, size_type __len1, const _CharT* __s,
132                const size_type __len2)
133     {
134       _M_check_length(__len1, __len2, "__versa_string::_M_replace");
136       const size_type __old_size = this->size();
137       const size_type __new_size = __old_size + __len2 - __len1;
138       
139       if (__new_size <= this->capacity() && !this->_M_is_shared())
140         {
141           _CharT* __p = this->_M_data() + __pos;
143           const size_type __how_much = __old_size - __pos - __len1;
144           if (_M_disjunct(__s))
145             {
146               if (__how_much && __len1 != __len2)
147                 this->_S_move(__p + __len2, __p + __len1, __how_much);
148               if (__len2)
149                 this->_S_copy(__p, __s, __len2);
150             }
151           else
152             {
153               // Work in-place.
154               if (__len2 && __len2 <= __len1)
155                 this->_S_move(__p, __s, __len2);
156               if (__how_much && __len1 != __len2)
157                 this->_S_move(__p + __len2, __p + __len1, __how_much);
158               if (__len2 > __len1)
159                 {
160                   if (__s + __len2 <= __p + __len1)
161                     this->_S_move(__p, __s, __len2);
162                   else if (__s >= __p + __len1)
163                     this->_S_copy(__p, __s + __len2 - __len1, __len2);
164                   else
165                     {
166                       const size_type __nleft = (__p + __len1) - __s;
167                       this->_S_move(__p, __s, __nleft);
168                       this->_S_copy(__p + __nleft, __p + __len2,
169                                     __len2 - __nleft);
170                     }
171                 }
172             }
173         }
174       else
175         this->_M_mutate(__pos, __len1, __s, __len2);
177       this->_M_set_length(__new_size);
178       return *this;
179     }
180   
181   template<typename _CharT, typename _Traits, typename _Alloc,
182            template <typename, typename, typename> class _Base>
183     __versa_string<_CharT, _Traits, _Alloc, _Base>
184     operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
185               const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
186     {
187       __versa_string<_CharT, _Traits, _Alloc, _Base> __str;
188       __str.reserve(__lhs.size() + __rhs.size());
189       __str.append(__lhs);
190       __str.append(__rhs);
191       return __str;
192     }
194   template<typename _CharT, typename _Traits, typename _Alloc,
195            template <typename, typename, typename> class _Base>
196     __versa_string<_CharT, _Traits, _Alloc, _Base>
197     operator+(const _CharT* __lhs,
198               const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
199     {
200       __glibcxx_requires_string(__lhs);
201       typedef __versa_string<_CharT, _Traits, _Alloc, _Base> __string_type;
202       typedef typename __string_type::size_type   __size_type;
203       const __size_type __len = _Traits::length(__lhs);
204       __string_type __str;
205       __str.reserve(__len + __rhs.size());
206       __str.append(__lhs, __len);
207       __str.append(__rhs);
208       return __str;
209     }
211   template<typename _CharT, typename _Traits, typename _Alloc,
212            template <typename, typename, typename> class _Base>
213     __versa_string<_CharT, _Traits, _Alloc, _Base>
214     operator+(_CharT __lhs,
215               const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
216     {
217       __versa_string<_CharT, _Traits, _Alloc, _Base> __str;
218       __str.reserve(__rhs.size() + 1);
219       __str.push_back(__lhs);
220       __str.append(__rhs);
221       return __str;
222     }
224   template<typename _CharT, typename _Traits, typename _Alloc,
225            template <typename, typename, typename> class _Base>
226     __versa_string<_CharT, _Traits, _Alloc, _Base>
227     operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
228               const _CharT* __rhs)
229     {
230       __glibcxx_requires_string(__rhs);
231       typedef __versa_string<_CharT, _Traits, _Alloc, _Base> __string_type;
232       typedef typename __string_type::size_type   __size_type;
233       const __size_type __len = _Traits::length(__rhs);
234       __string_type __str;
235       __str.reserve(__lhs.size() + __len);
236       __str.append(__lhs);
237       __str.append(__rhs, __len);
238       return __str;
239     }
241   template<typename _CharT, typename _Traits, typename _Alloc,
242            template <typename, typename, typename> class _Base>
243     __versa_string<_CharT, _Traits, _Alloc, _Base>
244     operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
245               _CharT __rhs)
246     {
247       __versa_string<_CharT, _Traits, _Alloc, _Base> __str;
248       __str.reserve(__lhs.size() + 1);
249       __str.append(__lhs);
250       __str.push_back(__rhs);
251       return __str;
252     }
254   template<typename _CharT, typename _Traits, typename _Alloc,
255            template <typename, typename, typename> class _Base>
256     typename __versa_string<_CharT, _Traits, _Alloc, _Base>::size_type
257     __versa_string<_CharT, _Traits, _Alloc, _Base>::
258     copy(_CharT* __s, size_type __n, size_type __pos) const
259     {
260       _M_check(__pos, "__versa_string::copy");
261       __n = _M_limit(__pos, __n);
262       __glibcxx_requires_string_len(__s, __n);
263       if (__n)
264         this->_S_copy(__s, this->_M_data() + __pos, __n);
265       // 21.3.5.7 par 3: do not append null.  (good.)
266       return __n;
267     }
269   template<typename _CharT, typename _Traits, typename _Alloc,
270            template <typename, typename, typename> class _Base>
271     typename __versa_string<_CharT, _Traits, _Alloc, _Base>::size_type
272     __versa_string<_CharT, _Traits, _Alloc, _Base>::
273     find(const _CharT* __s, size_type __pos, size_type __n) const
274     {
275       __glibcxx_requires_string_len(__s, __n);
276       const size_type __size = this->size();
277       const _CharT* __data = this->_M_data();
279       if (__n == 0)
280         return __pos <= __size ? __pos : npos;
282       if (__n <= __size)
283         {
284           for (; __pos <= __size - __n; ++__pos)
285             if (traits_type::eq(__data[__pos], __s[0])
286                 && traits_type::compare(__data + __pos + 1,
287                                         __s + 1, __n - 1) == 0)
288               return __pos;
289         }
290       return npos;
291     }
293   template<typename _CharT, typename _Traits, typename _Alloc,
294            template <typename, typename, typename> class _Base>
295     typename __versa_string<_CharT, _Traits, _Alloc, _Base>::size_type
296     __versa_string<_CharT, _Traits, _Alloc, _Base>::
297     find(_CharT __c, size_type __pos) const
298     {
299       size_type __ret = npos;
300       const size_type __size = this->size();
301       if (__pos < __size)
302         {
303           const _CharT* __data = this->_M_data();
304           const size_type __n = __size - __pos;
305           const _CharT* __p = traits_type::find(__data + __pos, __n, __c);
306           if (__p)
307             __ret = __p - __data;
308         }
309       return __ret;
310     }
312   template<typename _CharT, typename _Traits, typename _Alloc,
313            template <typename, typename, typename> class _Base>
314     typename __versa_string<_CharT, _Traits, _Alloc, _Base>::size_type
315     __versa_string<_CharT, _Traits, _Alloc, _Base>::
316     rfind(const _CharT* __s, size_type __pos, size_type __n) const
317     {
318       __glibcxx_requires_string_len(__s, __n);
319       const size_type __size = this->size();
320       if (__n <= __size)
321         {
322           __pos = std::min(size_type(__size - __n), __pos);
323           const _CharT* __data = this->_M_data();
324           do
325             {
326               if (traits_type::compare(__data + __pos, __s, __n) == 0)
327                 return __pos;
328             }
329           while (__pos-- > 0);
330         }
331       return npos;
332     }
334   template<typename _CharT, typename _Traits, typename _Alloc,
335            template <typename, typename, typename> class _Base>
336     typename __versa_string<_CharT, _Traits, _Alloc, _Base>::size_type
337     __versa_string<_CharT, _Traits, _Alloc, _Base>::
338     rfind(_CharT __c, size_type __pos) const
339     {
340       size_type __size = this->size();
341       if (__size)
342         {
343           if (--__size > __pos)
344             __size = __pos;
345           for (++__size; __size-- > 0; )
346             if (traits_type::eq(this->_M_data()[__size], __c))
347               return __size;
348         }
349       return npos;
350     }
352   template<typename _CharT, typename _Traits, typename _Alloc,
353            template <typename, typename, typename> class _Base>
354     typename __versa_string<_CharT, _Traits, _Alloc, _Base>::size_type
355     __versa_string<_CharT, _Traits, _Alloc, _Base>::
356     find_first_of(const _CharT* __s, size_type __pos, size_type __n) const
357     {
358       __glibcxx_requires_string_len(__s, __n);
359       for (; __n && __pos < this->size(); ++__pos)
360         {
361           const _CharT* __p = traits_type::find(__s, __n,
362                                                 this->_M_data()[__pos]);
363           if (__p)
364             return __pos;
365         }
366       return npos;
367     }
369   template<typename _CharT, typename _Traits, typename _Alloc,
370            template <typename, typename, typename> class _Base>
371     typename __versa_string<_CharT, _Traits, _Alloc, _Base>::size_type
372     __versa_string<_CharT, _Traits, _Alloc, _Base>::
373     find_last_of(const _CharT* __s, size_type __pos, size_type __n) const
374     {
375       __glibcxx_requires_string_len(__s, __n);
376       size_type __size = this->size();
377       if (__size && __n)
378         {
379           if (--__size > __pos)
380             __size = __pos;
381           do
382             {
383               if (traits_type::find(__s, __n, this->_M_data()[__size]))
384                 return __size;
385             }
386           while (__size-- != 0);
387         }
388       return npos;
389     }
391   template<typename _CharT, typename _Traits, typename _Alloc,
392            template <typename, typename, typename> class _Base>
393     typename __versa_string<_CharT, _Traits, _Alloc, _Base>::size_type
394     __versa_string<_CharT, _Traits, _Alloc, _Base>::
395     find_first_not_of(const _CharT* __s, size_type __pos, size_type __n) const
396     {
397       __glibcxx_requires_string_len(__s, __n);
398       for (; __pos < this->size(); ++__pos)
399         if (!traits_type::find(__s, __n, this->_M_data()[__pos]))
400           return __pos;
401       return npos;
402     }
404   template<typename _CharT, typename _Traits, typename _Alloc,
405            template <typename, typename, typename> class _Base>
406     typename __versa_string<_CharT, _Traits, _Alloc, _Base>::size_type
407     __versa_string<_CharT, _Traits, _Alloc, _Base>::
408     find_first_not_of(_CharT __c, size_type __pos) const
409     {
410       for (; __pos < this->size(); ++__pos)
411         if (!traits_type::eq(this->_M_data()[__pos], __c))
412           return __pos;
413       return npos;
414     }
416   template<typename _CharT, typename _Traits, typename _Alloc,
417            template <typename, typename, typename> class _Base>
418     typename __versa_string<_CharT, _Traits, _Alloc, _Base>::size_type
419     __versa_string<_CharT, _Traits, _Alloc, _Base>::
420     find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const
421     {
422       __glibcxx_requires_string_len(__s, __n);
423       size_type __size = this->size();
424       if (__size)
425         {
426           if (--__size > __pos)
427             __size = __pos;
428           do
429             {
430               if (!traits_type::find(__s, __n, this->_M_data()[__size]))
431                 return __size;
432             }
433           while (__size--);
434         }
435       return npos;
436     }
438   template<typename _CharT, typename _Traits, typename _Alloc,
439            template <typename, typename, typename> class _Base>
440     typename __versa_string<_CharT, _Traits, _Alloc, _Base>::size_type
441     __versa_string<_CharT, _Traits, _Alloc, _Base>::
442     find_last_not_of(_CharT __c, size_type __pos) const
443     {
444       size_type __size = this->size();
445       if (__size)
446         {
447           if (--__size > __pos)
448             __size = __pos;
449           do
450             {
451               if (!traits_type::eq(this->_M_data()[__size], __c))
452                 return __size;
453             }
454           while (__size--);
455         }
456       return npos;
457     }
459   template<typename _CharT, typename _Traits, typename _Alloc,
460            template <typename, typename, typename> class _Base>
461     int
462     __versa_string<_CharT, _Traits, _Alloc, _Base>::
463     compare(size_type __pos, size_type __n, const __versa_string& __str) const
464     {
465       _M_check(__pos, "__versa_string::compare");
466       __n = _M_limit(__pos, __n);
467       const size_type __osize = __str.size();
468       const size_type __len = std::min(__n, __osize);
469       int __r = traits_type::compare(this->_M_data() + __pos,
470                                      __str.data(), __len);
471       if (!__r)
472         __r = _S_compare(__n, __osize);
473       return __r;
474     }
476   template<typename _CharT, typename _Traits, typename _Alloc,
477            template <typename, typename, typename> class _Base>
478     int
479     __versa_string<_CharT, _Traits, _Alloc, _Base>::
480     compare(size_type __pos1, size_type __n1, const __versa_string& __str,
481             size_type __pos2, size_type __n2) const
482     {
483       _M_check(__pos1, "__versa_string::compare");
484       __str._M_check(__pos2, "__versa_string::compare");
485       __n1 = _M_limit(__pos1, __n1);
486       __n2 = __str._M_limit(__pos2, __n2);
487       const size_type __len = std::min(__n1, __n2);
488       int __r = traits_type::compare(this->_M_data() + __pos1,
489                                      __str.data() + __pos2, __len);
490       if (!__r)
491         __r = _S_compare(__n1, __n2);
492       return __r;
493     }
495   template<typename _CharT, typename _Traits, typename _Alloc,
496            template <typename, typename, typename> class _Base>
497     int
498     __versa_string<_CharT, _Traits, _Alloc, _Base>::
499     compare(const _CharT* __s) const
500     {
501       __glibcxx_requires_string(__s);
502       const size_type __size = this->size();
503       const size_type __osize = traits_type::length(__s);
504       const size_type __len = std::min(__size, __osize);
505       int __r = traits_type::compare(this->_M_data(), __s, __len);
506       if (!__r)
507         __r = _S_compare(__size, __osize);
508       return __r;
509     }
511   template<typename _CharT, typename _Traits, typename _Alloc,
512            template <typename, typename, typename> class _Base>
513     int
514     __versa_string <_CharT, _Traits, _Alloc, _Base>::
515     compare(size_type __pos, size_type __n1, const _CharT* __s) const
516     {
517       __glibcxx_requires_string(__s);
518       _M_check(__pos, "__versa_string::compare");
519       __n1 = _M_limit(__pos, __n1);
520       const size_type __osize = traits_type::length(__s);
521       const size_type __len = std::min(__n1, __osize);
522       int __r = traits_type::compare(this->_M_data() + __pos, __s, __len);
523       if (!__r)
524         __r = _S_compare(__n1, __osize);
525       return __r;
526     }
528   template<typename _CharT, typename _Traits, typename _Alloc,
529            template <typename, typename, typename> class _Base>
530     int
531     __versa_string <_CharT, _Traits, _Alloc, _Base>::
532     compare(size_type __pos, size_type __n1, const _CharT* __s,
533             size_type __n2) const
534     {
535       __glibcxx_requires_string_len(__s, __n2);
536       _M_check(__pos, "__versa_string::compare");
537       __n1 = _M_limit(__pos, __n1);
538       const size_type __len = std::min(__n1, __n2);
539       int __r = traits_type::compare(this->_M_data() + __pos, __s, __len);
540       if (!__r)
541         __r = _S_compare(__n1, __n2);
542       return __r;
543     }
545 _GLIBCXX_END_NAMESPACE
547 _GLIBCXX_BEGIN_NAMESPACE(std)
549   template<typename _CharT, typename _Traits, typename _Alloc,
550            template <typename, typename, typename> class _Base>
551     basic_istream<_CharT, _Traits>&
552     operator>>(basic_istream<_CharT, _Traits>& __in,
553                __gnu_cxx::__versa_string<_CharT, _Traits,
554                                          _Alloc, _Base>& __str)
555     {
556       typedef basic_istream<_CharT, _Traits>            __istream_type;
557       typedef typename __istream_type::ios_base         __ios_base;
558       typedef __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc, _Base>
559                                                         __string_type;
560       typedef typename __istream_type::int_type         __int_type;
561       typedef typename __string_type::size_type         __size_type;
562       typedef ctype<_CharT>                             __ctype_type;
563       typedef typename __ctype_type::ctype_base         __ctype_base;
565       __size_type __extracted = 0;
566       typename __ios_base::iostate __err = __ios_base::goodbit;
567       typename __istream_type::sentry __cerb(__in, false);
568       if (__cerb)
569         {
570           try
571             {
572               // Avoid reallocation for common case.
573               __str.erase();
574               _CharT __buf[128];
575               __size_type __len = 0;
576               const streamsize __w = __in.width();
577               const __size_type __n = __w > 0 ? static_cast<__size_type>(__w)
578                                               : __str.max_size();
579               const __ctype_type& __ct = use_facet<__ctype_type>(__in.getloc());
580               const __int_type __eof = _Traits::eof();
581               __int_type __c = __in.rdbuf()->sgetc();
583               while (__extracted < __n
584                      && !_Traits::eq_int_type(__c, __eof)
585                      && !__ct.is(__ctype_base::space,
586                                  _Traits::to_char_type(__c)))
587                 {
588                   if (__len == sizeof(__buf) / sizeof(_CharT))
589                     {
590                       __str.append(__buf, sizeof(__buf) / sizeof(_CharT));
591                       __len = 0;
592                     }
593                   __buf[__len++] = _Traits::to_char_type(__c);
594                   ++__extracted;
595                   __c = __in.rdbuf()->snextc();
596                 }
597               __str.append(__buf, __len);
599               if (_Traits::eq_int_type(__c, __eof))
600                 __err |= __ios_base::eofbit;
601               __in.width(0);
602             }
603           catch(__cxxabiv1::__forced_unwind&)
604             {
605               __in._M_setstate(__ios_base::badbit);
606               __throw_exception_again;
607             }
608           catch(...)
609             {
610               // _GLIBCXX_RESOLVE_LIB_DEFECTS
611               // 91. Description of operator>> and getline() for string<>
612               // might cause endless loop
613               __in._M_setstate(__ios_base::badbit);
614             }
615         }
616       // 211.  operator>>(istream&, string&) doesn't set failbit
617       if (!__extracted)
618         __err |= __ios_base::failbit;
619       if (__err)
620         __in.setstate(__err);
621       return __in;
622     }      
624   template<typename _CharT, typename _Traits, typename _Alloc,
625            template <typename, typename, typename> class _Base>
626     basic_istream<_CharT, _Traits>&
627     getline(basic_istream<_CharT, _Traits>& __in,
628             __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc, _Base>& __str,
629             _CharT __delim)
630     {
631       typedef basic_istream<_CharT, _Traits>            __istream_type;
632       typedef typename __istream_type::ios_base         __ios_base;
633       typedef __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc, _Base>
634                                                         __string_type;
635       typedef typename __istream_type::int_type         __int_type;
636       typedef typename __string_type::size_type         __size_type;
638       __size_type __extracted = 0;
639       const __size_type __n = __str.max_size();
640       typename __ios_base::iostate __err = __ios_base::goodbit;
641       typename __istream_type::sentry __cerb(__in, true);
642       if (__cerb)
643         {
644           try
645             {
646               // Avoid reallocation for common case.
647               __str.erase();
648               _CharT __buf[128];
649               __size_type __len = 0;
650               const __int_type __idelim = _Traits::to_int_type(__delim);
651               const __int_type __eof = _Traits::eof();
652               __int_type __c = __in.rdbuf()->sgetc();
654               while (__extracted < __n
655                      && !_Traits::eq_int_type(__c, __eof)
656                      && !_Traits::eq_int_type(__c, __idelim))
657                 {
658                   if (__len == sizeof(__buf) / sizeof(_CharT))
659                     {
660                       __str.append(__buf, sizeof(__buf) / sizeof(_CharT));
661                       __len = 0;
662                     }
663                   __buf[__len++] = _Traits::to_char_type(__c);
664                   ++__extracted;
665                   __c = __in.rdbuf()->snextc();
666                 }
667               __str.append(__buf, __len);
669               if (_Traits::eq_int_type(__c, __eof))
670                 __err |= __ios_base::eofbit;
671               else if (_Traits::eq_int_type(__c, __idelim))
672                 {
673                   ++__extracted;                  
674                   __in.rdbuf()->sbumpc();
675                 }
676               else
677                 __err |= __ios_base::failbit;
678             }
679           catch(__cxxabiv1::__forced_unwind&)
680             {
681               __in._M_setstate(__ios_base::badbit);
682               __throw_exception_again;
683             }
684           catch(...)
685             {
686               // _GLIBCXX_RESOLVE_LIB_DEFECTS
687               // 91. Description of operator>> and getline() for string<>
688               // might cause endless loop
689               __in._M_setstate(__ios_base::badbit);
690             }
691         }
692       if (!__extracted)
693         __err |= __ios_base::failbit;
694       if (__err)
695         __in.setstate(__err);
696       return __in;
697     }      
699 _GLIBCXX_END_NAMESPACE
701 #endif // _VSTRING_TCC