From 8220a50be6bcbddf179bb855b2f7d36436fcca6b Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Fri, 7 Dec 2018 16:41:40 +0100 Subject: More gracefully handle config errors in geometries --- src/Utilities.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/Utilities.cpp') diff --git a/src/Utilities.cpp b/src/Utilities.cpp index 6346a49..dc654ea 100644 --- a/src/Utilities.cpp +++ b/src/Utilities.cpp @@ -44,7 +44,17 @@ int stringToInt(const std::string& s) if (iss.fail() || !iss.eof()) throw bad_cast(); return i; +} +int stringToInt(const std::string& s, int fallback) +{ + int i; + std::istringstream iss(s); + iss.imbue(std::locale::classic()); + iss >> i; + if (iss.fail() || !iss.eof()) + return fallback; + return i; } float stringToFloat(const std::string& s) -- cgit v1.2.3