diff options
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/stringutils.cpp | 15 | ||||
-rw-r--r-- | src/utils/stringutils.h | 2 |
2 files changed, 17 insertions, 0 deletions
diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp index 11143206e..5674abfd9 100644 --- a/src/utils/stringutils.cpp +++ b/src/utils/stringutils.cpp @@ -746,3 +746,18 @@ bool parse2Int(const std::string &args, int &x, int &y) } return isValid; } + +int parseNumber(const std::string &str) +{ + int i = 0; + int idx = 0; + if (strStartWith(str, "0x")) + idx = 2; + else if (str[0] == 'h' || str[0] == 'x') + idx = 1; + if (idx > 0) + sscanf(str.substr(idx).c_str(), "%10x", &i); + else + i = atoi(str.c_str()); + return i; +} diff --git a/src/utils/stringutils.h b/src/utils/stringutils.h index 5cf685a89..cf729c345 100644 --- a/src/utils/stringutils.h +++ b/src/utils/stringutils.h @@ -240,4 +240,6 @@ void secureChatCommand(std::string &str); bool parse2Int(const std::string &args, int &x, int &y); +int parseNumber(const std::string &str); + #endif // UTILS_STRINGUTILS_H |