diff --git a/src/numberparsing.h b/src/numberparsing.h index 17205aa..632802e 100644 --- a/src/numberparsing.h +++ b/src/numberparsing.h @@ -94,4 +94,20 @@ template<> inline std::expected fromString(std: return std::unexpected(fmt::format("invalid uint64_t {}", str)); return val; } + +template<> inline std::expected fromString(std::string_view str) +{ + float val; + if (std::sscanf(str.data(), "%f", &val) != 1) + return std::unexpected(fmt::format("invalid float {}", str)); + return val; +} + +template<> inline std::expected fromString(std::string_view str) +{ + double val; + if (std::sscanf(str.data(), "%lf", &val) != 1) + return std::unexpected(fmt::format("invalid double {}", str)); + return val; +} } // namespace cpputils