D9168: Migrate some QRegExps to QRegularExpression

Milian Wolff noreply at phabricator.kde.org
Tue Dec 5 09:25:06 UTC 2017


mwolff requested changes to this revision.
mwolff added inline comments.
This revision now requires changes to proceed.

INLINE COMMENTS

> katewordcompletion.cpp:316
>      KTextEditor::Cursor dcCursor;     // directional completion search cursor
> -    QRegExp re;           // hrm
> +    QRegularExpression re;           // hrm
>      int directionalPos;   // be able to insert "" at the correct time

`hrm` indeed :D wth? ;-)

> katewordcompletion.cpp:478
>              //qCDebug(LOG_KTE)<<"USABLE MATCH";
> -            QString m = d->re.cap(1);
> +            QString m = match.captured(1);
>              if (m != doc->text(*d->liRange) && (d->dcCursor.line() != d->dcRange.start().line() || pos != d->dcRange.start().column())) {

here and below: can you use capturedRef instead?

> katemodemanager.cpp:167
>          QString varLine = type->varLine;
> -        if (QRegExp(QLatin1String("kate:(.*)")).indexIn(varLine) < 0) {
> +        if (varLine.indexOf(QRegularExpression(QStringLiteral("kate:(.*)"))) < 0) {
>              varLine.prepend(QLatin1String("kate: "));

why is this using a regexp? the match group isn't used at all, and the .* can be anything, including empty. So this is the same as `varLine.contains(QLatin1String("kate:"))`

> printpainter.cpp:289
>  
> -        QRegExp reTags(QStringLiteral("%([dDfUhuyY])")); // TODO tjeck for "%%<TAG>"
> +        QRegularExpression reTags(QStringLiteral("%([dDfUhuyY])")); // TODO tjeck for "%%<TAG>"
>  

fix old typo: tjeck -> check

> katecmds.cpp:207
>      //create a list of args
> -    QStringList args(_cmd.split(QRegExp(QLatin1String("\\s+")), QString::SkipEmptyParts));
> +    QStringList args(_cmd.split(QRegularExpression(QLatin1String("\\s+")), QString::SkipEmptyParts));
>      QString cmd(args.takeFirst());

future cleanup: use splitRef instead, if possible.

> katecmds.cpp:502
>      // hex, octal, base 9+1
> -    QRegExp num(QLatin1String("^char *(0?x[0-9A-Fa-f]{1,4}|0[0-7]{1,6}|[0-9]{1,5})$"));
> -    if (num.indexIn(cmd) == -1) {
> +    QRegularExpression num(QLatin1String("^char *(0?x[0-9A-Fa-f]{1,4}|0[0-7]{1,6}|[0-9]{1,5})$"));
> +    QRegularExpressionMatch match = num.match(cmd);

static?

> katecmds.cpp:515
>      if (cmd[0] == QLatin1Char('x') || cmd.startsWith(QLatin1String("0x"))) {
> -        cmd.remove(QRegExp(QLatin1String("^0?x")));
> +        cmd.remove(QRegularExpression(QStringLiteral("^0?x")));
>          base = 16;

this should be split into two branches and then use `cmd.remove(0, 1)` and `cmd.remove(0, 2)` respectively

REPOSITORY
  R39 KTextEditor

REVISION DETAIL
  https://phabricator.kde.org/D9168

To: dhaumann, cullmann, kfunk, mwolff
Cc: #frameworks, kevinapavew, ngraham, demsking, cullmann, sars, dhaumann
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kde-frameworks-devel/attachments/20171205/ab8264f2/attachment-0001.html>


More information about the Kde-frameworks-devel mailing list