all repos — fluxbox @ b76be98227bd6e62bc7e5a5fc1c3af0a3dd01b9c

custom fork of the fluxbox windowmanager

improved extract*Number functions from FbTk/StringUtil.cc
Mathias Gumz akira at fluxbox dot org
commit

b76be98227bd6e62bc7e5a5fc1c3af0a3dd01b9c

parent

6ecfa0ef3e20089e7fa3f76303847ae288e9d112

1 files changed, 22 insertions(+), 6 deletions(-)

jump to
M src/FbTk/StringUtil.ccsrc/FbTk/StringUtil.cc

@@ -63,13 +63,14 @@ using std::transform;

namespace { -int extractLongNumber(const char* in, long long int& out) { +template <typename T> +int extractBigNumber(const char* in, T (*extractFunc)(const char*, char**, int), T& out) { errno = 0; int ret = 0; char* end = 0; - long long int result = strtoll(in, &end, 0); + T result = extractFunc(in, &end, 0); if (errno == 0 && end != in) { out = result;

@@ -80,11 +81,11 @@ return ret;

} template<typename T> -int extractNumber(const std::string& in, T& out) { +int extractSignedNumber(const std::string& in, T& out) { long long int result = 0; - if (::extractLongNumber(in.c_str(), result) && out >= 0) { + if (::extractBigNumber(in.c_str(), strtoll, result)) { out = static_cast<T>(result); return 1; }

@@ -92,6 +93,21 @@

return 0; } +template<typename T> +int extractUnsignedNumber(const std::string& in, T& out) { + + unsigned long long int result = 0; + + if (::extractBigNumber(in.c_str(), strtoull, result) && result >= 0) { + out = static_cast<T>(result); + return 1; + } + + return 0; +} + + + }

@@ -100,11 +116,11 @@

namespace StringUtil { int extractNumber(const std::string& in, int& out) { - return ::extractNumber<int>(in, out); + return ::extractSignedNumber<int>(in, out); } int extractNumber(const std::string& in, unsigned int& out) { - return ::extractNumber<unsigned int>(in, out); + return ::extractUnsignedNumber<unsigned int>(in, out); } std::string number2String(int num) {