From 6d125e6c36f2499151424f78b44b51428087438c Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 18 Jun 2013 22:11:44 +0200 Subject: [PATCH] do not use std::{to_string,stoi} as they cause problems with cygwin --- src/color.cc | 3 ++- src/command_manager.cc | 2 +- src/string.cc | 17 ++++++++++------- src/string.hh | 4 ++-- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/color.cc b/src/color.cc index 7e8e9b01..aa1980d9 100644 --- a/src/color.cc +++ b/src/color.cc @@ -20,7 +20,8 @@ Color str_to_color(const String& color) static const Regex rgb_regex{"rgb:[0-9a-fA-F]{6}"}; if (boost::regex_match(color, rgb_regex)) { - long l = stol(color.substr(ByteCount{4}), NULL, 16); + unsigned l; + sscanf(color.c_str() + 4, "%x", &l); return { (unsigned char)((l >> 16) & 0xFF), (unsigned char)((l >> 8) & 0xFF), (unsigned char)(l & 0xFF) }; diff --git a/src/command_manager.cc b/src/command_manager.cc index 4bad2eb4..7de7209a 100644 --- a/src/command_manager.cc +++ b/src/command_manager.cc @@ -79,7 +79,7 @@ bool is_horizontal_blank(char c) struct unterminated_string : parse_error { - unterminated_string(const std::string& open, const std::string& close, int nest = 0) + unterminated_string(const String& open, const String& close, int nest = 0) : parse_error{"unterminated string '" + open + "..." + close + "'" + (nest > 0 ? "(nesting: " + to_string(nest) + ")" : "")} {} 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 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) diff --git a/src/string.hh b/src/string.hh index fb80d425..a64bf180 100644 --- a/src/string.hh +++ b/src/string.hh @@ -103,10 +103,10 @@ void option_from_string(const String& str, Regex& re); int str_to_int(const String& str); -using std::to_string; +String to_string(int val); template -std::string to_string(const StronglyTypedNumber& val) +String to_string(const StronglyTypedNumber& val) { return to_string((ValueType)val); }