From 301572212fc54d4972b0e2989f57299f6351f495 Mon Sep 17 00:00:00 2001 From: Shauren Date: Mon, 19 Sep 2022 00:33:19 +0200 Subject: Core/Misc: Changed string formatting functions to accept std::string_view as format argument instead being templated on it to slightly improve compile times and reduce executable size --- src/common/Utilities/StringFormat.h | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src/common/Utilities/StringFormat.h') diff --git a/src/common/Utilities/StringFormat.h b/src/common/Utilities/StringFormat.h index da1615575a4..1de56097851 100644 --- a/src/common/Utilities/StringFormat.h +++ b/src/common/Utilities/StringFormat.h @@ -23,16 +23,16 @@ namespace Trinity { /// Default TC string format function. - template - inline std::string StringFormat(Format&& fmt, Args&&... args) + template + std::string StringFormat(std::string_view fmt, Args&&... args) { try { - return fmt::sprintf(std::forward(fmt), std::forward(args)...); + return fmt::sprintf(fmt, std::forward(args)...); } - catch (const fmt::format_error& formatError) + catch (fmt::format_error const& formatError) { - std::string error = "An error occurred formatting string \"" + std::string(fmt) + "\" : " + std::string(formatError.what()); + std::string error = "An error occurred formatting string \"" + std::string(fmt) + "\" : " + formatError.what(); return error; } } @@ -48,6 +48,12 @@ namespace Trinity { return fmt.empty(); } + + /// Returns true if the given std::string_view is empty. + inline bool IsFormatEmptyOrNull(std::string_view const& fmt) + { + return fmt.empty(); + } } #endif -- cgit v1.2.3