mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 19:10:06 +00:00
Time and integer parsing
This commit is contained in:
parent
c8d8b24317
commit
2cd76d7da4
4 changed files with 62 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue