diff options
Diffstat (limited to 'src/StringUtils.cpp')
-rw-r--r-- | src/StringUtils.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/StringUtils.cpp b/src/StringUtils.cpp index 6a8d3f2..5706499 100644 --- a/src/StringUtils.cpp +++ b/src/StringUtils.cpp @@ -171,6 +171,31 @@ namespace QuickMedia { return true; } + bool to_num_hex(const char *str, size_t size, int &num) { + size_t i = 0; + const bool is_negative = size > 0 && str[0] == '-'; + if(is_negative) + i = 1; + + num = 0; + for(; i < size; ++i) { + const signed char c = str[i]; + if(c - '0' <= 9) + num = (num << 4) | (c - '0'); + else if(c - 'a' <= 'f' - 'a') + num = (num << 4) | (10 + (c - 'a')); + else if(c - 'A' <= 'F' - 'A') + num = (num << 4) | (10 + (c - 'A')); + else + return false; + } + + if(is_negative) + num = -num; + + return true; + } + // Returns relative time as a string (approximation) std::string seconds_to_relative_time_str(time_t seconds) { seconds = std::max(0L, seconds); |