Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use std if #545

Merged
merged 2 commits into from
May 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 19 additions & 15 deletions lib/kprocess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void KProcess::setNextOpenMode(QIODevice::OpenMode mode)

void KProcess::clearEnvironment()
{
setEnvironment(QStringList() << QString::fromLatin1(DUMMYENV));
setEnvironment(QStringList{QString::fromLatin1(DUMMYENV)});
}

void KProcess::setEnv(const QString &name, const QString &value, bool overwrite)
Expand All @@ -85,14 +85,16 @@ void KProcess::setEnv(const QString &name, const QString &value, bool overwrite)
}
QString fname(name);
fname.append(QLatin1Char('='));
for (QStringList::Iterator it = env.begin(); it != env.end(); ++it)
if ((*it).startsWith(fname)) {
if (overwrite) {
*it = fname.append(value);
setEnvironment(env);
}
return;
auto it = std::find_if(env.begin(), env.end(), [&fname](const QString &s) {
return s.startsWith(fname);
});
if (it != env.end()) {
if (overwrite) {
*it = fname.append(value);
setEnvironment(env);
}
return;
}
env.append(fname.append(value));
setEnvironment(env);
}
Expand All @@ -106,14 +108,16 @@ void KProcess::unsetEnv(const QString &name)
}
QString fname(name);
fname.append(QLatin1Char('='));
for (QStringList::Iterator it = env.begin(); it != env.end(); ++it)
if ((*it).startsWith(fname)) {
env.erase(it);
if (env.isEmpty())
env.append(QString::fromLatin1(DUMMYENV));
setEnvironment(env);
return;
auto it = std::find_if(env.begin(), env.end(), [&fname](const QString &s) {
return s.startsWith(fname);
});
if (it != env.end()) {
env.erase(it);
if (env.isEmpty()) {
env.append(QString::fromLatin1(DUMMYENV));
}
setEnvironment(env);
}
}

void KProcess::setProgram(const QString &exe, const QStringList &args)
Expand Down
Loading