From c9522fb740200ccef6230cec452c48efb31e5394 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Thu, 11 May 2023 22:05:17 +0200 Subject: Removed all Printf-family functions from StringUtils. Replaced them with fmt::format calls, including changes to the format strings. Also changed the format strings to use FMT_STRING, so that the format is checked compile-time against the arguments. Also fixed code-style violations already present in the code. --- src/Server.cpp | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'src/Server.cpp') diff --git a/src/Server.cpp b/src/Server.cpp index 36964d41c..a3953db5a 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -489,7 +489,7 @@ void cServer::ExecuteConsoleCommand(const AString & a_Cmd, cCommandOutputCallbac if (split.size() > 1) { cPluginManager::Get()->ReloadPlugin(split[1]); - a_Output.Out("Plugin reload scheduled"); + a_Output.OutLn("Plugin reload scheduled"); } else { @@ -501,14 +501,14 @@ void cServer::ExecuteConsoleCommand(const AString & a_Cmd, cCommandOutputCallbac else if (split[0] == "reloadplugins") { cPluginManager::Get()->ReloadPlugins(); - a_Output.Out("Plugins reloaded"); + a_Output.OutLn("Plugins reloaded"); a_Output.Finished(); return; } else if (split[0] == "reloadweb") { cRoot::Get()->GetWebAdmin()->Reload(); - a_Output.Out("WebAdmin configuration reloaded"); + a_Output.OutLn("WebAdmin configuration reloaded"); a_Output.Finished(); return; } @@ -517,11 +517,11 @@ void cServer::ExecuteConsoleCommand(const AString & a_Cmd, cCommandOutputCallbac if (split.size() > 1) { cPluginManager::Get()->RefreshPluginList(); // Refresh the plugin list, so that if the plugin was added just now, it is loadable - a_Output.Out(cPluginManager::Get()->LoadPlugin(split[1]) ? "Plugin loaded" : "Error occurred loading plugin"); + a_Output.OutLn(cPluginManager::Get()->LoadPlugin(split[1]) ? "Plugin loaded" : "Error occurred loading plugin"); } else { - a_Output.Out("Usage: load "); + a_Output.OutLn("Usage: load "); } a_Output.Finished(); return; @@ -531,11 +531,11 @@ void cServer::ExecuteConsoleCommand(const AString & a_Cmd, cCommandOutputCallbac if (split.size() > 1) { cPluginManager::Get()->UnloadPlugin(split[1]); - a_Output.Out("Plugin unload scheduled"); + a_Output.OutLn("Plugin unload scheduled"); } else { - a_Output.Out("Usage: unload "); + a_Output.OutLn("Usage: unload "); } a_Output.Finished(); return; @@ -556,7 +556,7 @@ void cServer::ExecuteConsoleCommand(const AString & a_Cmd, cCommandOutputCallbac return false; } ); - a_Output.Out("Destroyed all entities"); + a_Output.OutLn("Destroyed all entities"); a_Output.Finished(); return; } @@ -571,7 +571,7 @@ void cServer::ExecuteConsoleCommand(const AString & a_Cmd, cCommandOutputCallbac else if (split[0].compare("luastats") == 0) { - a_Output.Out(cLuaStateTracker::GetStats()); + a_Output.OutLn(cLuaStateTracker::GetStats()); a_Output.Finished(); return; } @@ -581,7 +581,7 @@ void cServer::ExecuteConsoleCommand(const AString & a_Cmd, cCommandOutputCallbac return; } - a_Output.Out("Unknown command, type 'help' for all commands."); + a_Output.OutLn("Unknown command, type 'help' for all commands."); a_Output.Finished(); } @@ -624,7 +624,8 @@ void cServer::PrintHelp(const AStringVector & a_Split, cCommandOutputCallback & for (AStringPairs::const_iterator itr = Callback.m_Commands.begin(), end = Callback.m_Commands.end(); itr != end; ++itr) { const AStringPair & cmd = *itr; - a_Output.Out(Printf("%-*s - %s\n", static_cast(Callback.m_MaxLen), cmd.first.c_str(), cmd.second.c_str())); + // Output the commands and their help strings, with all the commands aligned to the same width + a_Output.OutLn(fmt::format(FMT_STRING("{1:{0}s} - {2}"), Callback.m_MaxLen, cmd.first, cmd.second)); } // for itr - Callback.m_Commands[] } -- cgit v1.2.3