aboutsummaryrefslogtreecommitdiff
path: root/src/common/Utilities/StringFormat.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/Utilities/StringFormat.h')
-rw-r--r--src/common/Utilities/StringFormat.h59
1 files changed, 19 insertions, 40 deletions
diff --git a/src/common/Utilities/StringFormat.h b/src/common/Utilities/StringFormat.h
index f7f2b7c300b..ccad8ef2b34 100644
--- a/src/common/Utilities/StringFormat.h
+++ b/src/common/Utilities/StringFormat.h
@@ -18,6 +18,7 @@
#ifndef TRINITYCORE_STRING_FORMAT_H
#define TRINITYCORE_STRING_FORMAT_H
+#include "Define.h"
#include "Optional.h"
#include "StringFormatFwd.h"
#include <fmt/core.h>
@@ -34,56 +35,34 @@ namespace Trinity
template<typename... Args>
constexpr auto MakeFormatArgs(Args&&... args) { return fmt::make_format_args(args...); }
- /// Default TC string format function.
- template<typename... Args>
- inline std::string StringFormat(FormatString<Args...> fmt, Args&&... args)
+ namespace Impl
{
- try
- {
- return fmt::format(fmt, std::forward<Args>(args)...);
- }
- catch (std::exception const& formatError)
- {
- return fmt::format("An error occurred formatting string \"{}\" : {}", FormatStringView(fmt), formatError.what());
- }
+ TC_COMMON_API std::string StringVFormat(FormatStringView fmt, FormatArgs args) noexcept;
+
+ TC_COMMON_API void StringVFormatToImpl(fmt::detail::buffer<char>& buffer, FormatStringView fmt, FormatArgs args) noexcept;
}
- template<typename OutputIt, typename... Args>
- inline OutputIt StringFormatTo(OutputIt out, FormatString<Args...> fmt, Args&&... args)
+ using Impl::StringVFormat;
+
+ template<typename OutputIt>
+ inline OutputIt StringVFormatTo(OutputIt out, FormatStringView fmt, FormatArgs args) noexcept
{
- 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 \"{}\" : {}", FormatStringView(fmt), formatError.what());
- }
+ auto&& buf = fmt::detail::get_buffer<char>(out);
+ Trinity::Impl::StringVFormatToImpl(buf, fmt, args);
+ return fmt::detail::get_iterator(buf, out);
}
- inline std::string StringVFormat(FormatStringView fmt, FormatArgs args)
+ /// Default TC string format function.
+ template<typename... Args>
+ inline std::string StringFormat(FormatString<Args...> fmt, Args&&... args) noexcept
{
- try
- {
- return fmt::vformat(fmt, args);
- }
- catch (std::exception const& formatError)
- {
- return fmt::format("An error occurred formatting string \"{}\" : {}", fmt, formatError.what());
- }
+ return Trinity::StringVFormat(fmt, Trinity::MakeFormatArgs(std::forward<Args>(args)...));
}
- template<typename OutputIt>
- inline OutputIt StringVFormatTo(OutputIt out, FormatStringView fmt, FormatArgs args)
+ template<typename OutputIt, typename... Args>
+ inline OutputIt StringFormatTo(OutputIt out, FormatString<Args...> fmt, Args&&... args) noexcept
{
- try
- {
- return fmt::vformat_to(out, fmt, args);
- }
- catch (std::exception const& formatError)
- {
- return fmt::format_to(out, "An error occurred formatting string \"{}\" : {}", fmt, formatError.what());
- }
+ return Trinity::StringVFormatTo(out, fmt, Trinity::MakeFormatArgs(std::forward<Args>(args)...));
}
/// Returns true if the given char pointer is null.