Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/base
diff options
context:
space:
mode:
authorSergey Yershov <yershov@corp.mail.ru>2016-05-26 19:11:11 +0300
committerSergey Yershov <yershov@corp.mail.ru>2016-05-26 19:11:11 +0300
commit01d9b2bb1ba7a6c6e318e301820e92a6b7791561 (patch)
tree652a700e197354f35e30b0d7e2d7c3486ef0a2a2 /base
parent1c92e00abd23f6e7cab2d36c264a7cb0470d2512 (diff)
[generator] Review fixes in c++ part
Diffstat (limited to 'base')
-rw-r--r--base/string_utils.cpp27
1 files changed, 14 insertions, 13 deletions
diff --git a/base/string_utils.cpp b/base/string_utils.cpp
index 4456eb25c3..d91dc5bb0d 100644
--- a/base/string_utils.cpp
+++ b/base/string_utils.cpp
@@ -42,30 +42,31 @@ UniChar LastUniChar(string const & s)
return *iter;
}
-bool to_int(char const * s, int & i, int base /*= 10*/)
+namespace
+{
+template<typename T, typename ET>
+bool IntegerCheck(T x, char const *stop, ET & out)
{
- char * stop;
- long const x = strtol(s, &stop, base);
if (*stop == 0)
{
- i = static_cast<int>(x);
- ASSERT_EQUAL(static_cast<long>(i), x, ());
+ out = static_cast<ET>(x);
+ ASSERT_EQUAL(static_cast<T>(out), x, ());
return true;
}
return false;
}
+} // namespace
+
+bool to_int(char const * s, int & i, int base /*= 10*/)
+{
+ char * stop;
+ return IntegerCheck(strtol(s, &stop, base), stop, i);
+}
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;
+ return IntegerCheck(strtoul(s, &stop, base), stop, i);
}