aboutsummaryrefslogtreecommitdiff
path: root/src/common/Utilities/StringFormat.h
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2023-01-08 21:16:53 +0100
committerShauren <shauren.trinity@gmail.com>2023-01-08 21:16:53 +0100
commitd791afae1dfcfaf592326f787755ca32d629e4d3 (patch)
tree54dc9916ede5800e110a2f0edff91530811fbdb8 /src/common/Utilities/StringFormat.h
parentb6820a706f46f18b9652fcd9806e4bec8805d29d (diff)
Core/Logging: Switch from fmt::sprintf to fmt::format (c++20 standard compatible api)
Diffstat (limited to 'src/common/Utilities/StringFormat.h')
-rw-r--r--src/common/Utilities/StringFormat.h16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/common/Utilities/StringFormat.h b/src/common/Utilities/StringFormat.h
index 1de56097851..5802ae8d617 100644
--- a/src/common/Utilities/StringFormat.h
+++ b/src/common/Utilities/StringFormat.h
@@ -18,22 +18,24 @@
#ifndef TRINITYCORE_STRING_FORMAT_H
#define TRINITYCORE_STRING_FORMAT_H
-#include "fmt/printf.h"
+#include "fmt/core.h"
namespace Trinity
{
+ template<typename... Args>
+ using FormatString = std::string_view;
+
/// Default TC string format function.
template<typename... Args>
- std::string StringFormat(std::string_view fmt, Args&&... args)
+ inline std::string StringFormat(FormatString<Args...> fmt, Args&&... args)
{
try
{
- return fmt::sprintf(fmt, std::forward<Args>(args)...);
+ return fmt::format(fmt, std::forward<Args>(args)...);
}
- catch (fmt::format_error const& formatError)
+ catch (std::exception const& formatError)
{
- std::string error = "An error occurred formatting string \"" + std::string(fmt) + "\" : " + formatError.what();
- return error;
+ return fmt::format("An error occurred formatting string \"{}\" : {}", fmt, formatError.what());
}
}
@@ -50,7 +52,7 @@ namespace Trinity
}
/// Returns true if the given std::string_view is empty.
- inline bool IsFormatEmptyOrNull(std::string_view const& fmt)
+ inline constexpr bool IsFormatEmptyOrNull(std::string_view fmt)
{
return fmt.empty();
}