REFAC(client): Don't use class as namespace

The EnvUtils class only served as a namespace (containing static
functions). Thus, it makes more sense to convert EnvUtils into an actual
namespace.
This commit is contained in:
Robert Adam 2021-11-10 09:15:48 +01:00
parent 0ee6508ba6
commit 2dd0c8bf5d
2 changed files with 20 additions and 15 deletions

View File

@ -7,7 +7,9 @@
#include <QByteArray>
QString EnvUtils::getenv(QString name) {
namespace EnvUtils {
QString getenv(QString name) {
#ifdef Q_OS_WIN
QByteArray buf;
size_t requiredSize = 0;
@ -43,7 +45,7 @@ QString EnvUtils::getenv(QString name) {
#endif
}
bool EnvUtils::setenv(QString name, QString value) {
bool setenv(QString name, QString value) {
#ifdef Q_OS_WIN
return _wputenv_s(reinterpret_cast< const wchar_t * >(name.utf16()),
reinterpret_cast< const wchar_t * >(value.utf16()))
@ -53,3 +55,5 @@ bool EnvUtils::setenv(QString name, QString value) {
return ::setenv(name.toLocal8Bit().constData(), value.toLocal8Bit().constData(), OVERWRITE) == 0;
#endif
}
}; // namespace EnvUtils

View File

@ -8,19 +8,20 @@
#include <QString>
class EnvUtils {
public:
// getenv is a wrapper around _wgetenv_s (on Windows)
// and getenv (on everything else).
//
// On Windows, it expects a Unicode environment -- so variables
// are expected to be UTF16.
//
// On everything else, it expects environment variables to use the
// locale-defined encoding. (From a Qt-perspective, we use toLocal8Bit/fromLocal8Bit.)
static QString getenv(QString name);
namespace EnvUtils {
static bool setenv(QString name, QString value);
};
// getenv is a wrapper around _wgetenv_s (on Windows)
// and getenv (on everything else).
//
// On Windows, it expects a Unicode environment -- so variables
// are expected to be UTF16.
//
// On everything else, it expects environment variables to use the
// locale-defined encoding. (From a Qt-perspective, we use toLocal8Bit/fromLocal8Bit.)
QString getenv(QString name);
bool setenv(QString name, QString value);
}; // namespace EnvUtils
#endif