diff --git a/include/loki/flex/flex_string_shell.h b/include/loki/flex/flex_string_shell.h index 3e967ff..cc620c8 100644 --- a/include/loki/flex/flex_string_shell.h +++ b/include/loki/flex/flex_string_shell.h @@ -1082,10 +1082,10 @@ public: const value_type* s, size_type n2) const { Enforce(pos1 <= size(), static_cast(0), ""); - Procust(n1, size() - pos1); - // The line below fixed by Jean-Francois Bastien, 04-23-2007. Thanks! - const int r = traits_type::compare(pos1 + data(), s, Min(n1, n2)); - return r != 0 ? r : n1 > n2 ? 1 : n1 < n2 ? -1 : 0; + Procust(n1, size() - pos1); + // The line below fixed by Jean-Francois Bastien, 04-23-2007. Thanks! + const int r = traits_type::compare(pos1 + data(), s, Min(n1, n2)); + return r != 0 ? r : n1 > n2 ? 1 : n1 < n2 ? -1 : 0; } int compare(size_type pos1, size_type n1, @@ -1265,7 +1265,7 @@ std::basic_istream::value_type, typename flex_string::traits_type>& operator>>( std::basic_istream::value_type, - typename flex_string::traits_type>& is, + typename flex_string::traits_type>& is, flex_string& str); template @@ -1273,7 +1273,7 @@ std::basic_ostream::value_type, typename flex_string::traits_type>& operator<<( std::basic_ostream::value_type, - typename flex_string::traits_type>& os, + typename flex_string::traits_type>& os, const flex_string& str) { return os << str.c_str(); } @@ -1284,7 +1284,37 @@ getline( std::basic_istream::value_type, typename flex_string::traits_type>& is, flex_string& str, - typename flex_string::value_type delim); + typename flex_string::value_type delim) +{ + size_t nread = 0; + typename basic_istream::value_type, + typename flex_string::traits_type>::sentry sentry(is, true); + if (sentry) { + basic_streambuf::value_type, + typename flex_string::traits_type>* buf = is.rdbuf(); + str.clear(); + + while (nread < str.max_size()) { + int c1 = buf->sbumpc(); + if (flex_string::traits_type::eq_int_type(c1, flex_string::traits_type::eof())) { + is.setstate(ios_base::eofbit); + break; + } + else { + ++nread; + typename flex_string::value_type c = flex_string::traits_type::to_char_type(c1); + if (!flex_string::traits_type::eq(c, delim)) + str.push_back(c); + else + break; // Character is extracted but not appended. + } + } + } + if (nread == 0 || nread >= str.max_size()) + is.setstate(ios_base::failbit); + + return is; +} template std::basic_istream::value_type, @@ -1292,7 +1322,10 @@ std::basic_istream::value_type, getline( std::basic_istream::value_type, typename flex_string::traits_type>& is, - flex_string& str); + flex_string& str) +{ + return getline(is, str, is.widen('\n')); +} template const typename flex_string::size_type