Skip to content

Commit

Permalink
Use std library find algorithm
Browse files Browse the repository at this point in the history
Also avoids mixing const and non-const iterators.
  • Loading branch information
luis-pereira committed May 3, 2024
1 parent a8d1e67 commit b218e9e
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions lib/kprocess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit b218e9e

Please sign in to comment.