Bug 2645770: Missing getline implementation for flex_string

Implement both getline overloads. The implementation is from the SGI STL (http://www.sgi.com/tech/stl/) and comes with the following copyright:

Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose is hereby granted without fee, provided that the below copyright notice appears in all copies and that both the copyright notice and this permission notice appear in supporting documentation. Silicon Graphics makes no representations about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty.

Copyright © 1997-1999
Silicon Graphics Computer Systems, Inc.

Copyright © 1994
Hewlett-Packard Company 

git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@989 7ec92016-0320-0410-acc4-a06ded1c099a
This commit is contained in:
jfbastien 2009-03-02 14:54:16 +00:00
parent 56225861f7
commit c776744629

View file

@ -1082,10 +1082,10 @@ public:
const value_type* s, size_type n2) const const value_type* s, size_type n2) const
{ {
Enforce(pos1 <= size(), static_cast<std::out_of_range*>(0), ""); Enforce(pos1 <= size(), static_cast<std::out_of_range*>(0), "");
Procust(n1, size() - pos1); Procust(n1, size() - pos1);
// The line below fixed by Jean-Francois Bastien, 04-23-2007. Thanks! // The line below fixed by Jean-Francois Bastien, 04-23-2007. Thanks!
const int r = traits_type::compare(pos1 + data(), s, Min(n1, n2)); const int r = traits_type::compare(pos1 + data(), s, Min(n1, n2));
return r != 0 ? r : n1 > n2 ? 1 : n1 < n2 ? -1 : 0; return r != 0 ? r : n1 > n2 ? 1 : n1 < n2 ? -1 : 0;
} }
int compare(size_type pos1, size_type n1, int compare(size_type pos1, size_type n1,
@ -1265,7 +1265,7 @@ std::basic_istream<typename flex_string<E, T, A, S>::value_type,
typename flex_string<E, T, A, S>::traits_type>& typename flex_string<E, T, A, S>::traits_type>&
operator>>( operator>>(
std::basic_istream<typename flex_string<E, T, A, S>::value_type, std::basic_istream<typename flex_string<E, T, A, S>::value_type,
typename flex_string<E, T, A, S>::traits_type>& is, typename flex_string<E, T, A, S>::traits_type>& is,
flex_string<E, T, A, S>& str); flex_string<E, T, A, S>& str);
template <typename E, class T, class A, class S> template <typename E, class T, class A, class S>
@ -1273,7 +1273,7 @@ std::basic_ostream<typename flex_string<E, T, A, S>::value_type,
typename flex_string<E, T, A, S>::traits_type>& typename flex_string<E, T, A, S>::traits_type>&
operator<<( operator<<(
std::basic_ostream<typename flex_string<E, T, A, S>::value_type, std::basic_ostream<typename flex_string<E, T, A, S>::value_type,
typename flex_string<E, T, A, S>::traits_type>& os, typename flex_string<E, T, A, S>::traits_type>& os,
const flex_string<E, T, A, S>& str) const flex_string<E, T, A, S>& str)
{ return os << str.c_str(); } { return os << str.c_str(); }
@ -1284,7 +1284,37 @@ getline(
std::basic_istream<typename flex_string<E, T, A, S>::value_type, std::basic_istream<typename flex_string<E, T, A, S>::value_type,
typename flex_string<E, T, A, S>::traits_type>& is, typename flex_string<E, T, A, S>::traits_type>& is,
flex_string<E, T, A, S>& str, flex_string<E, T, A, S>& str,
typename flex_string<E, T, A, S>::value_type delim); typename flex_string<E, T, A, S>::value_type delim)
{
size_t nread = 0;
typename basic_istream<typename flex_string<E, T, A, S>::value_type,
typename flex_string<E, T, A, S>::traits_type>::sentry sentry(is, true);
if (sentry) {
basic_streambuf<typename flex_string<E, T, A, S>::value_type,
typename flex_string<E, T, A, S>::traits_type>* buf = is.rdbuf();
str.clear();
while (nread < str.max_size()) {
int c1 = buf->sbumpc();
if (flex_string<E, T, A, S>::traits_type::eq_int_type(c1, flex_string<E, T, A, S>::traits_type::eof())) {
is.setstate(ios_base::eofbit);
break;
}
else {
++nread;
typename flex_string<E, T, A, S>::value_type c = flex_string<E, T, A, S>::traits_type::to_char_type(c1);
if (!flex_string<E, T, A, S>::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 <typename E, class T, class A, class S> template <typename E, class T, class A, class S>
std::basic_istream<typename flex_string<E, T, A, S>::value_type, std::basic_istream<typename flex_string<E, T, A, S>::value_type,
@ -1292,7 +1322,10 @@ std::basic_istream<typename flex_string<E, T, A, S>::value_type,
getline( getline(
std::basic_istream<typename flex_string<E, T, A, S>::value_type, std::basic_istream<typename flex_string<E, T, A, S>::value_type,
typename flex_string<E, T, A, S>::traits_type>& is, typename flex_string<E, T, A, S>::traits_type>& is,
flex_string<E, T, A, S>& str); flex_string<E, T, A, S>& str)
{
return getline(is, str, is.widen('\n'));
}
template <typename E1, class T, class A, class S> template <typename E1, class T, class A, class S>
const typename flex_string<E1, T, A, S>::size_type const typename flex_string<E1, T, A, S>::size_type