diff options
author | Shauren <shauren.trinity@gmail.com> | 2023-05-13 15:46:27 +0200 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2023-05-13 15:46:27 +0200 |
commit | 3260b94dd627b7b0c7114f94bb97d108b005af3e (patch) | |
tree | 980d58d6db4a3d20785f8bca881d36f79d0f5755 /src/common/Utilities/StringFormat.h | |
parent | c4d40085964109893c76d301b6f7d99f03838fa0 (diff) |
Core/Misc: Replace string to int conversion functions from Common.h with c++17 std::from_chars based ones Trinity::StringTo
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 7c136185f4a..b2248aff6f1 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) { |