From: bangerth Date: Wed, 8 Sep 2010 14:20:48 +0000 (+0000) Subject: Fix bugs in Patterns::Integer and Patterns::Double. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7c756aa77e2c6b13351e7f737cfee31ff72897df;p=dealii-svn.git Fix bugs in Patterns::Integer and Patterns::Double. git-svn-id: https://svn.dealii.org/trunk@21879 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/base/source/parameter_handler.cc b/deal.II/base/source/parameter_handler.cc index 275d2f6441..c86927e839 100644 --- a/deal.II/base/source/parameter_handler.cc +++ b/deal.II/base/source/parameter_handler.cc @@ -39,6 +39,34 @@ DEAL_II_NAMESPACE_OPEN namespace Patterns { + namespace + { + /** + * Read to the end of the stream and + * return whether all there is is + * whitespace or whether there are other + * characters as well. + */ + bool has_only_whitespace (std::istream &in) + { + while (in) + { + char c; + + // skip if we've reached the end of + // the line + if (!(in >> c)) + break; + + if ((c != ' ') && (c != '\t')) + return false; + } + return true; + } + } + + + PatternBase::~PatternBase () {} @@ -89,19 +117,19 @@ namespace Patterns std::istringstream str(test_string); int i; - if (str >> i) - { - // check whether valid bounds - // were specified, and if so - // enforce their values - if (lower_bound <= upper_bound) - return ((lower_bound <= i) && - (upper_bound >= i)); - else - return true; - }; - - return false; + if (!(str >> i)) + return false; + + if (!has_only_whitespace (str)) + return false; + // check whether valid bounds + // were specified, and if so + // enforce their values + if (lower_bound <= upper_bound) + return ((lower_bound <= i) && + (upper_bound >= i)); + else + return true; } @@ -164,18 +192,19 @@ namespace Patterns std::istringstream str(test_string); double d; - if (str >> d) - { - // check whether valid bounds - // were specified, and if so - // enforce their values - if (lower_bound <= upper_bound) - return ((lower_bound <= d) && - (upper_bound >= d)); - else - return true; - }; - return false; + if (!(str >> d)) + return false; + + if (!has_only_whitespace (str)) + return false; + // check whether valid bounds + // were specified, and if so + // enforce their values + if (lower_bound <= upper_bound) + return ((lower_bound <= d) && + (upper_bound >= d)); + else + return true; } diff --git a/deal.II/doc/news/changes.h b/deal.II/doc/news/changes.h index d0a93a2e81..825ea958b7 100644 --- a/deal.II/doc/news/changes.h +++ b/deal.II/doc/news/changes.h @@ -170,6 +170,15 @@ through DoFHandler::get_tria() and DoFHandler::get_fe(), respectively.
    +
  1. Fixed: The Patterns::Integer and Patterns::Double classes did + not properly check that a value given matched the pattern because they + ignored text after an initial match. This led to "3.141" and + "3.141..,-RXYZ" to be recognized as valid integers and + double values, respectively. This is now fixed. +
    + (WB 2010/09/08) +

    +
  2. Fixed: The computation of quadrature points in the QGaussLobatto class uses a Newton method that was wrongly implemented. While the results were correct (at least for moderate orders), it required more