diff options
Diffstat (limited to 'src/server')
| -rw-r--r-- | src/server/game/Chat/ChatCommands/ChatCommandArgs.h | 15 | ||||
| -rw-r--r-- | src/server/game/Chat/Hyperlinks.h | 31 |
2 files changed, 19 insertions, 27 deletions
diff --git a/src/server/game/Chat/ChatCommands/ChatCommandArgs.h b/src/server/game/Chat/ChatCommands/ChatCommandArgs.h index ca94835272f..7b38bbb3a43 100644 --- a/src/server/game/Chat/ChatCommands/ChatCommandArgs.h +++ b/src/server/game/Chat/ChatCommands/ChatCommandArgs.h @@ -21,6 +21,7 @@ #include "ChatCommandHelpers.h" #include "ChatCommandTags.h" #include "SmartEnum.h" +#include "StringConvert.h" #include "Util.h" #include <charconv> #include <map> @@ -55,20 +56,10 @@ struct ArgInfo<T, std::enable_if_t<std::is_integral_v<T>>> char const* next = args; std::string_view token(args, Trinity::Impl::ChatCommands::tokenize(next)); - if (!token.length()) - return nullptr; - - std::from_chars_result result; - if (StringStartsWith(token, "0x")) - result = std::from_chars(token.data() + 2, token.data() + token.length(), val, 16); - else if (StringStartsWith(token, "0b")) - result = std::from_chars(token.data() + 2, token.data() + token.length(), val, 2); + if (Optional<T> v = StringTo<T>(token, 0)) + val = *v; else - result = std::from_chars(token.data(), token.data() + token.length(), val, 10); - - if ((token.data() + token.length()) != result.ptr) return nullptr; - return next; } }; diff --git a/src/server/game/Chat/Hyperlinks.h b/src/server/game/Chat/Hyperlinks.h index f47235e409a..18297cedc48 100644 --- a/src/server/game/Chat/Hyperlinks.h +++ b/src/server/game/Chat/Hyperlinks.h @@ -19,6 +19,7 @@ #define TRINITY_HYPERLINKS_H #include "ObjectGuid.h" +#include "StringConvert.h" #include <string> #include <type_traits> #include <utility> @@ -105,26 +106,26 @@ namespace Trinity::Hyperlinks } template <typename T> - static std::enable_if_t<std::is_integral_v<T> && std::is_unsigned_v<T>, bool> StoreTo(T& val, char const* pos, size_t len) + static std::enable_if_t<std::is_integral_v<T>, bool> StoreTo(T& val, char const* pos, size_t len) { - try { val = std::stoull(std::string(pos, len)); } - catch (...) { return false; } - return true; - } - - template <typename T> - static std::enable_if_t<std::is_integral_v<T> && std::is_signed_v<T>, bool> StoreTo(T& val, char const* pos, size_t len) - { - try { val = std::stoll(std::string(pos, len)); } - catch (...) { return false; } - return true; + if (Optional<T> res = Trinity::StringTo<T>(std::string_view(pos, len))) + { + val = *res; + return true; + } + else + return false; } static bool StoreTo(ObjectGuid& val, char const* pos, size_t len) { - try { val.Set(std::stoul(std::string(pos, len), nullptr, 16)); } - catch (...) { return false; } - return true; + if (Optional<uint64> res = Trinity::StringTo<uint64>(std::string_view(pos, len), 16)) + { + val.Set(*res); + return true; + } + else + return false; } }; |
