]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
refactor: Use util::parse_double
authorJoel Rosdahl <joel@rosdahl.net>
Wed, 4 Aug 2021 19:42:08 +0000 (21:42 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Wed, 4 Aug 2021 19:42:08 +0000 (21:42 +0200)
src/Config.cpp

index f135b8b6f330da0feeacda5a2944532c0a3976d1..723588085340f77c7ebcb55e1f9c5bd861ca3291 100644 (file)
@@ -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<core::Error>(util::parse_double(value)), 0.0, 1.0);
     break;
 
   case ConfigItem::log_file: