From 4a61f74e835e7ed3b8ce13249f9a0119c5050100 Mon Sep 17 00:00:00 2001 From: Henry Winkel Date: Wed, 27 Sep 2023 10:27:11 +0200 Subject: [PATCH] ADD: added string to short function in the utils class --- include/SimCore/UtilFunctions.hpp | 1 + src/SimCore/UtilFunctions.cpp | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/include/SimCore/UtilFunctions.hpp b/include/SimCore/UtilFunctions.hpp index 4305fcb..13fa6be 100644 --- a/include/SimCore/UtilFunctions.hpp +++ b/include/SimCore/UtilFunctions.hpp @@ -19,6 +19,7 @@ namespace SimCore { static std::string implode(const std::vector &v , char delim); 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_entry(struct hostent * hostentry); static void IP_formatter(char *IPbuffer); diff --git a/src/SimCore/UtilFunctions.cpp b/src/SimCore/UtilFunctions.cpp index 6afdb61..ff27ca8 100644 --- a/src/SimCore/UtilFunctions.cpp +++ b/src/SimCore/UtilFunctions.cpp @@ -37,6 +37,18 @@ namespace SimCore { 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(UINT16_MAX) && myInt >=0) { + myInt16 = static_cast(myInt); + } + } + return myInt16; + } bool UtilFunctions::isNumber(const std::string& s)