]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Fix bugs in Patterns::Integer and Patterns::Double.
authorbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 8 Sep 2010 14:20:48 +0000 (14:20 +0000)
committerbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 8 Sep 2010 14:20:48 +0000 (14:20 +0000)
git-svn-id: https://svn.dealii.org/trunk@21879 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/base/source/parameter_handler.cc
deal.II/doc/news/changes.h

index 275d2f6441c5420c6a9ee5941868c7c7d4e7b203..c86927e83904006d4b81e385ab5c6d71b3a4e6d7 100644 (file)
@@ -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;
   }
 
 
index d0a93a2e81c05e8d6adff773adafd509209b922d..825ea958b7e6269954d57ba0599e9928ed0695e0 100644 (file)
@@ -170,6 +170,15 @@ through DoFHandler::get_tria() and DoFHandler::get_fe(), respectively.
 
 
 <ol>
+  <li><p> 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 <code>"3.141"</code> and
+  <code>"3.141..,-RXYZ"</code> to be recognized as valid integers and
+  double values, respectively. This is now fixed.
+  <br>
+  (WB 2010/09/08)
+  </p>
+
   <li><p> 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

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.