diff options
author | Sergey Yershov <yershov@corp.mail.ru> | 2016-05-25 15:23:47 +0300 |
---|---|---|
committer | Sergey Yershov <yershov@corp.mail.ru> | 2016-05-25 15:23:47 +0300 |
commit | d2bcd9e16f6c386bec3175f7a48cc968a48ecdc4 (patch) | |
tree | 84045e06d654824e419bc1f130a2cb487da0742d /base | |
parent | 706e4467f3ac2cc490cf51660bc1c62733c438c0 (diff) |
Review fixes
Diffstat (limited to 'base')
-rw-r--r-- | base/string_utils.cpp | 14 | ||||
-rw-r--r-- | base/string_utils.hpp | 2 |
2 files changed, 16 insertions, 0 deletions
diff --git a/base/string_utils.cpp b/base/string_utils.cpp index da13ecb282..4456eb25c3 100644 --- a/base/string_utils.cpp +++ b/base/string_utils.cpp @@ -55,6 +55,20 @@ bool to_int(char const * s, int & i, int base /*= 10*/) return false; } +bool to_uint(char const * s, unsigned int & i, int base /*= 10*/) +{ + char * stop; + long const x = strtoul(s, &stop, base); + if (*stop == 0) + { + i = static_cast<unsigned int>(x); + ASSERT_EQUAL(static_cast<unsigned long>(i), x, ()); + return true; + } + return false; +} + + bool to_uint64(char const * s, uint64_t & i) { char * stop; diff --git a/base/string_utils.hpp b/base/string_utils.hpp index f7c5b775ff..ca5449ae2b 100644 --- a/base/string_utils.hpp +++ b/base/string_utils.hpp @@ -209,6 +209,7 @@ template <class T, size_t N, class TT> bool IsInArray(T (&arr) [N], TT const & t /// @name From string to numeric. //@{ bool to_int(char const * s, int & i, int base = 10); +bool to_uint(char const * s, unsigned int & i, int base = 10); bool to_uint64(char const * s, uint64_t & i); bool to_int64(char const * s, int64_t & i); bool to_double(char const * s, double & d); @@ -216,6 +217,7 @@ bool to_double(char const * s, double & d); inline bool is_number(string const & s) { int64_t dummy; return to_int64(s.c_str(), dummy); } inline bool to_int(string const & s, int & i, int base = 10) { return to_int(s.c_str(), i, base); } +inline bool to_uint(string const & s, unsigned int & i, int base = 10) { return to_uint(s.c_str(), i, base); } inline bool to_uint64(string const & s, uint64_t & i) { return to_uint64(s.c_str(), i); } inline bool to_int64(string const & s, int64_t & i) { return to_int64(s.c_str(), i); } inline bool to_double(string const & s, double & d) { return to_double(s.c_str(), d); } |