diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2013-06-18 22:11:44 +0200 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2013-06-19 19:29:05 +0100 |
| commit | 6d125e6c36f2499151424f78b44b51428087438c (patch) | |
| tree | 184ceb7a0378600ab72d0b77bfa2d506d083007d /src/string.cc | |
| parent | a642026e7c2c839e5f080b30b21808049b8b0f55 (diff) | |
do not use std::{to_string,stoi} as they cause problems with cygwin
Diffstat (limited to 'src/string.cc')
| -rw-r--r-- | src/string.cc | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/src/string.cc b/src/string.cc index 2c180e50..2c6bb140 100644 --- a/src/string.cc +++ b/src/string.cc @@ -25,14 +25,17 @@ std::vector<String> split(const String& str, char separator) int str_to_int(const String& str) { - try - { - return stoi(str); - } - catch (std::logic_error&) - { + int res = 0; + if (sscanf(str.c_str(), "%i", &res) != 1) throw runtime_error(str + "is not a number"); - } + return res; +} + +String to_string(int val) +{ + char buf[16]; + sprintf(buf, "%i", val); + return buf; } String option_to_string(const Regex& re) |
