diff --git a/src/utils.h b/src/utils.h index 1d15a1a9b0..0e1fead5cc 100644 --- a/src/utils.h +++ b/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 T lexical_cast_s(const std::string& string) +{ // lexically cast a string to the selected type. Does not throw + try + { + return boost::lexical_cast(string); + } + catch (...) + { + return 0; + } +} + +template std::string lexical_cast_i(T t) +{ // lexicaly cast the selected type to a string. Does not throw + try + { + return boost::lexical_cast(t); + } + catch (...) + { + return ""; + } +} + #endif // vim:ts=4