Commit 813ae317 authored by aligungr's avatar aligungr

PS establishment over CLI

parent e52975bf
...@@ -221,6 +221,24 @@ std::string utils::VectorToHexString(const std::vector<uint8_t> &hex) ...@@ -221,6 +221,24 @@ std::string utils::VectorToHexString(const std::vector<uint8_t> &hex)
return str; return str;
} }
bool utils::TryParseInt(const std::string &str, int &output)
{
return TryParseInt(str.c_str(), output);
}
bool utils::TryParseInt(const char *str, int &output)
{
try
{
output = std::stoi(str);
return true;
}
catch (...)
{
return false;
}
}
int utils::ParseInt(const std::string &str) int utils::ParseInt(const std::string &str)
{ {
return ParseInt(str.c_str()); return ParseInt(str.c_str());
...@@ -228,11 +246,9 @@ int utils::ParseInt(const std::string &str) ...@@ -228,11 +246,9 @@ int utils::ParseInt(const std::string &str)
int utils::ParseInt(const char *str) int utils::ParseInt(const char *str)
{ {
std::stringstream ss(""); int n = 0;
ss << str; TryParseInt(str, n);
int i; return n;
ss >> i;
return i;
} }
uint64_t utils::Random64() uint64_t utils::Random64()
...@@ -319,21 +335,3 @@ void utils::Trim(std::stringstream &s) ...@@ -319,21 +335,3 @@ void utils::Trim(std::stringstream &s)
Trim(str); Trim(str);
s.str(str); s.str(str);
} }
bool utils::TryParseInt(const std::string &str, int &output)
{
return TryParseInt(str.c_str(), output);
}
bool utils::TryParseInt(const char *str, int &output)
{
try
{
output = std::stoi(str);
return true;
}
catch (...)
{
return false;
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment