Skip to content

Commit

Permalink
REFAC(client): Don't use class as namespace
Browse files Browse the repository at this point in the history
The EnvUtils class only served as a namespace (containing static
functions). Thus, it makes more sense to convert EnvUtils into an actual
namespace.
  • Loading branch information
Krzmbrzl committed Nov 10, 2021
1 parent 0ee6508 commit 2dd0c8b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
8 changes: 6 additions & 2 deletions src/EnvUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()))
Expand All @@ -53,3 +55,5 @@ bool EnvUtils::setenv(QString name, QString value) {
return ::setenv(name.toLocal8Bit().constData(), value.toLocal8Bit().constData(), OVERWRITE) == 0;
#endif
}

}; // namespace EnvUtils
27 changes: 14 additions & 13 deletions src/EnvUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 2dd0c8b

Please sign in to comment.