Fix istream>>Quotient at EOF

This commit is contained in:
Marc Glisse 2010-12-20 20:48:26 +00:00
parent 41ae6a0cac
commit 92921b3a2a
1 changed files with 16 additions and 25 deletions

View File

@ -36,8 +36,7 @@
#define CGAL_QUOTIENT_H #define CGAL_QUOTIENT_H
#include <utility> #include <utility>
#include <locale> #include <istream>
#include <cctype>
#include <CGAL/Interval_nt.h> #include <CGAL/Interval_nt.h>
#include <CGAL/Kernel/mpl.h> #include <CGAL/Kernel/mpl.h>
@ -418,7 +417,7 @@ template <class NT>
std::ostream& std::ostream&
operator<<(std::ostream& s, const Quotient<NT>& r) operator<<(std::ostream& s, const Quotient<NT>& r)
{ {
return s << r.numerator() << "/" << r.denominator(); return s << r.numerator() << '/' << r.denominator();
} }
template <class NT> template <class NT>
@ -427,30 +426,22 @@ operator>>(std::istream& in, Quotient<NT>& r)
{ {
/* format num/den or simply num */ /* format num/den or simply num */
char c = 0; NT num,den=1;
while (in.get(c) && std::isspace(c, std::locale::classic() )) {}
if ( !in ) return in;
in.putback(c);
NT num;
NT den(1);
in >> num; in >> num;
if(!in) return in;
while (in.get(c) && std::isspace(c, std::locale::classic() )) {} std::istream::sentry s(in); // skip whitespace
if (( in ) && ( c == '/')) if(in.peek()!='/'){
{ if(!in.good()){
while (in.get(c) && std::isspace(c, std::locale::classic() )) {} in.clear(std::ios_base::eofbit);
CGAL_assertion( in != 0 ); // unlikely to be some other reason?
in.putback(c); }
in >> den; } else {
char c;
in.get(c); // remove the '/'
in >> den;
if(!in) return in;
} }
else r=Quotient<NT>(num,den);
{
in.putback(c);
if ( in.eof() ) in.clear();
}
r = Quotient<NT>( num, den);
return in; return in;
} }