forked from qt-creator/qt-creator
Utils::Environment: Remove another set of duplicate functions
More clean-up after 4bae5de36b
.
Change-Id: Ia60cb868c464627b42a94d502d301b175449aa17
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -41,30 +41,6 @@ Q_GLOBAL_STATIC(QVector<Utils::EnvironmentProvider>, environmentProviders)
|
||||
|
||||
namespace Utils {
|
||||
|
||||
static NameValueMap::iterator findKey(NameValueMap &input, Utils::OsType osType, const QString &key)
|
||||
{
|
||||
const Qt::CaseSensitivity casing = (osType == Utils::OsTypeWindows) ? Qt::CaseInsensitive
|
||||
: Qt::CaseSensitive;
|
||||
for (auto it = input.begin(); it != input.end(); ++it) {
|
||||
if (key.compare(it.key(), casing) == 0)
|
||||
return it;
|
||||
}
|
||||
return input.end();
|
||||
}
|
||||
|
||||
static NameValueMap::const_iterator findKey(const NameValueMap &input,
|
||||
Utils::OsType osType,
|
||||
const QString &key)
|
||||
{
|
||||
const Qt::CaseSensitivity casing = (osType == Utils::OsTypeWindows) ? Qt::CaseInsensitive
|
||||
: Qt::CaseSensitive;
|
||||
for (auto it = input.constBegin(); it != input.constEnd(); ++it) {
|
||||
if (key.compare(it.key(), casing) == 0)
|
||||
return it;
|
||||
}
|
||||
return input.constEnd();
|
||||
}
|
||||
|
||||
QProcessEnvironment Environment::toProcessEnvironment() const
|
||||
{
|
||||
QProcessEnvironment result;
|
||||
@@ -90,7 +66,7 @@ void Environment::prependOrSetPath(const QString &value)
|
||||
void Environment::appendOrSet(const QString &key, const QString &value, const QString &sep)
|
||||
{
|
||||
QTC_ASSERT(!key.contains('='), return );
|
||||
auto it = findKey(m_values, m_osType, key);
|
||||
const auto it = findKey(key);
|
||||
if (it == m_values.end()) {
|
||||
m_values.insert(key, qMakePair(value, true));
|
||||
} else {
|
||||
@@ -104,7 +80,7 @@ void Environment::appendOrSet(const QString &key, const QString &value, const QS
|
||||
void Environment::prependOrSet(const QString &key, const QString &value, const QString &sep)
|
||||
{
|
||||
QTC_ASSERT(!key.contains('='), return );
|
||||
auto it = findKey(m_values, m_osType, key);
|
||||
const auto it = findKey(key);
|
||||
if (it == m_values.end()) {
|
||||
m_values.insert(key, qMakePair(value, true));
|
||||
} else {
|
||||
@@ -346,7 +322,7 @@ QString Environment::expandVariables(const QString &input) const
|
||||
for (int vStart = -1, i = 0; i < result.length(); ) {
|
||||
if (result.at(i++) == '%') {
|
||||
if (vStart > 0) {
|
||||
const_iterator it = findKey(m_values, m_osType, result.mid(vStart, i - vStart - 1));
|
||||
const auto it = findKey(result.mid(vStart, i - vStart - 1));
|
||||
if (it != m_values.constEnd()) {
|
||||
result.replace(vStart - 1, i - vStart + 1, it->first);
|
||||
i = vStart - 1 + it->first.length();
|
||||
|
@@ -31,30 +31,6 @@
|
||||
|
||||
namespace Utils {
|
||||
|
||||
namespace {
|
||||
NameValueMap::iterator findKey(NameValueMap &input, Utils::OsType osType, const QString &key)
|
||||
{
|
||||
const Qt::CaseSensitivity casing = (osType == Utils::OsTypeWindows) ? Qt::CaseInsensitive
|
||||
: Qt::CaseSensitive;
|
||||
for (auto it = input.begin(); it != input.end(); ++it) {
|
||||
if (key.compare(it.key(), casing) == 0)
|
||||
return it;
|
||||
}
|
||||
return input.end();
|
||||
}
|
||||
|
||||
NameValueMap::const_iterator findKey(const NameValueMap &input, Utils::OsType osType, const QString &key)
|
||||
{
|
||||
const Qt::CaseSensitivity casing = (osType == Utils::OsTypeWindows) ? Qt::CaseInsensitive
|
||||
: Qt::CaseSensitive;
|
||||
for (auto it = input.constBegin(); it != input.constEnd(); ++it) {
|
||||
if (key.compare(it.key(), casing) == 0)
|
||||
return it;
|
||||
}
|
||||
return input.constEnd();
|
||||
}
|
||||
} // namespace
|
||||
|
||||
NameValueDictionary::NameValueDictionary(const QStringList &env, OsType osType)
|
||||
: m_osType(osType)
|
||||
{
|
||||
@@ -76,6 +52,24 @@ NameValueDictionary::NameValueDictionary(const NameValuePairs &nameValues)
|
||||
set(nameValue.first, nameValue.second);
|
||||
}
|
||||
|
||||
NameValueMap::iterator NameValueDictionary::findKey(const QString &key)
|
||||
{
|
||||
for (auto it = m_values.begin(); it != m_values.end(); ++it) {
|
||||
if (key.compare(it.key(), nameCaseSensitivity()) == 0)
|
||||
return it;
|
||||
}
|
||||
return m_values.end();
|
||||
}
|
||||
|
||||
NameValueMap::const_iterator NameValueDictionary::findKey(const QString &key) const
|
||||
{
|
||||
for (auto it = m_values.constBegin(); it != m_values.constEnd(); ++it) {
|
||||
if (key.compare(it.key(), nameCaseSensitivity()) == 0)
|
||||
return it;
|
||||
}
|
||||
return m_values.constEnd();
|
||||
}
|
||||
|
||||
QStringList NameValueDictionary::toStringList() const
|
||||
{
|
||||
QStringList result;
|
||||
@@ -89,7 +83,7 @@ QStringList NameValueDictionary::toStringList() const
|
||||
void NameValueDictionary::set(const QString &key, const QString &value, bool enabled)
|
||||
{
|
||||
QTC_ASSERT(!key.contains('='), return );
|
||||
auto it = findKey(m_values, m_osType, key);
|
||||
const auto it = findKey(key);
|
||||
const auto valuePair = qMakePair(value, enabled);
|
||||
if (it == m_values.end())
|
||||
m_values.insert(key, valuePair);
|
||||
@@ -100,7 +94,7 @@ void NameValueDictionary::set(const QString &key, const QString &value, bool ena
|
||||
void NameValueDictionary::unset(const QString &key)
|
||||
{
|
||||
QTC_ASSERT(!key.contains('='), return );
|
||||
auto it = findKey(m_values, m_osType, key);
|
||||
const auto it = findKey(key);
|
||||
if (it != m_values.end())
|
||||
m_values.erase(it);
|
||||
}
|
||||
@@ -112,13 +106,13 @@ void NameValueDictionary::clear()
|
||||
|
||||
QString NameValueDictionary::value(const QString &key) const
|
||||
{
|
||||
const auto it = findKey(m_values, m_osType, key);
|
||||
const auto it = findKey(key);
|
||||
return it != m_values.end() && it.value().second ? it.value().first : QString();
|
||||
}
|
||||
|
||||
NameValueDictionary::const_iterator NameValueDictionary::constFind(const QString &name) const
|
||||
{
|
||||
return findKey(m_values, m_osType, name);
|
||||
return findKey(name);
|
||||
}
|
||||
|
||||
int NameValueDictionary::size() const
|
||||
@@ -195,6 +189,11 @@ OsType NameValueDictionary::osType() const
|
||||
return m_osType;
|
||||
}
|
||||
|
||||
Qt::CaseSensitivity NameValueDictionary::nameCaseSensitivity() const
|
||||
{
|
||||
return OsSpecificAspects::envVarCaseSensitivity(osType());
|
||||
}
|
||||
|
||||
QString NameValueDictionary::userName() const
|
||||
{
|
||||
return value(QString::fromLatin1(m_osType == OsTypeWindows ? "USERNAME" : "USER"));
|
||||
|
@@ -55,6 +55,7 @@ public:
|
||||
NameValueItems diff(const NameValueDictionary &other, bool checkAppendPrepend = false) const;
|
||||
bool hasKey(const QString &key) const;
|
||||
OsType osType() const;
|
||||
Qt::CaseSensitivity nameCaseSensitivity() const;
|
||||
|
||||
QString userName() const;
|
||||
|
||||
@@ -80,6 +81,9 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
NameValueMap::iterator findKey(const QString &key);
|
||||
const_iterator findKey(const QString &key) const;
|
||||
|
||||
NameValueMap m_values;
|
||||
OsType m_osType;
|
||||
};
|
||||
|
@@ -51,6 +51,11 @@ inline Qt::CaseSensitivity fileNameCaseSensitivity(OsType osType)
|
||||
return osType == OsTypeWindows || osType == OsTypeMac ? Qt::CaseInsensitive : Qt::CaseSensitive;
|
||||
}
|
||||
|
||||
inline Qt::CaseSensitivity envVarCaseSensitivity(OsType osType)
|
||||
{
|
||||
return fileNameCaseSensitivity(osType);
|
||||
}
|
||||
|
||||
inline QChar pathListSeparator(OsType osType)
|
||||
{
|
||||
return QLatin1Char(osType == OsTypeWindows ? ';' : ':');
|
||||
|
Reference in New Issue
Block a user