From fe4a79a754d14af52bc9637ae74876c7e11a4ee1 Mon Sep 17 00:00:00 2001 From: bangerth Date: Sun, 20 Jul 2014 19:24:26 +0000 Subject: [PATCH] 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 --- deal.II/source/base/utilities.cc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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.")); -- 2.39.5