mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Lexical casts that don't throw.
This commit is contained in:
25
src/utils.h
25
src/utils.h
@@ -158,6 +158,31 @@ inline std::string strGetEnv(const std::string& strKey)
|
||||
{
|
||||
return getenv(strKey.c_str()) ? getenv(strKey.c_str()) : "";
|
||||
}
|
||||
|
||||
template<typename T> T lexical_cast_s(const std::string& string)
|
||||
{ // lexically cast a string to the selected type. Does not throw
|
||||
try
|
||||
{
|
||||
return boost::lexical_cast<T>(string);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T> std::string lexical_cast_i(T t)
|
||||
{ // lexicaly cast the selected type to a string. Does not throw
|
||||
try
|
||||
{
|
||||
return boost::lexical_cast<std::string>(t);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// vim:ts=4
|
||||
|
||||
Reference in New Issue
Block a user