ADD: added string to short function in the utils class

This commit is contained in:
Henry Winkel
2023-09-27 10:27:11 +02:00
parent 91ccccb134
commit 4a61f74e83
2 changed files with 13 additions and 0 deletions

View File

@@ -19,6 +19,7 @@ namespace SimCore {
static std::string implode(const std::vector<std::string> &v , char delim); static std::string implode(const std::vector<std::string> &v , char delim);
static bool isNumber(const std::string& s); static bool isNumber(const std::string& s);
static std::uint16_t StringToUShort(std::string str);
static void check_host_name(int hostname); static void check_host_name(int hostname);
static void check_host_entry(struct hostent * hostentry); static void check_host_entry(struct hostent * hostentry);
static void IP_formatter(char *IPbuffer); static void IP_formatter(char *IPbuffer);

View File

@@ -37,6 +37,18 @@ namespace SimCore {
return ret; return ret;
} }
std::uint16_t UtilFunctions::StringToUShort(std::string str)
{
std::uint16_t myInt16(0);
if(!std::empty(str))
{
int myInt(std::stoi(str));
if (myInt <= static_cast<int>(UINT16_MAX) && myInt >=0) {
myInt16 = static_cast<uint16_t>(myInt);
}
}
return myInt16;
}
bool UtilFunctions::isNumber(const std::string& s) bool UtilFunctions::isNumber(const std::string& s)