diff options
author | Kitzunu <24550914+Kitzunu@users.noreply.github.com> | 2024-09-03 12:59:37 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-03 07:59:37 -0300 |
commit | de2bcbdabf19cb05682b2087b42726ee2325fe8e (patch) | |
tree | 79b0cbc222519b7c283938daecbbce0c4b2a29a6 /src/common | |
parent | f6fd978a7a871ff91ad67e60284c5195e227dcd5 (diff) |
refactor(Core/Misc): Acore::StringFormat to fmt format (#19838)
refactor(Core/Utilities): Acore::StringFormat to fmt format
* closes https://github.com/azerothcore/azerothcore-wotlk/issues/10356
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/Banner.cpp | 2 | ||||
-rw-r--r-- | src/common/Collision/Management/MMapMgr.cpp | 4 | ||||
-rw-r--r-- | src/common/Configuration/Config.cpp | 8 | ||||
-rw-r--r-- | src/common/Debugging/Errors.cpp | 16 | ||||
-rw-r--r-- | src/common/Debugging/Errors.h | 6 | ||||
-rw-r--r-- | src/common/Logging/AppenderConsole.cpp | 4 | ||||
-rw-r--r-- | src/common/Logging/AppenderFile.cpp | 4 | ||||
-rw-r--r-- | src/common/Logging/Log.h | 4 | ||||
-rw-r--r-- | src/common/Utilities/StringFormat.h | 19 | ||||
-rw-r--r-- | src/common/Utilities/Timer.cpp | 12 |
10 files changed, 32 insertions, 47 deletions
diff --git a/src/common/Banner.cpp b/src/common/Banner.cpp index f77c9abeea..65f5ab577f 100644 --- a/src/common/Banner.cpp +++ b/src/common/Banner.cpp @@ -21,7 +21,7 @@ void Acore::Banner::Show(std::string_view applicationName, void(*log)(std::string_view text), void(*logExtraInfo)()) { - log(Acore::StringFormatFmt("{} ({})", GitRevision::GetFullVersion(), applicationName)); + log(Acore::StringFormat("{} ({})", GitRevision::GetFullVersion(), applicationName)); log("<Ctrl-C> to stop.\n"); log(" █████╗ ███████╗███████╗██████╗ ██████╗ ████████╗██╗ ██╗"); log(" ██╔══██╗╚══███╔╝██╔════╝██╔══██╗██╔═══██╗╚══██╔══╝██║ ██║"); diff --git a/src/common/Collision/Management/MMapMgr.cpp b/src/common/Collision/Management/MMapMgr.cpp index bb67910573..480a2db2d5 100644 --- a/src/common/Collision/Management/MMapMgr.cpp +++ b/src/common/Collision/Management/MMapMgr.cpp @@ -85,7 +85,7 @@ namespace MMAP } // load and init dtNavMesh - read parameters from file - std::string fileName = Acore::StringFormat(MAP_FILE_NAME_FORMAT, sConfigMgr->GetOption<std::string>("DataDir", ".").c_str(), mapId); + std::string fileName = Acore::StringFormat(MAP_FILE_NAME_FORMAT, sConfigMgr->GetOption<std::string>("DataDir", "."), mapId); FILE* file = fopen(fileName.c_str(), "rb"); if (!file) @@ -146,7 +146,7 @@ namespace MMAP } // load this tile :: mmaps/MMMXXYY.mmtile - std::string fileName = Acore::StringFormat(TILE_FILE_NAME_FORMAT, sConfigMgr->GetOption<std::string>("DataDir", ".").c_str(), mapId, x, y); + std::string fileName = Acore::StringFormat(TILE_FILE_NAME_FORMAT, sConfigMgr->GetOption<std::string>("DataDir", "."), mapId, x, y); FILE* file = fopen(fileName.c_str(), "rb"); if (!file) { diff --git a/src/common/Configuration/Config.cpp b/src/common/Configuration/Config.cpp index 2261c14b10..5f653fa968 100644 --- a/src/common/Configuration/Config.cpp +++ b/src/common/Configuration/Config.cpp @@ -65,7 +65,7 @@ namespace template<typename Format, typename... Args> inline void PrintError(std::string_view filename, Format&& fmt, Args&& ... args) { - std::string message = Acore::StringFormatFmt(std::forward<Format>(fmt), std::forward<Args>(args)...); + std::string message = Acore::StringFormat(std::forward<Format>(fmt), std::forward<Args>(args)...); if (IsAppConfig(filename)) { @@ -117,7 +117,7 @@ namespace return false; } - throw ConfigException(Acore::StringFormatFmt("Config::LoadFile: Failed open {}file '{}'", isOptional ? "optional " : "", file)); + throw ConfigException(Acore::StringFormat("Config::LoadFile: Failed open {}file '{}'", isOptional ? "optional " : "", file)); } uint32 count = 0; @@ -144,7 +144,7 @@ namespace // read line error if (!in.good() && !in.eof()) - throw ConfigException(Acore::StringFormatFmt("> Config::LoadFile: Failure to read line number {} in file '{}'", lineNumber, file)); + throw ConfigException(Acore::StringFormat("> Config::LoadFile: Failure to read line number {} in file '{}'", lineNumber, file)); // remove whitespace in line line = Acore::String::Trim(line, in.getloc()); @@ -187,7 +187,7 @@ namespace return false; } - throw ConfigException(Acore::StringFormatFmt("Config::LoadFile: Empty file '{}'", file)); + throw ConfigException(Acore::StringFormat("Config::LoadFile: Empty file '{}'", file)); } // Add correct keys if file load without errors diff --git a/src/common/Debugging/Errors.cpp b/src/common/Debugging/Errors.cpp index 9ca5f8c294..b42b34a187 100644 --- a/src/common/Debugging/Errors.cpp +++ b/src/common/Debugging/Errors.cpp @@ -62,19 +62,19 @@ namespace inline std::string MakeMessage(std::string_view messageType, std::string_view file, uint32 line, std::string_view function, std::string_view message, std::string_view fmtMessage = {}, std::string_view debugInfo = {}) { - std::string msg = Acore::StringFormatFmt("\n>> {}\n\n# Location: {}:{}\n# Function: {}\n# Condition: {}\n", messageType, file, line, function, message); + std::string msg = Acore::StringFormat("\n>> {}\n\n# Location: {}:{}\n# Function: {}\n# Condition: {}\n", messageType, file, line, function, message); if (!fmtMessage.empty()) { - msg.append(Acore::StringFormatFmt("# Message: {}\n", fmtMessage)); + msg.append(Acore::StringFormat("# Message: {}\n", fmtMessage)); } if (!debugInfo.empty()) { - msg.append(Acore::StringFormatFmt("\n# Debug info: {}\n", debugInfo)); + msg.append(Acore::StringFormat("\n# Debug info: {}\n", debugInfo)); } - return Acore::StringFormatFmt( + return Acore::StringFormat( "#{0:-^{2}}#\n" " {1: ^{2}} \n" "#{0:-^{2}}#\n", "", msg, 70); @@ -90,14 +90,14 @@ namespace */ inline std::string MakeAbortMessage(std::string_view file, uint32 line, std::string_view function, std::string_view fmtMessage = {}) { - std::string msg = Acore::StringFormatFmt("\n>> ABORTED\n\n# Location '{}:{}'\n# Function '{}'\n", file, line, function); + std::string msg = Acore::StringFormat("\n>> ABORTED\n\n# Location '{}:{}'\n# Function '{}'\n", file, line, function); if (!fmtMessage.empty()) { - msg.append(Acore::StringFormatFmt("# Message '{}'\n", fmtMessage)); + msg.append(Acore::StringFormat("# Message '{}'\n", fmtMessage)); } - return Acore::StringFormatFmt( + return Acore::StringFormat( "\n#{0:-^{2}}#\n" " {1: ^{2}} \n" "#{0:-^{2}}#\n", "", msg, 70); @@ -148,7 +148,7 @@ void Acore::Abort(std::string_view file, uint32 line, std::string_view function, void Acore::AbortHandler(int sigval) { // nothing useful to log here, no way to pass args - std::string formattedMessage = StringFormatFmt("Caught signal {}\n", sigval); + std::string formattedMessage = StringFormat("Caught signal {}\n", sigval); fmt::print(stderr, "{}", formattedMessage); fflush(stderr); Crash(formattedMessage.c_str()); diff --git a/src/common/Debugging/Errors.h b/src/common/Debugging/Errors.h index 0155d0ddb8..24a36f1e8d 100644 --- a/src/common/Debugging/Errors.h +++ b/src/common/Debugging/Errors.h @@ -31,19 +31,19 @@ namespace Acore template<typename... Args> AC_COMMON_API inline void Assert(std::string_view file, uint32 line, std::string_view function, std::string_view debugInfo, std::string_view message, std::string_view fmt, Args&&... args) { - Assert(file, line, function, debugInfo, message, StringFormatFmt(fmt, std::forward<Args>(args)...)); + Assert(file, line, function, debugInfo, message, StringFormat(fmt, std::forward<Args>(args)...)); } template<typename... Args> AC_COMMON_API inline void Fatal(std::string_view file, uint32 line, std::string_view function, std::string_view message, std::string_view fmt, Args&&... args) { - Fatal(file, line, function, message, StringFormatFmt(fmt, std::forward<Args>(args)...)); + Fatal(file, line, function, message, StringFormat(fmt, std::forward<Args>(args)...)); } template<typename... Args> AC_COMMON_API inline void Abort(std::string_view file, uint32 line, std::string_view function, std::string_view fmt, Args&&... args) { - Abort(file, line, function, StringFormatFmt(fmt, std::forward<Args>(args)...)); + Abort(file, line, function, StringFormat(fmt, std::forward<Args>(args)...)); } AC_COMMON_API void Warning(std::string_view file, uint32 line, std::string_view function, std::string_view message); diff --git a/src/common/Logging/AppenderConsole.cpp b/src/common/Logging/AppenderConsole.cpp index e7c63eadb8..db5a473361 100644 --- a/src/common/Logging/AppenderConsole.cpp +++ b/src/common/Logging/AppenderConsole.cpp @@ -52,7 +52,7 @@ void AppenderConsole::InitColors(std::string const& name, std::string_view str) std::vector<std::string_view> colorStrs = Acore::Tokenize(str, ' ', false); if (colorStrs.size() != NUM_ENABLED_LOG_LEVELS) { - throw InvalidAppenderArgsException(Acore::StringFormatFmt("Log::CreateAppenderFromConfig: Invalid color data '{}' for console appender {} (expected {} entries, got {})", + throw InvalidAppenderArgsException(Acore::StringFormat("Log::CreateAppenderFromConfig: Invalid color data '{}' for console appender {} (expected {} entries, got {})", str, name, NUM_ENABLED_LOG_LEVELS, colorStrs.size())); } @@ -64,7 +64,7 @@ void AppenderConsole::InitColors(std::string const& name, std::string_view str) } else { - throw InvalidAppenderArgsException(Acore::StringFormatFmt("Log::CreateAppenderFromConfig: Invalid color '{}' for log level {} on console appender {}", + throw InvalidAppenderArgsException(Acore::StringFormat("Log::CreateAppenderFromConfig: Invalid color '{}' for log level {} on console appender {}", colorStrs[i], EnumUtils::ToTitle(static_cast<LogLevel>(i)), name)); } } diff --git a/src/common/Logging/AppenderFile.cpp b/src/common/Logging/AppenderFile.cpp index 81b84cb985..9b4aa53ca1 100644 --- a/src/common/Logging/AppenderFile.cpp +++ b/src/common/Logging/AppenderFile.cpp @@ -31,7 +31,7 @@ AppenderFile::AppenderFile(uint8 id, std::string const& name, LogLevel level, Ap { if (args.size() < 4) { - throw InvalidAppenderArgsException(Acore::StringFormatFmt("Log::CreateAppenderFromConfig: Missing file name for appender {}", name)); + throw InvalidAppenderArgsException(Acore::StringFormat("Log::CreateAppenderFromConfig: Missing file name for appender {}", name)); } _fileName.assign(args[3]); @@ -63,7 +63,7 @@ AppenderFile::AppenderFile(uint8 id, std::string const& name, LogLevel level, Ap } else { - throw InvalidAppenderArgsException(Acore::StringFormatFmt("Log::CreateAppenderFromConfig: Invalid size '{}' for appender {}", args[5], name)); + throw InvalidAppenderArgsException(Acore::StringFormat("Log::CreateAppenderFromConfig: Invalid size '{}' for appender {}", args[5], name)); } } diff --git a/src/common/Logging/Log.h b/src/common/Logging/Log.h index f60bb03678..e4b6d61423 100644 --- a/src/common/Logging/Log.h +++ b/src/common/Logging/Log.h @@ -69,7 +69,7 @@ public: template<typename... Args> inline void outMessage(std::string const& filter, LogLevel const level, Acore::FormatString<Args...> fmt, Args&&... args) { - _outMessage(filter, level, Acore::StringFormatFmt(fmt, std::forward<Args>(args)...)); + _outMessage(filter, level, Acore::StringFormat(fmt, std::forward<Args>(args)...)); } template<typename... Args> @@ -80,7 +80,7 @@ public: return; } - _outCommand(Acore::StringFormatFmt(fmt, std::forward<Args>(args)...), std::to_string(account)); + _outCommand(Acore::StringFormat(fmt, std::forward<Args>(args)...), std::to_string(account)); } void SetRealmId(uint32 id); diff --git a/src/common/Utilities/StringFormat.h b/src/common/Utilities/StringFormat.h index fa5aeb4616..d4d93f2324 100644 --- a/src/common/Utilities/StringFormat.h +++ b/src/common/Utilities/StringFormat.h @@ -26,27 +26,12 @@ namespace Acore { - /// Default AC string format function. - template<typename Format, typename... Args> - inline std::string StringFormat(Format&& fmt, Args&& ... args) - { - try - { - return fmt::sprintf(std::forward<Format>(fmt), std::forward<Args>(args)...); - } - catch (const fmt::format_error& formatError) - { - std::string error = "An error occurred formatting string \"" + std::string(fmt) + "\" : " + std::string(formatError.what()); - return error; - } - } - template<typename... Args> using FormatString = fmt::format_string<Args...>; - // Default string format function. + /// Default AC string format function. template<typename... Args> - inline std::string StringFormatFmt(FormatString<Args...> fmt, Args&&... args) + inline std::string StringFormat(FormatString<Args...> fmt, Args&&... args) { try { diff --git a/src/common/Utilities/Timer.cpp b/src/common/Utilities/Timer.cpp index e7cb691a1c..54913163fe 100644 --- a/src/common/Utilities/Timer.cpp +++ b/src/common/Utilities/Timer.cpp @@ -86,27 +86,27 @@ AC_COMMON_API std::string Acore::Time::ToTimeString<Microseconds>(uint64 duratio { if (days) { - return Acore::StringFormatFmt("{}:{:02}:{:02}:{:02}:{:02}:{:02}", days, hours, minutes, secs, millisecs); + return Acore::StringFormat("{}:{:02}:{:02}:{:02}:{:02}:{:02}", days, hours, minutes, secs, millisecs); } else if (hours) { - return Acore::StringFormatFmt("{}:{:02}:{:02}:{:02}:{:02}", hours, minutes, secs, millisecs); + return Acore::StringFormat("{}:{:02}:{:02}:{:02}:{:02}", hours, minutes, secs, millisecs); } else if (minutes) { - return Acore::StringFormatFmt("{}:{:02}:{:02}:{:02}", minutes, secs, millisecs); + return Acore::StringFormat("{}:{:02}:{:02}:{:02}", minutes, secs, millisecs); } else if (secs) { - return Acore::StringFormatFmt("{}:{:02}:{:02}", secs, millisecs); + return Acore::StringFormat("{}:{:02}:{:02}", secs, millisecs); } else if (millisecs) { - return Acore::StringFormatFmt("{}:{:02}", millisecs); + return Acore::StringFormat("{}:{:02}", millisecs); } else // microsecs { - return Acore::StringFormatFmt("{}", microsecs); + return Acore::StringFormat("{}", microsecs); } } |