[KCoreAddons] Port QRegExp to QRegularExpression
ClosedPublic

Authored by ahmadsamir on Dec 24 2019, 11:54 AM.

Details

Summary

Port QRegExp::exactMatch() by using QRegularExpression::anchoredPattern()
to match the entire subject string.

KStringHandler::tagUrls(), make the regex slightly easier to read and capture
the whole matched url to use when calling QString::replace().

Note that KStringHandler::perlSplit(QRegExp... will have to be kept and
marked for deprecation, since it's called by some other apps in KDE.
A new perlSplit() overload should be added, possibly, just one perlSplit()
function that takes a QString, and a param indicating whether to treat it
as plain text or a regular expression.

Test Plan

make && ctest

Diff Detail

Repository
R244 KCoreAddons
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
ahmadsamir created this revision.Dec 24 2019, 11:54 AM
Restricted Application added a project: Frameworks. · View Herald TranscriptDec 24 2019, 11:54 AM
ahmadsamir requested review of this revision.Dec 24 2019, 11:54 AM
apol added a comment.Dec 24 2019, 4:20 PM

Looks good overall

src/lib/util/klistopenfilesjob_unix.cpp
69

splitRef?

ahmadsamir added inline comments.Dec 24 2019, 5:15 PM
src/lib/util/klistopenfilesjob_unix.cpp
69

I didn't even know there was a splitRef...

It'll have to be something like:

QVector<QStringRef> pidList = out.splitRef(QRegularExpression(QStringLiteral("\\s+")), QString::SkipEmptyParts);
// remove duplicates
std::unique(pidList.begin(), pidList.end());

I'd better do it in a separate commit, given it's really going to change stuff here (that compiles BTW, so I know it works).

Interestingly running lsof | wc -l on my system gives 162709; so yeah, we should definitely replace QList with QVector and QString with QStringRef here. :D

apol accepted this revision.Dec 26 2019, 1:29 AM
apol added inline comments.
src/lib/util/klistopenfilesjob_unix.cpp
69

Yes, okay, do it in a separate patch.

This revision is now accepted and ready to land.Dec 26 2019, 1:29 AM
This revision was automatically updated to reflect the committed changes.