Add helper to get int from variable

This commit is contained in:
WarmUpTill
2023-06-07 14:13:12 +02:00
committed by WarmUpTill
parent 4b0a631987
commit 6cc224aeec
4 changed files with 17 additions and 0 deletions

View File

@@ -44,4 +44,14 @@ std::optional<double> GetDouble(const std::string &str)
return {};
}
std::optional<int> GetInt(const std::string &str)
{
char *end = nullptr;
int value = std::strtol(str.c_str(), &end, 10);
if (end != str.c_str() && *end == '\0') {
return value;
}
return {};
}
} // namespace advss