From dd89403df0a6fd99038cc1f7eee06ca7ce90c17c Mon Sep 17 00:00:00 2001 From: elsid Date: Thu, 12 Jan 2023 22:29:48 +0100 Subject: [PATCH] Move ensureUtf8Encoding to named namespace To follow https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#sf21-dont-use-an-unnamed-anonymous-namespace-in-a-header Add QtGlobal include to define QT_VERSION and QT_VERSION_CHECK macroses before they're used. --- apps/launcher/maindialog.cpp | 6 +++--- apps/wizard/mainwizard.cpp | 10 +++++----- components/config/gamesettings.cpp | 2 +- components/misc/utf8qtextstream.hpp | 10 ++++++---- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/apps/launcher/maindialog.cpp b/apps/launcher/maindialog.cpp index f1b800285e..4faef75cb0 100644 --- a/apps/launcher/maindialog.cpp +++ b/apps/launcher/maindialog.cpp @@ -308,7 +308,7 @@ bool Launcher::MainDialog::setupLauncherSettings() return false; } QTextStream stream(&file); - ensureUtf8Encoding(stream); + Misc::ensureUtf8Encoding(stream); mLauncherSettings.readFile(stream); } @@ -344,7 +344,7 @@ bool Launcher::MainDialog::setupGameSettings() return {}; } QTextStream stream(&file); - ensureUtf8Encoding(stream); + Misc::ensureUtf8Encoding(stream); (mGameSettings.*reader)(stream, ignoreContent); file.close(); @@ -544,7 +544,7 @@ bool Launcher::MainDialog::writeSettings() QTextStream stream(&file); stream.setDevice(&file); - ensureUtf8Encoding(stream); + Misc::ensureUtf8Encoding(stream); mLauncherSettings.writeFile(stream); file.close(); diff --git a/apps/wizard/mainwizard.cpp b/apps/wizard/mainwizard.cpp index 8d0c085b00..69bf7536b4 100644 --- a/apps/wizard/mainwizard.cpp +++ b/apps/wizard/mainwizard.cpp @@ -165,7 +165,7 @@ void Wizard::MainWizard::setupGameSettings() return; } QTextStream stream(&file); - ensureUtf8Encoding(stream); + Misc::ensureUtf8Encoding(stream); mGameSettings.readUserFile(stream); } @@ -197,7 +197,7 @@ void Wizard::MainWizard::setupGameSettings() return; } QTextStream stream(&file); - ensureUtf8Encoding(stream); + Misc::ensureUtf8Encoding(stream); mGameSettings.readFile(stream); } @@ -233,7 +233,7 @@ void Wizard::MainWizard::setupLauncherSettings() return; } QTextStream stream(&file); - ensureUtf8Encoding(stream); + Misc::ensureUtf8Encoding(stream); mLauncherSettings.readFile(stream); } @@ -460,7 +460,7 @@ void Wizard::MainWizard::writeSettings() } QTextStream stream(&file); - ensureUtf8Encoding(stream); + Misc::ensureUtf8Encoding(stream); mGameSettings.writeFile(stream); file.close(); @@ -486,7 +486,7 @@ void Wizard::MainWizard::writeSettings() } stream.setDevice(&file); - ensureUtf8Encoding(stream); + Misc::ensureUtf8Encoding(stream); mLauncherSettings.writeFile(stream); file.close(); diff --git a/components/config/gamesettings.cpp b/components/config/gamesettings.cpp index bc2286fbfd..67b4ed173f 100644 --- a/components/config/gamesettings.cpp +++ b/components/config/gamesettings.cpp @@ -230,7 +230,7 @@ bool Config::GameSettings::isOrderedLine(const QString& line) bool Config::GameSettings::writeFileWithComments(QFile& file) { QTextStream stream(&file); - ensureUtf8Encoding(stream); + Misc::ensureUtf8Encoding(stream); // slurp std::vector fileCopy; diff --git a/components/misc/utf8qtextstream.hpp b/components/misc/utf8qtextstream.hpp index 37ee2cfe89..a1e101864f 100644 --- a/components/misc/utf8qtextstream.hpp +++ b/components/misc/utf8qtextstream.hpp @@ -1,14 +1,16 @@ -#ifndef MISC_UTF8QTEXTSTREAM_HPP -#define MISC_UTF8QTEXTSTREAM_HPP +#ifndef OPENMW_COMPONENTS_MISC_UTF8QTEXTSTREAM_HPP +#define OPENMW_COMPONENTS_MISC_UTF8QTEXTSTREAM_HPP + +#include #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) #include #endif #include -namespace +namespace Misc { - void ensureUtf8Encoding(QTextStream& stream) + inline void ensureUtf8Encoding(QTextStream& stream) { #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) stream.setCodec(QTextCodec::codecForName("UTF-8"));