# vstring.tcc

Go to the documentation of this file.

    00001 // Versatile string -*- C++ -*-
    00002
    00003 // Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc.
    00004 //
    00005 // This file is part of the GNU ISO C++ Library.  This library is free
    00006 // software; you can redistribute it and/or modify it under the
    00007 // terms of the GNU General Public License as published by the
    00008 // Free Software Foundation; either version 2, or (at your option)
    00009 // any later version.
    00010
    00011 // This library is distributed in the hope that it will be useful,
    00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
    00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00014 // GNU General Public License for more details.
    00015
    00016 // You should have received a copy of the GNU General Public License along
    00017 // with this library; see the file COPYING.  If not, write to the Free
    00018 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
    00019 // USA.
    00020
    00021 // As a special exception, you may use this file as part of a free software
    00022 // library without restriction.  Specifically, if other files instantiate
    00023 // templates or use macros or inline functions from this file, or you compile
    00024 // this file and link it with other files to produce an executable, this
    00025 // file does not by itself cause the resulting executable to be covered by
    00026 // the GNU General Public License.  This exception does not however
    00027 // invalidate any other reasons why the executable file might be covered by
    00028 // the GNU General Public License.
    00029
    00030 /** @file ext/vstring.tcc
    00031  *  This file is a GNU extension to the Standard C++ Library.
    00032  *  This is an internal header file, included by other library headers.
    00033  *  You should not attempt to use it directly.
    00034  */
    00035
    00036 #ifndef _VSTRING_TCC
    00037 #define _VSTRING_TCC 1
    00038
    00039 #pragma GCC system_header
    00040
    00041 _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
    00042
    00043   template<typename _CharT, typename _Traits, typename _Alloc,
    00044        template <typename, typename, typename> class _Base>
    00045     const typename __versa_string<_CharT, _Traits, _Alloc, _Base>::size_type
    00046     __versa_string<_CharT, _Traits, _Alloc, _Base>::npos;
    00047
    00048   template<typename _CharT, typename _Traits, typename _Alloc,
    00049        template <typename, typename, typename> class _Base>
    00050     void
    00051     __versa_string<_CharT, _Traits, _Alloc, _Base>::
    00052     resize(size_type __n, _CharT __c)
    00053     {
    00054       const size_type __size = this->size();
    00055       if (__size < __n)
    00056     this->append(__n - __size, __c);
    00057       else if (__n < __size)
    00058     this->_M_erase(__n, __size - __n);
    00059     }
    00060
    00061   template<typename _CharT, typename _Traits, typename _Alloc,
    00062        template <typename, typename, typename> class _Base>
    00063     __versa_string<_CharT, _Traits, _Alloc, _Base>&
    00064     __versa_string<_CharT, _Traits, _Alloc, _Base>::
    00065     _M_append(const _CharT* __s, size_type __n)
    00066     {
    00067       const size_type __len = __n + this->size();
    00068
    00069       if (__len <= this->capacity() && !this->_M_is_shared())
    00070     {
    00071       if (__n)
    00072         this->_S_copy(this->_M_data() + this->size(), __s, __n);
    00073     }
    00074       else
    00075     this->_M_mutate(this->size(), size_type(0), __s, __n);
    00076
    00077       this->_M_set_length(__len);
    00078       return *this;
    00079     }
    00080
    00081   template<typename _CharT, typename _Traits, typename _Alloc,
    00082        template <typename, typename, typename> class _Base>
    00083     template<typename _InputIterator>
    00084       __versa_string<_CharT, _Traits, _Alloc, _Base>&
    00085       __versa_string<_CharT, _Traits, _Alloc, _Base>::
    00086       _M_replace_dispatch(iterator __i1, iterator __i2, _InputIterator __k1,
    00087               _InputIterator __k2, std::__false_type)
    00088       {
    00089     const __versa_string __s(__k1, __k2);
    00090     const size_type __n1 = __i2 - __i1;
    00091     return _M_replace(__i1 - _M_ibegin(), __n1, __s._M_data(),
    00092               __s.size());
    00093       }
    00094
    00095   template<typename _CharT, typename _Traits, typename _Alloc,
    00096        template <typename, typename, typename> class _Base>
    00097     __versa_string<_CharT, _Traits, _Alloc, _Base>&
    00098     __versa_string<_CharT, _Traits, _Alloc, _Base>::
    00099     _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2,
    00100            _CharT __c)
    00101     {
    00102       _M_check_length(__n1, __n2, "__versa_string::_M_replace_aux");
    00103
    00104       const size_type __old_size = this->size();
    00105       const size_type __new_size = __old_size + __n2 - __n1;
    00106
    00107       if (__new_size <= this->capacity() && !this->_M_is_shared())
    00108     {
    00109       _CharT* __p = this->_M_data() + __pos1;
    00110
    00111       const size_type __how_much = __old_size - __pos1 - __n1;
    00112       if (__how_much && __n1 != __n2)
    00113         this->_S_move(__p + __n2, __p + __n1, __how_much);
    00114     }
    00115       else
    00116     this->_M_mutate(__pos1, __n1, 0, __n2);
    00117
    00118       if (__n2)
    00119     this->_S_assign(this->_M_data() + __pos1, __n2, __c);
    00120
    00121       this->_M_set_length(__new_size);
    00122       return *this;
    00123     }
    00124
    00125   template<typename _CharT, typename _Traits, typename _Alloc,
    00126        template <typename, typename, typename> class _Base>
    00127     __versa_string<_CharT, _Traits, _Alloc, _Base>&
    00128     __versa_string<_CharT, _Traits, _Alloc, _Base>::
    00129     _M_replace(size_type __pos, size_type __len1, const _CharT* __s,
    00130            const size_type __len2)
    00131     {
    00132       _M_check_length(__len1, __len2, "__versa_string::_M_replace");
    00133
    00134       const size_type __old_size = this->size();
    00135       const size_type __new_size = __old_size + __len2 - __len1;
    00136
    00137       if (__new_size <= this->capacity() && !this->_M_is_shared())
    00138     {
    00139       _CharT* __p = this->_M_data() + __pos;
    00140
    00141       const size_type __how_much = __old_size - __pos - __len1;
    00142       if (_M_disjunct(__s))
    00143         {
    00144           if (__how_much && __len1 != __len2)
    00145         this->_S_move(__p + __len2, __p + __len1, __how_much);
    00146           if (__len2)
    00147         this->_S_copy(__p, __s, __len2);
    00148         }
    00149       else
    00150         {
    00151           // Work in-place.
    00152           if (__len2 && __len2 <= __len1)
    00153         this->_S_move(__p, __s, __len2);
    00154           if (__how_much && __len1 != __len2)
    00155         this->_S_move(__p + __len2, __p + __len1, __how_much);
    00156           if (__len2 > __len1)
    00157         {
    00158           if (__s + __len2 <= __p + __len1)
    00159             this->_S_move(__p, __s, __len2);
    00160           else if (__s >= __p + __len1)
    00161             this->_S_copy(__p, __s + __len2 - __len1, __len2);
    00162           else
    00163             {
    00164               const size_type __nleft = (__p + __len1) - __s;
    00165               this->_S_move(__p, __s, __nleft);
    00166               this->_S_copy(__p + __nleft, __p + __len2,
    00167                     __len2 - __nleft);
    00168             }
    00169         }
    00170         }
    00171     }
    00172       else
    00173     this->_M_mutate(__pos, __len1, __s, __len2);
    00174
    00175       this->_M_set_length(__new_size);
    00176       return *this;
    00177     }
    00178
    00179   template<typename _CharT, typename _Traits, typename _Alloc,
    00180        template <typename, typename, typename> class _Base>
    00181     __versa_string<_CharT, _Traits, _Alloc, _Base>
    00182     operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
    00183           const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
    00184     {
    00185       __versa_string<_CharT, _Traits, _Alloc, _Base> __str;
    00186       __str.reserve(__lhs.size() + __rhs.size());
    00187       __str.append(__lhs);
    00188       __str.append(__rhs);
    00189       return __str;
    00190     }
    00191
    00192   template<typename _CharT, typename _Traits, typename _Alloc,
    00193        template <typename, typename, typename> class _Base>
    00194     __versa_string<_CharT, _Traits, _Alloc, _Base>
    00195     operator+(const _CharT* __lhs,
    00196           const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
    00197     {
    00198       __glibcxx_requires_string(__lhs);
    00199       typedef __versa_string<_CharT, _Traits, _Alloc, _Base> __string_type;
    00200       typedef typename __string_type::size_type   __size_type;
    00201       const __size_type __len = _Traits::length(__lhs);
    00202       __string_type __str;
    00203       __str.reserve(__len + __rhs.size());
    00204       __str.append(__lhs, __len);
    00205       __str.append(__rhs);
    00206       return __str;
    00207     }
    00208
    00209   template<typename _CharT, typename _Traits, typename _Alloc,
    00210        template <typename, typename, typename> class _Base>
    00211     __versa_string<_CharT, _Traits, _Alloc, _Base>
    00212     operator+(_CharT __lhs,
    00213           const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs)
    00214     {
    00215       __versa_string<_CharT, _Traits, _Alloc, _Base> __str;
    00216       __str.reserve(__rhs.size() + 1);
    00217       __str.push_back(__lhs);
    00218       __str.append(__rhs);
    00219       return __str;
    00220     }
    00221
    00222   template<typename _CharT, typename _Traits, typename _Alloc,
    00223        template <typename, typename, typename> class _Base>
    00224     __versa_string<_CharT, _Traits, _Alloc, _Base>
    00225     operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
    00226           const _CharT* __rhs)
    00227     {
    00228       __glibcxx_requires_string(__rhs);
    00229       typedef __versa_string<_CharT, _Traits, _Alloc, _Base> __string_type;
    00230       typedef typename __string_type::size_type   __size_type;
    00231       const __size_type __len = _Traits::length(__rhs);
    00232       __string_type __str;
    00233       __str.reserve(__lhs.size() + __len);
    00234       __str.append(__lhs);
    00235       __str.append(__rhs, __len);
    00236       return __str;
    00237     }
    00238
    00239   template<typename _CharT, typename _Traits, typename _Alloc,
    00240        template <typename, typename, typename> class _Base>
    00241     __versa_string<_CharT, _Traits, _Alloc, _Base>
    00242     operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs,
    00243           _CharT __rhs)
    00244     {
    00245       __versa_string<_CharT, _Traits, _Alloc, _Base> __str;
    00246       __str.reserve(__lhs.size() + 1);
    00247       __str.append(__lhs);
    00248       __str.push_back(__rhs);
    00249       return __str;
    00250     }
    00251
    00252   template<typename _CharT, typename _Traits, typename _Alloc,
    00253        template <typename, typename, typename> class _Base>
    00254     typename __versa_string<_CharT, _Traits, _Alloc, _Base>::size_type
    00255     __versa_string<_CharT, _Traits, _Alloc, _Base>::
    00256     copy(_CharT* __s, size_type __n, size_type __pos) const
    00257     {
    00258       _M_check(__pos, "__versa_string::copy");
    00259       __n = _M_limit(__pos, __n);
    00260       __glibcxx_requires_string_len(__s, __n);
    00261       if (__n)
    00262     this->_S_copy(__s, this->_M_data() + __pos, __n);
    00263       // 21.3.5.7 par 3: do not append null.  (good.)
    00264       return __n;
    00265     }
    00266
    00267   template<typename _CharT, typename _Traits, typename _Alloc,
    00268        template <typename, typename, typename> class _Base>
    00269     typename __versa_string<_CharT, _Traits, _Alloc, _Base>::size_type
    00270     __versa_string<_CharT, _Traits, _Alloc, _Base>::
    00271     find(const _CharT* __s, size_type __pos, size_type __n) const
    00272     {
    00273       __glibcxx_requires_string_len(__s, __n);
    00274       const size_type __size = this->size();
    00275       const _CharT* __data = this->_M_data();
    00276
    00277       if (__n == 0)
    00278     return __pos <= __size ? __pos : npos;
    00279
    00280       if (__n <= __size)
    00281     {
    00282       for (; __pos <= __size - __n; ++__pos)
    00283         if (traits_type::eq(__data[__pos], __s[0])
    00284         && traits_type::compare(__data + __pos + 1,
    00285                     __s + 1, __n - 1) == 0)
    00286           return __pos;
    00287     }
    00288       return npos;
    00289     }
    00290
    00291   template<typename _CharT, typename _Traits, typename _Alloc,
    00292        template <typename, typename, typename> class _Base>
    00293     typename __versa_string<_CharT, _Traits, _Alloc, _Base>::size_type
    00294     __versa_string<_CharT, _Traits, _Alloc, _Base>::
    00295     find(_CharT __c, size_type __pos) const
    00296     {
    00297       size_type __ret = npos;
    00298       const size_type __size = this->size();
    00299       if (__pos < __size)
    00300     {
    00301       const _CharT* __data = this->_M_data();
    00302       const size_type __n = __size - __pos;
    00303       const _CharT* __p = traits_type::find(__data + __pos, __n, __c);
    00304       if (__p)
    00305         __ret = __p - __data;
    00306     }
    00307       return __ret;
    00308     }
    00309
    00310   template<typename _CharT, typename _Traits, typename _Alloc,
    00311        template <typename, typename, typename> class _Base>
    00312     typename __versa_string<_CharT, _Traits, _Alloc, _Base>::size_type
    00313     __versa_string<_CharT, _Traits, _Alloc, _Base>::
    00314     rfind(const _CharT* __s, size_type __pos, size_type __n) const
    00315     {
    00316       __glibcxx_requires_string_len(__s, __n);
    00317       const size_type __size = this->size();
    00318       if (__n <= __size)
    00319     {
    00320       __pos = std::min(size_type(__size - __n), __pos);
    00321       const _CharT* __data = this->_M_data();
    00322       do
    00323         {
    00324           if (traits_type::compare(__data + __pos, __s, __n) == 0)
    00325         return __pos;
    00326         }
    00327       while (__pos-- > 0);
    00328     }
    00329       return npos;
    00330     }
    00331
    00332   template<typename _CharT, typename _Traits, typename _Alloc,
    00333        template <typename, typename, typename> class _Base>
    00334     typename __versa_string<_CharT, _Traits, _Alloc, _Base>::size_type
    00335     __versa_string<_CharT, _Traits, _Alloc, _Base>::
    00336     rfind(_CharT __c, size_type __pos) const
    00337     {
    00338       size_type __size = this->size();
    00339       if (__size)
    00340     {
    00341       if (--__size > __pos)
    00342         __size = __pos;
    00343       for (++__size; __size-- > 0; )
    00344         if (traits_type::eq(this->_M_data()[__size], __c))
    00345           return __size;
    00346     }
    00347       return npos;
    00348     }
    00349
    00350   template<typename _CharT, typename _Traits, typename _Alloc,
    00351        template <typename, typename, typename> class _Base>
    00352     typename __versa_string<_CharT, _Traits, _Alloc, _Base>::size_type
    00353     __versa_string<_CharT, _Traits, _Alloc, _Base>::
    00354     find_first_of(const _CharT* __s, size_type __pos, size_type __n) const
    00355     {
    00356       __glibcxx_requires_string_len(__s, __n);
    00357       for (; __n && __pos < this->size(); ++__pos)
    00358     {
    00359       const _CharT* __p = traits_type::find(__s, __n,
    00360                         this->_M_data()[__pos]);
    00361       if (__p)
    00362         return __pos;
    00363     }
    00364       return npos;
    00365     }
    00366
    00367   template<typename _CharT, typename _Traits, typename _Alloc,
    00368        template <typename, typename, typename> class _Base>
    00369     typename __versa_string<_CharT, _Traits, _Alloc, _Base>::size_type
    00370     __versa_string<_CharT, _Traits, _Alloc, _Base>::
    00371     find_last_of(const _CharT* __s, size_type __pos, size_type __n) const
    00372     {
    00373       __glibcxx_requires_string_len(__s, __n);
    00374       size_type __size = this->size();
    00375       if (__size && __n)
    00376     {
    00377       if (--__size > __pos)
    00378         __size = __pos;
    00379       do
    00380         {
    00381           if (traits_type::find(__s, __n, this->_M_data()[__size]))
    00382         return __size;
    00383         }
    00384       while (__size-- != 0);
    00385     }
    00386       return npos;
    00387     }
    00388
    00389   template<typename _CharT, typename _Traits, typename _Alloc,
    00390        template <typename, typename, typename> class _Base>
    00391     typename __versa_string<_CharT, _Traits, _Alloc, _Base>::size_type
    00392     __versa_string<_CharT, _Traits, _Alloc, _Base>::
    00393     find_first_not_of(const _CharT* __s, size_type __pos, size_type __n) const
    00394     {
    00395       __glibcxx_requires_string_len(__s, __n);
    00396       for (; __pos < this->size(); ++__pos)
    00397     if (!traits_type::find(__s, __n, this->_M_data()[__pos]))
    00398       return __pos;
    00399       return npos;
    00400     }
    00401
    00402   template<typename _CharT, typename _Traits, typename _Alloc,
    00403        template <typename, typename, typename> class _Base>
    00404     typename __versa_string<_CharT, _Traits, _Alloc, _Base>::size_type
    00405     __versa_string<_CharT, _Traits, _Alloc, _Base>::
    00406     find_first_not_of(_CharT __c, size_type __pos) const
    00407     {
    00408       for (; __pos < this->size(); ++__pos)
    00409     if (!traits_type::eq(this->_M_data()[__pos], __c))
    00410       return __pos;
    00411       return npos;
    00412     }
    00413
    00414   template<typename _CharT, typename _Traits, typename _Alloc,
    00415        template <typename, typename, typename> class _Base>
    00416     typename __versa_string<_CharT, _Traits, _Alloc, _Base>::size_type
    00417     __versa_string<_CharT, _Traits, _Alloc, _Base>::
    00418     find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const
    00419     {
    00420       __glibcxx_requires_string_len(__s, __n);
    00421       size_type __size = this->size();
    00422       if (__size)
    00423     {
    00424       if (--__size > __pos)
    00425         __size = __pos;
    00426       do
    00427         {
    00428           if (!traits_type::find(__s, __n, this->_M_data()[__size]))
    00429         return __size;
    00430         }
    00431       while (__size--);
    00432     }
    00433       return npos;
    00434     }
    00435
    00436   template<typename _CharT, typename _Traits, typename _Alloc,
    00437        template <typename, typename, typename> class _Base>
    00438     typename __versa_string<_CharT, _Traits, _Alloc, _Base>::size_type
    00439     __versa_string<_CharT, _Traits, _Alloc, _Base>::
    00440     find_last_not_of(_CharT __c, size_type __pos) const
    00441     {
    00442       size_type __size = this->size();
    00443       if (__size)
    00444     {
    00445       if (--__size > __pos)
    00446         __size = __pos;
    00447       do
    00448         {
    00449           if (!traits_type::eq(this->_M_data()[__size], __c))
    00450         return __size;
    00451         }
    00452       while (__size--);
    00453     }
    00454       return npos;
    00455     }
    00456
    00457   template<typename _CharT, typename _Traits, typename _Alloc,
    00458        template <typename, typename, typename> class _Base>
    00459     int
    00460     __versa_string<_CharT, _Traits, _Alloc, _Base>::
    00461     compare(size_type __pos, size_type __n, const __versa_string& __str) const
    00462     {
    00463       _M_check(__pos, "__versa_string::compare");
    00464       __n = _M_limit(__pos, __n);
    00465       const size_type __osize = __str.size();
    00466       const size_type __len = std::min(__n, __osize);
    00467       int __r = traits_type::compare(this->_M_data() + __pos,
    00468                      __str.data(), __len);
    00469       if (!__r)
    00470     __r = __n - __osize;
    00471       return __r;
    00472     }
    00473
    00474   template<typename _CharT, typename _Traits, typename _Alloc,
    00475        template <typename, typename, typename> class _Base>
    00476     int
    00477     __versa_string<_CharT, _Traits, _Alloc, _Base>::
    00478     compare(size_type __pos1, size_type __n1, const __versa_string& __str,
    00479         size_type __pos2, size_type __n2) const
    00480     {
    00481       _M_check(__pos1, "__versa_string::compare");
    00482       __str._M_check(__pos2, "__versa_string::compare");
    00483       __n1 = _M_limit(__pos1, __n1);
    00484       __n2 = __str._M_limit(__pos2, __n2);
    00485       const size_type __len = std::min(__n1, __n2);
    00486       int __r = traits_type::compare(this->_M_data() + __pos1,
    00487                      __str.data() + __pos2, __len);
    00488       if (!__r)
    00489     __r = __n1 - __n2;
    00490       return __r;
    00491     }
    00492
    00493   template<typename _CharT, typename _Traits, typename _Alloc,
    00494        template <typename, typename, typename> class _Base>
    00495     int
    00496     __versa_string<_CharT, _Traits, _Alloc, _Base>::
    00497     compare(const _CharT* __s) const
    00498     {
    00499       __glibcxx_requires_string(__s);
    00500       const size_type __size = this->size();
    00501       const size_type __osize = traits_type::length(__s);
    00502       const size_type __len = std::min(__size, __osize);
    00503       int __r = traits_type::compare(this->_M_data(), __s, __len);
    00504       if (!__r)
    00505     __r = __size - __osize;
    00506       return __r;
    00507     }
    00508
    00509   template<typename _CharT, typename _Traits, typename _Alloc,
    00510        template <typename, typename, typename> class _Base>
    00511     int
    00512     __versa_string <_CharT, _Traits, _Alloc, _Base>::
    00513     compare(size_type __pos, size_type __n1, const _CharT* __s) const
    00514     {
    00515       __glibcxx_requires_string(__s);
    00516       _M_check(__pos, "__versa_string::compare");
    00517       __n1 = _M_limit(__pos, __n1);
    00518       const size_type __osize = traits_type::length(__s);
    00519       const size_type __len = std::min(__n1, __osize);
    00520       int __r = traits_type::compare(this->_M_data() + __pos, __s, __len);
    00521       if (!__r)
    00522     __r = __n1 - __osize;
    00523       return __r;
    00524     }
    00525
    00526   template<typename _CharT, typename _Traits, typename _Alloc,
    00527        template <typename, typename, typename> class _Base>
    00528     int
    00529     __versa_string <_CharT, _Traits, _Alloc, _Base>::
    00530     compare(size_type __pos, size_type __n1, const _CharT* __s,
    00531         size_type __n2) const
    00532     {
    00533       __glibcxx_requires_string_len(__s, __n2);
    00534       _M_check(__pos, "__versa_string::compare");
    00535       __n1 = _M_limit(__pos, __n1);
    00536       const size_type __len = std::min(__n1, __n2);
    00537       int __r = traits_type::compare(this->_M_data() + __pos, __s, __len);
    00538       if (!__r)
    00539     __r = __n1 - __n2;
    00540       return __r;
    00541     }
    00542
    00543 _GLIBCXX_END_NAMESPACE
    00544
    00545 _GLIBCXX_BEGIN_NAMESPACE(std)
    00546
    00547   template<typename _CharT, typename _Traits, typename _Alloc,
    00548            template <typename, typename, typename> class _Base>
    00549     basic_istream<_CharT, _Traits>&
    00550     operator>>(basic_istream<_CharT, _Traits>& __in,
    00551            __gnu_cxx::__versa_string<_CharT, _Traits,
    00552                                      _Alloc, _Base>& __str)
    00553     {
    00554       typedef basic_istream<_CharT, _Traits>            __istream_type;
    00555       typedef typename __istream_type::int_type     __int_type;
    00556       typedef typename __istream_type::__streambuf_type __streambuf_type;
    00557       typedef typename __istream_type::__ctype_type __ctype_type;
    00558       typedef __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc, _Base>
    00559                                                     __string_type;
    00560       typedef typename __string_type::size_type     __size_type;
    00561
    00562       __size_type __extracted = 0;
    00563       ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
    00564       typename __istream_type::sentry __cerb(__in, false);
    00565       if (__cerb)
    00566     {
    00567       try
    00568         {
    00569           // Avoid reallocation for common case.
    00570           __str.erase();
    00571           _CharT __buf[128];
    00572           __size_type __len = 0;
    00573           const streamsize __w = __in.width();
    00574           const __size_type __n = __w > 0 ? static_cast<__size_type>(__w)
    00575                                       : __str.max_size();
    00576           const __ctype_type& __ct = use_facet<__ctype_type>(__in.getloc());
    00577           const __int_type __eof = _Traits::eof();
    00578           __streambuf_type* __sb = __in.rdbuf();
    00579           __int_type __c = __sb->sgetc();
    00580
    00581           while (__extracted < __n
    00582              && !_Traits::eq_int_type(__c, __eof)
    00583              && !__ct.is(ctype_base::space, _Traits::to_char_type(__c)))
    00584         {
    00585           if (__len == sizeof(__buf) / sizeof(_CharT))
    00586             {
    00587               __str.append(__buf, sizeof(__buf) / sizeof(_CharT));
    00588               __len = 0;
    00589             }
    00590           __buf[__len++] = _Traits::to_char_type(__c);
    00591           ++__extracted;
    00592           __c = __sb->snextc();
    00593         }
    00594           __str.append(__buf, __len);
    00595
    00596           if (_Traits::eq_int_type(__c, __eof))
    00597         __err |= ios_base::eofbit;
    00598           __in.width(0);
    00599         }
    00600       catch(...)
    00601         {
    00602           // _GLIBCXX_RESOLVE_LIB_DEFECTS
    00603           // 91. Description of operator>> and getline() for string<>
    00604           // might cause endless loop
    00605           __in._M_setstate(ios_base::badbit);
    00606         }
    00607     }
    00608       // 211.  operator>>(istream&, string&) doesn't set failbit
    00609       if (!__extracted)
    00610     __err |= ios_base::failbit;
    00611       if (__err)
    00612     __in.setstate(__err);
    00613       return __in;
    00614     }
    00615
    00616   template<typename _CharT, typename _Traits, typename _Alloc,
    00617            template <typename, typename, typename> class _Base>
    00618     basic_istream<_CharT, _Traits>&
    00619     getline(basic_istream<_CharT, _Traits>& __in,
    00620         __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc, _Base>& __str,
    00621         _CharT __delim)
    00622     {
    00623       typedef basic_istream<_CharT, _Traits>            __istream_type;
    00624       typedef typename __istream_type::int_type     __int_type;
    00625       typedef typename __istream_type::__streambuf_type __streambuf_type;
    00626       typedef typename __istream_type::__ctype_type __ctype_type;
    00627       typedef __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc, _Base>
    00628                                                     __string_type;
    00629       typedef typename __string_type::size_type     __size_type;
    00630
    00631       __size_type __extracted = 0;
    00632       const __size_type __n = __str.max_size();
    00633       ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
    00634       typename __istream_type::sentry __cerb(__in, true);
    00635       if (__cerb)
    00636     {
    00637       try
    00638         {
    00639           // Avoid reallocation for common case.
    00640           __str.erase();
    00641           _CharT __buf[128];
    00642           __size_type __len = 0;
    00643           const __int_type __idelim = _Traits::to_int_type(__delim);
    00644           const __int_type __eof = _Traits::eof();
    00645           __streambuf_type* __sb = __in.rdbuf();
    00646           __int_type __c = __sb->sgetc();
    00647
    00648           while (__extracted < __n
    00649              && !_Traits::eq_int_type(__c, __eof)
    00650              && !_Traits::eq_int_type(__c, __idelim))
    00651         {
    00652           if (__len == sizeof(__buf) / sizeof(_CharT))
    00653             {
    00654               __str.append(__buf, sizeof(__buf) / sizeof(_CharT));
    00655               __len = 0;
    00656             }
    00657           __buf[__len++] = _Traits::to_char_type(__c);
    00658           ++__extracted;
    00659           __c = __sb->snextc();
    00660         }
    00661           __str.append(__buf, __len);
    00662
    00663           if (_Traits::eq_int_type(__c, __eof))
    00664         __err |= ios_base::eofbit;
    00665           else if (_Traits::eq_int_type(__c, __idelim))
    00666         {
    00667           ++__extracted;
    00668           __sb->sbumpc();
    00669         }
    00670           else
    00671         __err |= ios_base::failbit;
    00672         }
    00673       catch(...)
    00674         {
    00675           // _GLIBCXX_RESOLVE_LIB_DEFECTS
    00676           // 91. Description of operator>> and getline() for string<>
    00677           // might cause endless loop
    00678           __in._M_setstate(ios_base::badbit);
    00679         }
    00680     }
    00681       if (!__extracted)
    00682     __err |= ios_base::failbit;
    00683       if (__err)
    00684     __in.setstate(__err);
    00685       return __in;
    00686     }
    00687
    00688 _GLIBCXX_END_NAMESPACE
    00689
    00690 #endif // _VSTRING_TCC