diff options
author | Shauren <shauren.trinity@gmail.com> | 2023-05-13 15:46:27 +0200 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2023-08-15 21:59:52 +0200 |
commit | a4299c2a4b88d1cbdcea1301a190da6081abf876 (patch) | |
tree | 85b194c12b0413b8da3ad554633ddeb0fec98185 /src/common/Utilities/StringFormat.h | |
parent | b9201d3c07ecbd690117d248bec238e3657b57b9 (diff) |
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)
Diffstat (limited to 'src/common/Utilities/StringFormat.h')
-rw-r--r-- | src/common/Utilities/StringFormat.h | 13 |
1 files changed, 13 insertions, 0 deletions
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<typename OutputIt, typename... Args> + inline OutputIt StringFormatTo(OutputIt out, FormatString<Args...> fmt, Args&&... args) + { + try + { + return fmt::format_to(out, fmt, std::forward<Args>(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) { |