]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
In string_to_int, strip spaces at the front and back as we used to do. trunk
authorbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Sun, 20 Jul 2014 19:24:26 +0000 (19:24 +0000)
committerbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Sun, 20 Jul 2014 19:24:26 +0000 (19:24 +0000)
git-svn-id: https://svn.dealii.org/trunk@33203 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/source/base/utilities.cc

index b014ee6ff7d85c2f33a861282f7d9d2d8eb943e4..a09e9dabf160b1611f3f6635ed255e63416764cd 100644 (file)
@@ -147,9 +147,17 @@ namespace Utilities
 
 
   int
-  string_to_int (const std::string &s)
+  string_to_int (const std::string &s_)
   {
+    // trim whitespace on either side of the text if necessary
+    std::string s = s_;
+    while ((s.size() > 0) && (s[0] == ' '))
+      s.erase (s.begin());
+    while ((s.size() > 0) && (s[s.size()-1] == ' '))
+      s.erase (s.end()-1);
+
     char *p;
+    errno = 0;
     const int i = std::strtol(s.c_str(), &p, 10);
     AssertThrow ( !((errno != 0) || (s.size() == 0) || ((s.size()>0) && (*p != '\0'))),
                   ExcMessage ("Can't convert <" + s + "> to an integer."));

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.