22 #ifndef GEARS_IO_GETLINE_HPP
23 #define GEARS_IO_GETLINE_HPP
45 template<
typename CharT,
typename Traits,
typename Alloc,
typename Pred>
46 inline auto getline_until(std::basic_istream<CharT, Traits>& in, std::basic_string<CharT, Traits, Alloc>& str, Pred p) -> decltype(in) {
47 std::ios_base::iostate state = std::ios_base::goodbit;
48 bool extracted =
false;
49 const typename std::basic_istream<CharT, Traits>::sentry s(in,
true);
53 typename Traits::int_type ch = in.rdbuf()->sgetc();
54 for(; ; ch = in.rdbuf()->snextc()) {
55 if(Traits::eq_int_type(ch, Traits::eof())) {
57 state |= std::ios_base::eofbit;
60 else if(p(Traits::to_char_type(ch))) {
66 else if(str.max_size() <= str.size()) {
68 state |= std::ios_base::failbit;
73 str.push_back(Traits::to_char_type(ch));
79 in.setstate(std::ios_base::badbit);
84 state |= std::ios_base::failbit;
93 #endif // GEARS_IO_GETLINE_HPP