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.
7220-lua-add-a-general-purpose-lexical-parser
elsid 2 years ago
parent ee980721b8
commit dd89403df0
No known key found for this signature in database
GPG Key ID: 4DE04C198CBA7625

@ -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();

@ -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();

@ -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<QString> fileCopy;

@ -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 <QtGlobal>
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#include <QTextCodec>
#endif
#include <QTextStream>
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"));

Loading…
Cancel
Save