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:
Kitzunu
2024-09-03 12:59:37 +02:00
committed by GitHub
parent f6fd978a7a
commit de2bcbdabf
36 changed files with 100 additions and 115 deletions

View File

@@ -35,7 +35,7 @@ protected:
// For Logging purpose
std::string ToString() const override
{
return Acore::StringFormatFmt("Damage done: {}, Healing done: {}, Killing blows: {}", DamageDone, HealingDone, KillingBlows);
return Acore::StringFormat("Damage done: {}, Healing done: {}, Killing blows: {}", DamageDone, HealingDone, KillingBlows);
}
uint8 PvPTeamId;

View File

@@ -1107,7 +1107,7 @@ void BattlegroundQueue::SendJoinMessageArenaQueue(Player* leader, GroupQueueInfo
BattlegroundBracketId bracketId = bracketEntry->GetBracketId();
auto bgName = bg->GetName();
auto arenatype = Acore::StringFormat("%uv%u", ginfo->ArenaType, ginfo->ArenaType);
auto arenatype = Acore::StringFormat("{}v{}", ginfo->ArenaType, ginfo->ArenaType);
uint32 playersNeed = ArenaTeam::GetReqPlayersForType(ginfo->ArenaType);
uint32 q_min_level = std::min(bracketEntry->minLevel, (uint32)80);
uint32 q_max_level = std::min(bracketEntry->maxLevel, (uint32)80);

View File

@@ -56,13 +56,13 @@ public:
void SendNotification(uint32 strId, Args&&... args)
{
if (HasSession())
SendNotification(Acore::StringFormatFmt(GetAcoreString(strId), std::forward<Args>(args)...));
SendNotification(Acore::StringFormat(GetAcoreString(strId), std::forward<Args>(args)...));
}
template<typename... Args>
void SendNotification(char const* fmt, Args&&... args)
{
if (HasSession())
SendNotification(Acore::StringFormatFmt(fmt, std::forward<Args>(args)...));
SendNotification(Acore::StringFormat(fmt, std::forward<Args>(args)...));
}
void SendGMText(std::string_view str);
@@ -73,7 +73,7 @@ public:
DoForAllValidSessions([&](Player* player)
{
m_session = player->GetSession();
SendGMText(Acore::StringFormatFmt(GetAcoreString(strId), std::forward<Args>(args)...));
SendGMText(Acore::StringFormat(GetAcoreString(strId), std::forward<Args>(args)...));
});
}
template<typename... Args>
@@ -83,7 +83,7 @@ public:
DoForAllValidSessions([&](Player* player)
{
m_session = player->GetSession();
SendGMText(Acore::StringFormatFmt(fmt, std::forward<Args>(args)...));
SendGMText(Acore::StringFormat(fmt, std::forward<Args>(args)...));
});
}
@@ -95,7 +95,7 @@ public:
DoForAllValidSessions([&](Player* player)
{
m_session = player->GetSession();
SendWorldText(Acore::StringFormatFmt(GetAcoreString(strId), std::forward<Args>(args)...));
SendWorldText(Acore::StringFormat(GetAcoreString(strId), std::forward<Args>(args)...));
});
}
template<typename... Args>
@@ -105,7 +105,7 @@ public:
DoForAllValidSessions([&](Player* player)
{
m_session = player->GetSession();
SendWorldText(Acore::StringFormatFmt(fmt, std::forward<Args>(args)...));
SendWorldText(Acore::StringFormat(fmt, std::forward<Args>(args)...));
});
}
@@ -117,7 +117,7 @@ public:
DoForAllValidSessions([&](Player* player)
{
m_session = player->GetSession();
SendWorldTextOptional(Acore::StringFormatFmt(GetAcoreString(strId), std::forward<Args>(args)...), flag);
SendWorldTextOptional(Acore::StringFormat(GetAcoreString(strId), std::forward<Args>(args)...), flag);
});
}
template<typename... Args>
@@ -127,7 +127,7 @@ public:
DoForAllValidSessions([&](Player* player)
{
m_session = player->GetSession();
SendWorldTextOptional(Acore::StringFormatFmt(fmt, std::forward<Args>(args)...), flag);
SendWorldTextOptional(Acore::StringFormat(fmt, std::forward<Args>(args)...), flag);
});
}
@@ -142,7 +142,7 @@ public:
void PSendSysMessage(char const* fmt, Args&&... args)
{
if (HasSession())
SendSysMessage(Acore::StringFormatFmt(fmt, std::forward<Args>(args)...));
SendSysMessage(Acore::StringFormat(fmt, std::forward<Args>(args)...));
}
template<typename... Args>
@@ -155,7 +155,7 @@ public:
template<typename... Args>
std::string PGetParseString(uint32 entry, Args&&... args) const
{
return Acore::StringFormatFmt(GetAcoreString(entry), std::forward<Args>(args)...);
return Acore::StringFormat(GetAcoreString(entry), std::forward<Args>(args)...);
}
std::string const* GetModuleString(std::string module, uint32 id) const;
@@ -170,7 +170,7 @@ public:
template<typename... Args>
std::string PGetParseModuleString(std::string module, uint32 id, Args&&... args) const
{
return Acore::StringFormatFmt(GetModuleString(module, id)->c_str(), std::forward<Args>(args)...);
return Acore::StringFormat(GetModuleString(module, id)->c_str(), std::forward<Args>(args)...);
}
void SendErrorMessage(uint32 entry);

View File

@@ -175,7 +175,7 @@ static void LogCommandUsage(WorldSession const& session, std::string_view cmdStr
zoneName = zone->area_name[locale];
}
std::string logMessage = Acore::StringFormatFmt("Command: {} [Player: {} ({}) (Account: {}) X: {} Y: {} Z: {} Map: {} ({}) Area: {} ({}) Zone: {} ({}) Selected: {} ({})]",
std::string logMessage = Acore::StringFormat("Command: {} [Player: {} ({}) (Account: {}) X: {} Y: {} Z: {} Map: {} ({}) Area: {} ({}) Zone: {} ({}) Selected: {} ({})]",
cmdStr, player->GetName(), player->GetGUID().ToString(),
session.GetAccountId(),
player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(), player->GetMapId(),
@@ -443,11 +443,11 @@ namespace Acore::Impl::ChatCommands
{
if (prefix.empty())
{
return Acore::StringFormatFmt("{}{}{}", match, COMMAND_DELIMITER, suffix);
return Acore::StringFormat("{}{}{}", match, COMMAND_DELIMITER, suffix);
}
else
{
return Acore::StringFormatFmt("{}{}{}{}{}", prefix, COMMAND_DELIMITER, match, COMMAND_DELIMITER, suffix);
return Acore::StringFormat("{}{}{}{}{}", prefix, COMMAND_DELIMITER, match, COMMAND_DELIMITER, suffix);
}
});
@@ -465,7 +465,7 @@ namespace Acore::Impl::ChatCommands
path.assign(it1->first);
else
{
path = Acore::StringFormatFmt("{}{}{}", path, COMMAND_DELIMITER, it1->first);
path = Acore::StringFormat("{}{}{}", path, COMMAND_DELIMITER, it1->first);
}
cmd = &it1->second;
map = &cmd->_subCommands;
@@ -477,7 +477,7 @@ namespace Acore::Impl::ChatCommands
{ /* there is some trailing text, leave it as is */
if (cmd)
{ /* if we matched a command at some point, auto-complete it */
return { Acore::StringFormatFmt("{}{}{}", path, COMMAND_DELIMITER, oldTail) };
return { Acore::StringFormat("{}{}{}", path, COMMAND_DELIMITER, oldTail) };
}
else
return {};
@@ -490,7 +490,7 @@ namespace Acore::Impl::ChatCommands
return std::string(match);
else
{
return Acore::StringFormatFmt("{}{}{}", prefix, COMMAND_DELIMITER, match);
return Acore::StringFormat("{}{}{}", prefix, COMMAND_DELIMITER, match);
}
});

View File

@@ -91,7 +91,7 @@ namespace Acore::Impl::ChatCommands
return result2;
if (result1.HasErrorMessage() && result2.HasErrorMessage())
{
return Acore::StringFormatFmt("{} \"{}\"\n{} \"{}\"",
return Acore::StringFormat("{} \"{}\"\n{} \"{}\"",
GetAcoreString(handler, LANG_CMDPARSER_EITHER), result2.GetErrorMessage(),
GetAcoreString(handler, LANG_CMDPARSER_OR), result1.GetErrorMessage());
}

View File

@@ -273,9 +273,9 @@ namespace Acore::Impl::ChatCommands
if (!nestedResult.HasErrorMessage())
return thisResult;
if (StringStartsWith(nestedResult.GetErrorMessage(), "\""))
return Acore::StringFormat("\"%s\"\n%s %s", thisResult.GetErrorMessage().c_str(), GetAcoreString(handler, LANG_CMDPARSER_OR), nestedResult.GetErrorMessage().c_str());
return Acore::StringFormat("\"{}\"\n{} {}", thisResult.GetErrorMessage(), GetAcoreString(handler, LANG_CMDPARSER_OR), nestedResult.GetErrorMessage());
else
return Acore::StringFormat("\"%s\"\n%s \"%s\"", thisResult.GetErrorMessage().c_str(), GetAcoreString(handler, LANG_CMDPARSER_OR), nestedResult.GetErrorMessage().c_str());
return Acore::StringFormat("\"{}\"\n{} \"{}\"", thisResult.GetErrorMessage(), GetAcoreString(handler, LANG_CMDPARSER_OR), nestedResult.GetErrorMessage());
}
}
else
@@ -286,7 +286,7 @@ namespace Acore::Impl::ChatCommands
{
ChatCommandResult result = TryAtIndex<0>(val, handler, args);
if (result.HasErrorMessage() && (result.GetErrorMessage().find('\n') != std::string::npos))
return Acore::StringFormat("%s %s", GetAcoreString(handler, LANG_CMDPARSER_EITHER), result.GetErrorMessage().c_str());
return Acore::StringFormat("{} {}", GetAcoreString(handler, LANG_CMDPARSER_EITHER), result.GetErrorMessage());
return result;
}
};

View File

@@ -125,7 +125,7 @@ namespace Acore::Impl::ChatCommands
template <typename... Ts>
std::string FormatAcoreString(ChatHandler const* handler, AcoreStrings which, Ts&&... args)
{
return Acore::StringFormatFmt(GetAcoreString(handler, which), std::forward<Ts>(args)...);
return Acore::StringFormat(GetAcoreString(handler, which), std::forward<Ts>(args)...);
}
}

View File

@@ -304,7 +304,7 @@ void PlayerDump::InitializeTables()
// item0 - item18
for (uint32 j = 0; j < EQUIPMENT_SLOT_END; ++j)
{
std::string itColumn = Acore::StringFormat("item%u", j);
std::string itColumn = Acore::StringFormat("item{}", j);
MarkDependentColumn(t, itColumn, GUID_TYPE_ITEM);
}
break;
@@ -923,7 +923,7 @@ DumpReturn PlayerDumpReader::LoadDump(std::istream& input, uint32 account, std::
if (name.empty())
{
// generate a temporary name
std::string guidPart = Acore::StringFormat("%X", guid);
std::string guidPart = Acore::StringFormat("{:X}", guid);
std::size_t maxCharsFromOriginalName = MAX_PLAYER_NAME - guidPart.length();
name = GetColumn(ts, line, "name").substr(0, maxCharsFromOriginalName) + guidPart;

View File

@@ -246,14 +246,14 @@ void Warden::ApplyPenalty(uint16 checkId, std::string const& reason)
if (Player const* plr = _session->GetPlayer())
{
std::string const reportFormat = "Player {} (guid {}, account id: {}) failed warden {} check ({}). Action: {}";
reportMsg = Acore::StringFormatFmt(reportFormat, plr->GetName(), plr->GetGUID().GetCounter(), _session->GetAccountId(),
reportMsg = Acore::StringFormat(reportFormat, plr->GetName(), plr->GetGUID().GetCounter(), _session->GetAccountId(),
checkId, ((checkData && !checkData->Comment.empty()) ? checkData->Comment : "<warden comment is not set>"),
GetWardenActionStr(action));
}
else
{
std::string const reportFormat = "Account id: {} failed warden {} check. Action: {}";
reportMsg = Acore::StringFormatFmt(reportFormat, _session->GetAccountId(), checkId, GetWardenActionStr(action));
reportMsg = Acore::StringFormat(reportFormat, _session->GetAccountId(), checkId, GetWardenActionStr(action));
}
}
else
@@ -261,12 +261,12 @@ void Warden::ApplyPenalty(uint16 checkId, std::string const& reason)
if (Player const* plr = _session->GetPlayer())
{
std::string const reportFormat = "Player {} (guid {}, account id: {}) triggered warden penalty by reason: {}. Action: {}";
reportMsg = Acore::StringFormatFmt(reportFormat, plr->GetName(), plr->GetGUID().GetCounter(), _session->GetAccountId(), causeMsg, GetWardenActionStr(action));
reportMsg = Acore::StringFormat(reportFormat, plr->GetName(), plr->GetGUID().GetCounter(), _session->GetAccountId(), causeMsg, GetWardenActionStr(action));
}
else
{
std::string const reportFormat = "Account id: {} failed warden {} check. Action: {}";
reportMsg = Acore::StringFormatFmt(reportFormat, _session->GetAccountId(), causeMsg, GetWardenActionStr(action));
reportMsg = Acore::StringFormat(reportFormat, _session->GetAccountId(), causeMsg, GetWardenActionStr(action));
}
}

View File

@@ -137,7 +137,7 @@ void WardenCheckMgr::LoadWardenChecks()
continue;
}
std::string str2 = Acore::StringFormat("%04u", id);
std::string str2 = Acore::StringFormat("{:04}", id);
ASSERT(str2.size() == 4);
std::copy(str2.begin(), str2.end(), wardenCheck.IdStr.begin());

View File

@@ -74,7 +74,7 @@ bool WardenPayloadMgr::RegisterPayload(std::string const& payload, uint16 payloa
wCheck.Str = payload;
wCheck.CheckId = payloadId;
std::string idStr = Acore::StringFormat("%04u", payloadId);
std::string idStr = Acore::StringFormat("{:04}", payloadId);
ASSERT(idStr.size() == 4);
std::copy(idStr.begin(), idStr.end(), wCheck.IdStr.begin());