From: Joel Rosdahl Date: Wed, 4 Aug 2021 19:42:08 +0000 (+0200) Subject: refactor: Use util::parse_double X-Git-Tag: v4.4~57 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d0a9ef93a37344d2c559a37a8a0d096415a58231;p=thirdparty%2Fccache.git refactor: Use util::parse_double --- diff --git a/src/Config.cpp b/src/Config.cpp index f135b8b6f..723588085 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -228,22 +228,6 @@ format_bool(bool value) return value ? "true" : "false"; } -double -parse_double(const std::string& value) -{ - size_t end; - double result; - try { - result = std::stod(value, &end); - } catch (std::exception& e) { - throw core::Error(e.what()); - } - if (end != value.size()) { - throw core::Error("invalid floating point: \"{}\"", value); - } - return result; -} - std::string format_cache_size(uint64_t value) { @@ -924,7 +908,8 @@ Config::set_item(const std::string& key, break; case ConfigItem::limit_multiple: - m_limit_multiple = Util::clamp(parse_double(value), 0.0, 1.0); + m_limit_multiple = Util::clamp( + util::value_or_throw(util::parse_double(value)), 0.0, 1.0); break; case ConfigItem::log_file: