Time and integer parsing

This commit is contained in:
Dan Paulat 2024-02-20 23:26:02 -06:00
parent c8d8b24317
commit 2cd76d7da4
4 changed files with 62 additions and 0 deletions

View file

@ -88,5 +88,24 @@ std::string ToString(const std::vector<std::string>& v)
return value;
}
template<typename T>
std::optional<T> TryParseUnsignedLong(const std::string& str)
{
std::optional<T> value = std::nullopt;
try
{
value = static_cast<T>(std::stoul(str));
}
catch (const std::exception&)
{
}
return value;
}
template std::optional<std::uint16_t>
TryParseUnsignedLong<std::uint16_t>(const std::string& str);
} // namespace util
} // namespace scwx