aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Chat/ChatCommands
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2023-08-15 20:10:04 +0200
committerShauren <shauren.trinity@gmail.com>2023-08-15 20:10:04 +0200
commitaaa6e73c8ca6d60e943cb964605536eb78219db2 (patch)
treef5a0187925e646ef071d647efa7a5dac20501813 /src/server/game/Chat/ChatCommands
parent825c697a764017349ca94ecfca8f30a8365666c0 (diff)
Core/Logging: Switch from fmt::sprintf to fmt::format (c++20 standard compatible api)
(cherry picked from commit d791afae1dfcfaf592326f787755ca32d629e4d3)
Diffstat (limited to 'src/server/game/Chat/ChatCommands')
-rw-r--r--src/server/game/Chat/ChatCommands/ChatCommand.cpp30
-rw-r--r--src/server/game/Chat/ChatCommands/ChatCommand.h6
-rw-r--r--src/server/game/Chat/ChatCommands/ChatCommandArgs.h6
-rw-r--r--src/server/game/Chat/ChatCommands/ChatCommandHelpers.h3
-rw-r--r--src/server/game/Chat/ChatCommands/ChatCommandTags.h20
5 files changed, 34 insertions, 31 deletions
diff --git a/src/server/game/Chat/ChatCommands/ChatCommand.cpp b/src/server/game/Chat/ChatCommands/ChatCommand.cpp
index cecd6ff333d..dc376545bc9 100644
--- a/src/server/game/Chat/ChatCommands/ChatCommand.cpp
+++ b/src/server/game/Chat/ChatCommands/ChatCommand.cpp
@@ -97,7 +97,7 @@ static ChatSubCommandMap COMMAND_MAP;
}
else
{
- TC_LOG_ERROR("sql.sql", "Table `command` contains data for non-existant command '" STRING_VIEW_FMT "'. Skipped.", STRING_VIEW_FMT_ARG(name));
+ TC_LOG_ERROR("sql.sql", "Table `command` contains data for non-existant command '{}'. Skipped.", name);
cmd = nullptr;
break;
}
@@ -107,12 +107,12 @@ static ChatSubCommandMap COMMAND_MAP;
continue;
if (std::holds_alternative<std::string>(cmd->_help))
- TC_LOG_ERROR("sql.sql", "Table `command` contains duplicate data for command '" STRING_VIEW_FMT "'. Skipped.", STRING_VIEW_FMT_ARG(name));
+ TC_LOG_ERROR("sql.sql", "Table `command` contains duplicate data for command '{}'. Skipped.", name);
if (std::holds_alternative<std::monostate>(cmd->_help))
cmd->_help.emplace<std::string>(help);
else
- TC_LOG_ERROR("sql.sql", "Table `command` contains legacy help text for command '" STRING_VIEW_FMT "', which uses `trinity_string`. Skipped.", STRING_VIEW_FMT_ARG(name));
+ TC_LOG_ERROR("sql.sql", "Table `command` contains legacy help text for command '{}', which uses `trinity_string`. Skipped.", name);
} while (result->NextRow());
}
@@ -123,7 +123,7 @@ static ChatSubCommandMap COMMAND_MAP;
void Trinity::Impl::ChatCommands::ChatCommandNode::ResolveNames(std::string name)
{
if (_invoker && std::holds_alternative<std::monostate>(_help))
- TC_LOG_WARN("sql.sql", "Table `command` is missing help text for command '" STRING_VIEW_FMT "'.", STRING_VIEW_FMT_ARG(name));
+ TC_LOG_WARN("sql.sql", "Table `command` is missing help text for command '{}'.", name);
_name = name;
for (auto& [subToken, cmd] : _subCommands)
@@ -156,8 +156,8 @@ static void LogCommandUsage(WorldSession const& session, uint32 permission, std:
zoneName = zone->AreaName[locale];
}
- sLog->outCommand(session.GetAccountId(), "Command: " STRING_VIEW_FMT " [Player: %s (%s) (Account: %u) X: %f Y: %f Z: %f Map: %u (%s) Area: %u (%s) Zone: %s Selected: %s (%s)]",
- STRING_VIEW_FMT_ARG(cmdStr), player->GetName().c_str(), player->GetGUID().ToString().c_str(),
+ sLog->OutCommand(session.GetAccountId(), "Command: {} [Player: %s (%s) (Account: %u) X: %f Y: %f Z: %f Map: %u (%s) Area: %u (%s) Zone: %s Selected: %s (%s)]",
+ cmdStr, player->GetName().c_str(), player->GetGUID().ToString().c_str(),
session.GetAccountId(), player->GetPositionX(), player->GetPositionY(),
player->GetPositionZ(), player->GetMapId(),
player->FindMap() ? player->FindMap()->GetMapName() : "Unknown",
@@ -401,13 +401,11 @@ namespace Trinity::Impl::ChatCommands
{
if (prefix.empty())
{
- return Trinity::StringFormat(STRING_VIEW_FMT "%c" STRING_VIEW_FMT,
- STRING_VIEW_FMT_ARG(match), COMMAND_DELIMITER, STRING_VIEW_FMT_ARG(suffix));
+ return Trinity::StringFormat("{}{}{}", match, COMMAND_DELIMITER, suffix);
}
else
{
- return Trinity::StringFormat(STRING_VIEW_FMT "%c" STRING_VIEW_FMT "%c" STRING_VIEW_FMT,
- STRING_VIEW_FMT_ARG(prefix), COMMAND_DELIMITER, STRING_VIEW_FMT_ARG(match), COMMAND_DELIMITER, STRING_VIEW_FMT_ARG(suffix));
+ return Trinity::StringFormat("{}{}{}{}{}", prefix, COMMAND_DELIMITER, match, COMMAND_DELIMITER, suffix);
}
});
@@ -424,10 +422,8 @@ namespace Trinity::Impl::ChatCommands
if (path.empty())
path.assign(it1->first);
else
- {
- path = Trinity::StringFormat(STRING_VIEW_FMT "%c" STRING_VIEW_FMT,
- STRING_VIEW_FMT_ARG(path), COMMAND_DELIMITER, STRING_VIEW_FMT_ARG(it1->first));
- }
+ path = Trinity::StringFormat("{}{}{}", path, COMMAND_DELIMITER, it1->first);
+
cmd = &it1->second;
map = &cmd->_subCommands;
@@ -439,8 +435,7 @@ namespace Trinity::Impl::ChatCommands
if (cmd)
{ /* if we matched a command at some point, auto-complete it */
return {
- Trinity::StringFormat(STRING_VIEW_FMT "%c" STRING_VIEW_FMT,
- STRING_VIEW_FMT_ARG(path), COMMAND_DELIMITER, STRING_VIEW_FMT_ARG(oldTail))
+ Trinity::StringFormat("{}{}{}", path, COMMAND_DELIMITER, oldTail)
};
}
else
@@ -454,8 +449,7 @@ namespace Trinity::Impl::ChatCommands
return std::string(match);
else
{
- return Trinity::StringFormat(STRING_VIEW_FMT "%c" STRING_VIEW_FMT,
- STRING_VIEW_FMT_ARG(prefix), COMMAND_DELIMITER, STRING_VIEW_FMT_ARG(match));
+ return Trinity::StringFormat("{}{}{}", prefix, COMMAND_DELIMITER, match);
}
});
diff --git a/src/server/game/Chat/ChatCommands/ChatCommand.h b/src/server/game/Chat/ChatCommands/ChatCommand.h
index 329eecfc567..ad4288f7a2e 100644
--- a/src/server/game/Chat/ChatCommands/ChatCommand.h
+++ b/src/server/game/Chat/ChatCommands/ChatCommand.h
@@ -92,9 +92,9 @@ namespace Trinity::Impl::ChatCommands
return result2;
if (result1.HasErrorMessage() && result2.HasErrorMessage())
{
- return Trinity::StringFormat("%s \"%s\"\n%s \"%s\"",
- GetTrinityString(handler, LANG_CMDPARSER_EITHER), result2.GetErrorMessage().c_str(),
- GetTrinityString(handler, LANG_CMDPARSER_OR), result1.GetErrorMessage().c_str());
+ return Trinity::StringFormat("{} \"{}\"\n{} \"{}\"",
+ GetTrinityString(handler, LANG_CMDPARSER_EITHER), result2.GetErrorMessage(),
+ GetTrinityString(handler, LANG_CMDPARSER_OR), result1.GetErrorMessage());
}
else if (result1.HasErrorMessage())
return result1;
diff --git a/src/server/game/Chat/ChatCommands/ChatCommandArgs.h b/src/server/game/Chat/ChatCommands/ChatCommandArgs.h
index 71d115923ab..770f67b3485 100644
--- a/src/server/game/Chat/ChatCommands/ChatCommandArgs.h
+++ b/src/server/game/Chat/ChatCommands/ChatCommandArgs.h
@@ -273,9 +273,9 @@ namespace Trinity::Impl::ChatCommands
if (!nestedResult.HasErrorMessage())
return thisResult;
if (StringStartsWith(nestedResult.GetErrorMessage(), "\""))
- return Trinity::StringFormat("\"%s\"\n%s %s", thisResult.GetErrorMessage().c_str(), GetTrinityString(handler, LANG_CMDPARSER_OR), nestedResult.GetErrorMessage().c_str());
+ return Trinity::StringFormat("\"{}\"\n{} {}", thisResult.GetErrorMessage(), GetTrinityString(handler, LANG_CMDPARSER_OR), nestedResult.GetErrorMessage());
else
- return Trinity::StringFormat("\"%s\"\n%s \"%s\"", thisResult.GetErrorMessage().c_str(), GetTrinityString(handler, LANG_CMDPARSER_OR), nestedResult.GetErrorMessage().c_str());
+ return Trinity::StringFormat("\"{}\"\n{} \"{}\"", thisResult.GetErrorMessage(), GetTrinityString(handler, LANG_CMDPARSER_OR), nestedResult.GetErrorMessage());
}
}
else
@@ -286,7 +286,7 @@ namespace Trinity::Impl::ChatCommands
{
ChatCommandResult result = TryAtIndex<0>(val, handler, args);
if (result.HasErrorMessage() && (result.GetErrorMessage().find('\n') != std::string::npos))
- return Trinity::StringFormat("%s %s", GetTrinityString(handler, LANG_CMDPARSER_EITHER), result.GetErrorMessage().c_str());
+ return Trinity::StringFormat("{} {}", GetTrinityString(handler, LANG_CMDPARSER_EITHER), result.GetErrorMessage());
return result;
}
};
diff --git a/src/server/game/Chat/ChatCommands/ChatCommandHelpers.h b/src/server/game/Chat/ChatCommands/ChatCommandHelpers.h
index 0883c8b6ffc..f253ce4657b 100644
--- a/src/server/game/Chat/ChatCommands/ChatCommandHelpers.h
+++ b/src/server/game/Chat/ChatCommands/ChatCommandHelpers.h
@@ -21,6 +21,7 @@
#include "Define.h"
#include "Language.h"
#include "StringFormat.h"
+#include <fmt/printf.h>
#include <optional>
#include <string>
#include <string_view>
@@ -125,7 +126,7 @@ namespace Trinity::Impl::ChatCommands
template <typename... Ts>
std::string FormatTrinityString(ChatHandler const* handler, TrinityStrings which, Ts&&... args)
{
- return Trinity::StringFormat(GetTrinityString(handler, which), std::forward<Ts>(args)...);
+ return fmt::sprintf(GetTrinityString(handler, which), std::forward<Ts>(args)...);
}
}
diff --git a/src/server/game/Chat/ChatCommands/ChatCommandTags.h b/src/server/game/Chat/ChatCommands/ChatCommandTags.h
index b90c614e85d..8d311c6924c 100644
--- a/src/server/game/Chat/ChatCommands/ChatCommandTags.h
+++ b/src/server/game/Chat/ChatCommands/ChatCommandTags.h
@@ -25,6 +25,7 @@
#include "Util.h"
#include <boost/preprocessor/repetition/repeat.hpp>
#include <boost/preprocessor/punctuation/comma_if.hpp>
+#include <fmt/ostream.h>
#include <cmath>
#include <cstring>
#include <iostream>
@@ -281,12 +282,6 @@ namespace Trinity::ChatCommands
return operator*();
}
- template<bool C = have_operators>
- operator std::enable_if_t<C && !std::is_same_v<first_type, size_t> && std::is_convertible_v<first_type, size_t>, size_t>() const
- {
- return operator*();
- }
-
template <bool C = have_operators>
std::enable_if_t<C, bool> operator!() const { return !**this; }
@@ -318,4 +313,17 @@ namespace Trinity::ChatCommands
};
}
+template <typename T1, typename... Ts>
+struct fmt::formatter<Trinity::ChatCommands::Variant<T1, Ts...>> : ostream_formatter { };
+
+template <typename T1, typename... Ts>
+struct fmt::printf_formatter<Trinity::ChatCommands::Variant<T1, Ts...>> : formatter<T1>
+{
+ template <typename T, typename OutputIt>
+ auto format(T const& value, basic_format_context<OutputIt, char>& ctx) const -> OutputIt
+ {
+ return formatter<T1>::format(*value, ctx);
+ }
+};
+
#endif