mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-23 05:36:23 +00:00
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
This commit is contained in:
@@ -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(" ██╔══██╗╚══███╔╝██╔════╝██╔══██╗██╔═══██╗╚══██╔══╝██║ ██║");
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user