From: bangerth Date: Sun, 20 Jul 2014 19:24:26 +0000 (+0000) Subject: In string_to_int, strip spaces at the front and back as we used to do. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fheads%2Ftrunk;p=dealii-svn.git In string_to_int, strip spaces at the front and back as we used to do. git-svn-id: https://svn.dealii.org/trunk@33203 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/source/base/utilities.cc b/deal.II/source/base/utilities.cc index b014ee6ff7..a09e9dabf1 100644 --- a/deal.II/source/base/utilities.cc +++ b/deal.II/source/base/utilities.cc @@ -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."));