catch exception in BSPF::stoi (fixes #958)

This commit is contained in:
Thomas Jentzsch 2023-02-27 19:43:23 +01:00
parent 7676e9b4c8
commit 93ea39d615
1 changed files with 7 additions and 4 deletions

View File

@ -197,10 +197,13 @@ namespace BSPF
template<int BASE = 10>
inline int stoi(string_view s, const int defaultValue = 0)
{
int i{};
s = s.substr(s.find_first_not_of(" "));
auto result = std::from_chars(s.data(), s.data() + s.size(), i, BASE);
return result.ec == std::errc() ? i : defaultValue;
try {
int i{};
s = s.substr(s.find_first_not_of(" "));
auto result = std::from_chars(s.data(), s.data() + s.size(), i, BASE);
return result.ec == std::errc() ? i : defaultValue;
}
catch(...) { return defaultValue; }
}
// Compare two strings (case insensitive)