aboutsummaryrefslogtreecommitdiff
path: root/src/common/Utilities/StringFormat.h
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2023-05-13 15:46:27 +0200
committerShauren <shauren.trinity@gmail.com>2023-05-13 15:46:27 +0200
commit3260b94dd627b7b0c7114f94bb97d108b005af3e (patch)
tree980d58d6db4a3d20785f8bca881d36f79d0f5755 /src/common/Utilities/StringFormat.h
parentc4d40085964109893c76d301b6f7d99f03838fa0 (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.h13
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)
{