libstdc++
GNU C++ library
Loading...
Searching...
No Matches

◆ getline() [4/9]

template<typename _CharT, typename _Traits, typename _Alloc, template< typename, typename, typename > class _Base>
basic_istream< _CharT, _Traits > & std::getline ( basic_istream< _CharT, _Traits > & __is,
__gnu_cxx::__versa_string< _CharT, _Traits, _Alloc, _Base > & __str,
_CharT __delim )

Read a line from stream into a string.

Parameters
__isInput stream.
__strBuffer to store into.
__delimCharacter marking end of line.
Returns
Reference to the input stream.

Stores characters from __is into __str until __delim is found, the end of the stream is encountered, or str.max_size() is reached. If is.width() is non-zero, that is the limit on the number of characters stored into __str. Any previous contents of __str are erased. If delim was encountered, it is extracted but not stored into __str.

Definition at line 631 of file vstring.tcc.

634 {
635 typedef basic_istream<_CharT, _Traits> __istream_type;
636 typedef typename __istream_type::ios_base __ios_base;
638 __string_type;
639 typedef typename __istream_type::int_type __int_type;
640 typedef typename __string_type::size_type __size_type;
641
642 __size_type __extracted = 0;
643 const __size_type __n = __str.max_size();
644 typename __ios_base::iostate __err = __ios_base::goodbit;
645 typename __istream_type::sentry __cerb(__in, true);
646 if (__cerb)
647 {
648 __try
649 {
650 // Avoid reallocation for common case.
651 __str.erase();
652 _CharT __buf[128];
653 __size_type __len = 0;
654 const __int_type __idelim = _Traits::to_int_type(__delim);
655 const __int_type __eof = _Traits::eof();
656 __int_type __c = __in.rdbuf()->sgetc();
657
658 while (__extracted < __n
659 && !_Traits::eq_int_type(__c, __eof)
660 && !_Traits::eq_int_type(__c, __idelim))
661 {
662 if (__len == sizeof(__buf) / sizeof(_CharT))
663 {
664 __str.append(__buf, sizeof(__buf) / sizeof(_CharT));
665 __len = 0;
666 }
667 __buf[__len++] = _Traits::to_char_type(__c);
668 ++__extracted;
669 __c = __in.rdbuf()->snextc();
670 }
671 __str.append(__buf, __len);
672
673 if (_Traits::eq_int_type(__c, __eof))
674 __err |= __ios_base::eofbit;
675 else if (_Traits::eq_int_type(__c, __idelim))
676 {
677 ++__extracted;
678 __in.rdbuf()->sbumpc();
679 }
680 else
681 __err |= __ios_base::failbit;
682 }
683 __catch(__cxxabiv1::__forced_unwind&)
684 {
685 __in._M_setstate(__ios_base::badbit);
687 }
688 __catch(...)
689 {
690 // _GLIBCXX_RESOLVE_LIB_DEFECTS
691 // 91. Description of operator>> and getline() for string<>
692 // might cause endless loop
693 __in._M_setstate(__ios_base::badbit);
694 }
695 }
696 if (!__extracted)
697 __err |= __ios_base::failbit;
698 if (__err)
699 __in.setstate(__err);
700 return __in;
701 }
#define __try
#define __throw_exception_again
#define __catch(X)
Template class basic_istream.
Definition istream:67
__versa_string & append(const __versa_string &__str)
Append a string to this string.
Definition vstring.h:698
__versa_string & erase(size_type __pos=0, size_type __n=npos)
Remove characters.
Definition vstring.h:1179
size_type max_size() const noexcept
Returns the size() of the largest possible string.
Definition vstring.h:442
Template class __versa_string.
Definition vstring.h:63

References __catch, __throw_exception_again, __try, std::basic_ios< _CharT, _Traits >::_M_setstate(), __gnu_cxx::__versa_string< _CharT, _Traits, _Alloc, _Base >::append(), __gnu_cxx::__versa_string< _CharT, _Traits, _Alloc, _Base >::erase(), getline(), __gnu_cxx::__versa_string< _CharT, _Traits, _Alloc, _Base >::max_size(), std::basic_ios< _CharT, _Traits >::rdbuf(), and std::basic_ios< _CharT, _Traits >::setstate().

Here is the call graph for this function: