Commit c6f04ddf authored by hjk's avatar hjk Committed by hjk
Browse files

utils/environment: style

Change-Id: Ifbb9196d293205ab779294a22d0e5bd40faa887c
Reviewed-on: http://codereview.qt.nokia.com/84
Reviewed-by: hjk
parent d21645cc
......@@ -32,13 +32,13 @@
#include "environment.h"
#include <QtCore/QProcess>
#include <QtCore/QDir>
#include <QtCore/QProcess>
#include <QtCore/QString>
using namespace Utils;
namespace Utils {
QList<EnvironmentItem> EnvironmentItem::fromStringList(QStringList list)
QList<EnvironmentItem> EnvironmentItem::fromStringList(const QStringList &list)
{
QList<EnvironmentItem> result;
foreach (const QString &string, list) {
......@@ -55,7 +55,7 @@ QList<EnvironmentItem> EnvironmentItem::fromStringList(QStringList list)
return result;
}
QStringList EnvironmentItem::toStringList(QList<EnvironmentItem> list)
QStringList EnvironmentItem::toStringList(const QList<EnvironmentItem> &list)
{
QStringList result;
foreach (const EnvironmentItem &item, list) {
......@@ -67,11 +67,7 @@ QStringList EnvironmentItem::toStringList(QList<EnvironmentItem> list)
return result;
}
Environment::Environment()
{
}
Environment::Environment(QStringList env)
Environment::Environment(const QStringList &env)
{
foreach (const QString &s, env) {
int i = s.indexOf(QLatin1Char('='));
......@@ -218,6 +214,7 @@ QString Environment::searchInPath(const QString &executable,
QString Environment::searchInPath(const QStringList &executables,
const QStringList &additionalDirs) const
{
const QChar slash = QLatin1Char('/');
foreach (const QString &executable, executables) {
QString exec = QDir::cleanPath(expandVariables(executable));
......@@ -238,7 +235,6 @@ QString Environment::searchInPath(const QStringList &executables,
}
// Check in path:
const QChar slash = QLatin1Char('/');
if (exec.indexOf(slash) != -1)
continue;
foreach (const QString &p, path()) {
......@@ -461,7 +457,9 @@ QString Environment::expandVariables(const QString &input) const
QStringList Environment::expandVariables(const QStringList &variables) const
{
QStringList results;
foreach (const QString & i, variables)
foreach (const QString &i, variables)
results << expandVariables(i);
return results;
}
} // namespace Utils
......@@ -35,17 +35,17 @@
#include "utils_global.h"
#include <QtCore/QList>
#include <QtCore/QMap>
#include <QtCore/QString>
#include <QtCore/QStringList>
#include <QtCore/QMap>
#include <QtCore/QList>
namespace Utils {
class QTCREATOR_UTILS_EXPORT EnvironmentItem
{
public:
EnvironmentItem(QString n, QString v)
EnvironmentItem(const QString &n, const QString &v)
: name(n), value(v), unset(false)
{}
......@@ -55,26 +55,27 @@ public:
bool operator==(const EnvironmentItem &other) const
{
return (unset == other.unset) && (name == other.name) && (value == other.value);
return unset == other.unset && name == other.name && value == other.value;
}
static QList<EnvironmentItem> fromStringList(QStringList list);
static QStringList toStringList(QList<EnvironmentItem> list);
static QList<EnvironmentItem> fromStringList(const QStringList &list);
static QStringList toStringList(const QList<EnvironmentItem> &list);
};
class QTCREATOR_UTILS_EXPORT Environment {
class QTCREATOR_UTILS_EXPORT Environment
{
public:
typedef QMap<QString, QString>::const_iterator const_iterator;
Environment();
explicit Environment(QStringList env);
Environment() {}
explicit Environment(const QStringList &env);
static Environment systemEnvironment();
QStringList toStringList() const;
QString value(const QString &key) const;
void set(const QString &key, const QString &value);
void unset(const QString &key);
void modify(const QList<EnvironmentItem> & list);
void modify(const QList<EnvironmentItem> &list);
/// Return the Environment changes necessary to modify this into the other environment.
QList<EnvironmentItem> diff(const Environment &other) const;
bool hasKey(const QString &key);
......@@ -98,17 +99,18 @@ public:
Environment::const_iterator constFind(const QString &name) const;
QString searchInPath(const QString &executable,
const QStringList & additionalDirs = QStringList()) const;
const QStringList &additionalDirs = QStringList()) const;
QStringList path() const;
QString expandVariables(const QString &) const;
QStringList expandVariables(const QStringList &) const;
QString expandVariables(const QString &input) const;
QStringList expandVariables(const QStringList &input) const;
bool operator!=(const Environment &other) const;
bool operator==(const Environment &other) const;
private:
QString searchInPath(const QStringList &executables,
const QStringList & additionalDirs = QStringList()) const;
const QStringList &additionalDirs = QStringList()) const;
QMap<QString, QString> m_values;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment