diff options
author | Shauren <shauren.trinity@gmail.com> | 2022-09-19 00:33:19 +0200 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2022-09-19 00:33:19 +0200 |
commit | 301572212fc54d4972b0e2989f57299f6351f495 (patch) | |
tree | 36ae5b11be8b95fb1613babbc0d358847063d5c7 /src/common/Utilities/StringFormat.h | |
parent | f67cd38312014b13624dcb5fe1d117dac4892b7d (diff) |
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
Diffstat (limited to 'src/common/Utilities/StringFormat.h')
-rw-r--r-- | src/common/Utilities/StringFormat.h | 16 |
1 files changed, 11 insertions, 5 deletions
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<typename Format, typename... Args> - inline std::string StringFormat(Format&& fmt, Args&&... args) + template<typename... Args> + std::string StringFormat(std::string_view fmt, Args&&... args) { try { - return fmt::sprintf(std::forward<Format>(fmt), std::forward<Args>(args)...); + return fmt::sprintf(fmt, std::forward<Args>(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 |