From f45aa5cac1579e87cbc599ffb58e10e662066792 Mon Sep 17 00:00:00 2001 From: Treeston Date: Wed, 2 Sep 2020 22:04:45 +0200 Subject: Common/Util: Trinity::StringTo support (PR #25364) --- .../game/Chat/ChatCommands/ChatCommandArgs.h | 30 ++++------------------ 1 file changed, 5 insertions(+), 25 deletions(-) (limited to 'src/server') diff --git a/src/server/game/Chat/ChatCommands/ChatCommandArgs.h b/src/server/game/Chat/ChatCommands/ChatCommandArgs.h index 583edcd40e2..9f10013989c 100644 --- a/src/server/game/Chat/ChatCommands/ChatCommandArgs.h +++ b/src/server/game/Chat/ChatCommands/ChatCommandArgs.h @@ -45,9 +45,9 @@ namespace Trinity::Impl::ChatCommands template struct ArgInfo { static_assert(!std::is_same_v, "Invalid command parameter type - see ChatCommandArgs.h for possible types"); }; -// catch-all for integral types +// catch-all for number types template -struct ArgInfo>> +struct ArgInfo || std::is_floating_point_v>> { static Optional TryConsume(T& val, std::string_view args) { @@ -59,34 +59,14 @@ struct ArgInfo>> val = *v; else return std::nullopt; - return tail; - } -}; - -// catch-all for floating point types -template -struct ArgInfo>> -{ - static Optional TryConsume(T& val, std::string_view args) - { - auto [token, tail] = tokenize(args); - if (token.empty()) - return std::nullopt; - try + if constexpr (std::is_floating_point_v) { - // @todo replace this once libc++ supports double args to from_chars for required minimum - size_t processedChars = 0; - val = std::stold(std::string(token), &processedChars); - if (processedChars != token.length()) + if (!std::isfinite(val)) return std::nullopt; } - catch (...) { return std::nullopt; } - if (std::isfinite(val)) - return tail; - else - return std::nullopt; + return tail; } }; -- cgit v1.2.3