summaryrefslogtreecommitdiff
path: root/src/string.cc
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2013-06-18 22:11:44 +0200
committerMaxime Coste <frrrwww@gmail.com>2013-06-19 19:29:05 +0100
commit6d125e6c36f2499151424f78b44b51428087438c (patch)
tree184ceb7a0378600ab72d0b77bfa2d506d083007d /src/string.cc
parenta642026e7c2c839e5f080b30b21808049b8b0f55 (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.cc17
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)