From 9834e80833783357743b2a5abe3071760638effb Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 23 Feb 2023 11:34:16 +0100 Subject: savegame ex.: give some TLC to main() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - include what you use - make 'args' const, so we don't detach in op[] - make boolean variables const - use QString::compare(lhs, rhs, Qt::CaseInsensitive) instead of lhs.toLower() == rhs - use new _L1 UDL - fix indentation of a return statement Pick-to: 6.5 Change-Id: If9da4fbe975d9a97939ea01558b2a8cef7ad3a24 Reviewed-by: MÃ¥rten Nordheim --- examples/corelib/serialization/savegame/main.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'examples') diff --git a/examples/corelib/serialization/savegame/main.cpp b/examples/corelib/serialization/savegame/main.cpp index 408b08dbc9..f97b0d595f 100644 --- a/examples/corelib/serialization/savegame/main.cpp +++ b/examples/corelib/serialization/savegame/main.cpp @@ -4,25 +4,28 @@ #include "game.h" #include +#include +#include #include +using namespace Qt::StringLiterals; // for _L1 + //! [0] int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); - QStringList args = QCoreApplication::arguments(); - bool newGame = true; - if (args.length() > 1) - newGame = (args[1].toLower() != QStringLiteral("load")); - bool json = true; - if (args.length() > 2) - json = (args[2].toLower() != QStringLiteral("binary")); + + const QStringList args = QCoreApplication::arguments(); + const bool newGame + = args.size() <= 1 || QString::compare(args[1], "load"_L1, Qt::CaseInsensitive) == 0; + const bool json + = args.size() <= 2 || QString::compare(args[2], "binary"_L1, Qt::CaseInsensitive) == 0; Game game; if (newGame) game.newGame(); else if (!game.loadGame(json ? Game::Json : Game::Binary)) - return 1; + return 1; // Game is played; changes are made... //! [0] //! [1] -- cgit v1.2.1