From a4299c2a4b88d1cbdcea1301a190da6081abf876 Mon Sep 17 00:00:00 2001 From: Shauren Date: Sat, 13 May 2023 15:46:27 +0200 Subject: Core/Misc: Replace string to int conversion functions from Common.h with c++17 std::from_chars based ones Trinity::StringTo (cherry picked from commit 3260b94dd627b7b0c7114f94bb97d108b005af3e) --- src/common/Utilities/StringFormat.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/common/Utilities/StringFormat.h') diff --git a/src/common/Utilities/StringFormat.h b/src/common/Utilities/StringFormat.h index c95039efea4..9bef5516139 100644 --- a/src/common/Utilities/StringFormat.h +++ b/src/common/Utilities/StringFormat.h @@ -39,6 +39,19 @@ namespace Trinity } } + template + inline OutputIt StringFormatTo(OutputIt out, FormatString fmt, Args&&... args) + { + try + { + return fmt::format_to(out, fmt, std::forward(args)...); + } + catch (std::exception const& formatError) + { + return fmt::format_to(out, "An error occurred formatting string \"{}\" : {}", fmt, formatError.what()); + } + } + /// Returns true if the given char pointer is null. inline bool IsFormatEmptyOrNull(char const* fmt) { -- cgit v1.2.3