diff --git a/autotests/src/scripting_test.cpp b/autotests/src/scripting_test.cpp --- a/autotests/src/scripting_test.cpp +++ b/autotests/src/scripting_test.cpp @@ -38,7 +38,6 @@ #include #include #include -#include #include #include #include diff --git a/src/completion/katewordcompletion.cpp b/src/completion/katewordcompletion.cpp --- a/src/completion/katewordcompletion.cpp +++ b/src/completion/katewordcompletion.cpp @@ -41,7 +41,7 @@ #include #include -#include +#include #include #include #include @@ -313,7 +313,7 @@ KTextEditor::MovingRange *liRange; // range containing last inserted text KTextEditor::Range dcRange; // current range to be completed by directional completion KTextEditor::Cursor dcCursor; // directional completion search cursor - QRegExp re; // hrm + QRegularExpression re; // hrm int directionalPos; // be able to insert "" at the correct time bool isCompleting; // true when the directional completion is doing a completion }; @@ -469,13 +469,13 @@ while (true) { //qCDebug(LOG_KTE)<<"SEARCHING FOR "<re.pattern()<<" "<dcCursor; - pos = fw ? - d->re.indexIn(ln, d->dcCursor.column()) : - d->re.lastIndexIn(ln, d->dcCursor.column()); + QRegularExpressionMatch match; + pos = fw ? ln.indexOf(d->re, d->dcCursor.column(), &match) + : ln.lastIndexOf(d->re, d->dcCursor.column(), &match); - if (pos > -1) { // we matched a word + if (match.hasMatch()) { // we matched a word //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())) { // we got good a match! replace text and return. d->isCompleting = true; diff --git a/src/document/katedocument.cpp b/src/document/katedocument.cpp --- a/src/document/katedocument.cpp +++ b/src/document/katedocument.cpp @@ -84,6 +84,7 @@ #include #include #include +#include #include @@ -4459,10 +4460,10 @@ void KTextEditor::DocumentPrivate::readVariableLine(QString t, bool onlyViewAndRenderer) { - static const QRegExp kvLine(QStringLiteral("kate:(.*)")); - static const QRegExp kvLineWildcard(QStringLiteral("kate-wildcard\\((.*)\\):(.*)")); - static const QRegExp kvLineMime(QStringLiteral("kate-mimetype\\((.*)\\):(.*)")); - static const QRegExp kvVar(QStringLiteral("([\\w\\-]+)\\s+([^;]+)")); + static const QRegularExpression kvLine(QStringLiteral("kate:(.*)")); + static const QRegularExpression kvLineWildcard(QStringLiteral("kate-wildcard\\((.*)\\):(.*)")); + static const QRegularExpression kvLineMime(QStringLiteral("kate-mimetype\\((.*)\\):(.*)")); + static const QRegularExpression kvVar(QStringLiteral("([\\w\\-]+)\\s+([^;]+)")); // simple check first, no regex // no kate inside, no vars, simple... @@ -4474,12 +4475,13 @@ QString s; // now, try first the normal ones - if (kvLine.indexIn(t) > -1) { - s = kvLine.cap(1); + auto match = kvLine.match(t); + if (match.hasMatch()) { + s = match.captured(1); //qCDebug(LOG_KTE) << "normal variable line kate: matched: " << s; - } else if (kvLineWildcard.indexIn(t) > -1) { // regex given - const QStringList wildcards(kvLineWildcard.cap(1).split(QLatin1Char(';'), QString::SkipEmptyParts)); + } else if ((match = kvLineWildcard.match(t)).hasMatch()) { // regex given + const QStringList wildcards(match.captured(1).split(QLatin1Char(';'), QString::SkipEmptyParts)); const QString nameOfFile = url().fileName(); bool found = false; @@ -4494,18 +4496,18 @@ return; } - s = kvLineWildcard.cap(2); + s = match.captured(2); //qCDebug(LOG_KTE) << "guarded variable line kate-wildcard: matched: " << s; - } else if (kvLineMime.indexIn(t) > -1) { // mime-type given - const QStringList types(kvLineMime.cap(1).split(QLatin1Char(';'), QString::SkipEmptyParts)); + } else if ((match = kvLineMime.match(t)).hasMatch()) { // mime-type given + const QStringList types(match.captured(1).split(QLatin1Char(';'), QString::SkipEmptyParts)); // no matching type found if (!types.contains(mimeType())) { return; } - s = kvLineMime.cap(2); + s = match.captured(2); //qCDebug(LOG_KTE) << "guarded variable line kate-mimetype: matched: " << s; } else { // nothing found @@ -4527,13 +4529,13 @@ << QStringLiteral("font") << QStringLiteral("font-size") << QStringLiteral("scheme"); int spaceIndent = -1; // for backward compatibility; see below bool replaceTabsSet = false; - int p(0); + int startPos(0); QString var, val; - while ((p = kvVar.indexIn(s, p)) > -1) { - p += kvVar.matchedLength(); - var = kvVar.cap(1); - val = kvVar.cap(2).trimmed(); + while ((match = kvVar.match(s, startPos)).hasMatch()) { + startPos = match.capturedEnd(0); + var = match.captured(1); + val = match.captured(2).trimmed(); bool state; // store booleans here int n; // store ints here diff --git a/src/mode/katemodeconfigpage.cpp b/src/mode/katemodeconfigpage.cpp --- a/src/mode/katemodeconfigpage.cpp +++ b/src/mode/katemodeconfigpage.cpp @@ -34,7 +34,7 @@ #include #include "katepartdebug.h" -#include +#include #include #include #include @@ -286,7 +286,7 @@ void ModeConfigPage::showMTDlg() { QString text = i18n("Select the MimeTypes you want for this file type.\nPlease note that this will automatically edit the associated file extensions as well."); - QStringList list = ui->edtMimeTypes->text().split(QRegExp(QLatin1String("\\s*;\\s*")), QString::SkipEmptyParts); + QStringList list = ui->edtMimeTypes->text().split(QRegularExpression(QStringLiteral("\\s*;\\s*")), QString::SkipEmptyParts); KMimeTypeChooserDialog d(i18n("Select Mime Types"), text, list, QStringLiteral("text"), this); if (d.exec() == QDialog::Accepted) { // do some checking, warn user if mime types or patterns are removed. diff --git a/src/mode/katemodemanager.cpp b/src/mode/katemodemanager.cpp --- a/src/mode/katemodemanager.cpp +++ b/src/mode/katemodemanager.cpp @@ -32,7 +32,7 @@ #include -#include +#include #include //END Includes @@ -164,7 +164,7 @@ config.writeEntry("Indenter", type->indenter); QString varLine = type->varLine; - if (QRegExp(QLatin1String("kate:(.*)")).indexIn(varLine) < 0) { + if (varLine.indexOf(QRegularExpression(QStringLiteral("kate:(.*)"))) < 0) { varLine.prepend(QLatin1String("kate: ")); } diff --git a/src/printing/printpainter.cpp b/src/printing/printpainter.cpp --- a/src/printing/printpainter.cpp +++ b/src/printing/printpainter.cpp @@ -286,7 +286,7 @@ tags[QStringLiteral("U")].prepend(s); } - QRegExp reTags(QStringLiteral("%([dDfUhuyY])")); // TODO tjeck for "%%" + QRegularExpression reTags(QStringLiteral("%([dDfUhuyY])")); // TODO tjeck for "%%" if (m_useHeader) { pl.headerHeight = QFontMetrics(m_fhFont).height(); @@ -300,13 +300,14 @@ QMutableStringListIterator it(pl.headerTagList); while (it.hasNext()) { QString tag = it.next(); - int pos = reTags.indexIn(tag); + QRegularExpressionMatch match; + int pos = tag.indexOf(reTags, 0, &match); QString rep; while (pos > -1) { - rep = tags[reTags.cap(1)]; + rep = tags[match.captured(1)]; tag.replace((uint)pos, 2, rep); pos += rep.length(); - pos = reTags.indexIn(tag, pos); + pos = tag.indexOf(reTags, pos, &match); } it.setValue(tag); } @@ -324,13 +325,14 @@ QMutableStringListIterator it(pl.footerTagList); while (it.hasNext()) { QString tag = it.next(); - int pos = reTags.indexIn(tag); + QRegularExpressionMatch match; + int pos = tag.indexOf(reTags, 0, &match); QString rep; while (pos > -1) { - rep = tags[reTags.cap(1)]; + rep = tags[match.captured(1)]; tag.replace((uint)pos, 2, rep); pos += rep.length(); - pos = reTags.indexIn(tag, pos); + pos = tag.indexOf(reTags, pos, &match); } it.setValue(tag); } diff --git a/src/utils/katecmds.cpp b/src/utils/katecmds.cpp --- a/src/utils/katecmds.cpp +++ b/src/utils/katecmds.cpp @@ -33,7 +33,7 @@ #include -#include +#include //BEGIN CoreCommands KateCommands::CoreCommands *KateCommands::CoreCommands::m_instance = nullptr; @@ -204,7 +204,7 @@ } //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()); // ALL commands that takes no arguments. @@ -499,19 +499,20 @@ QString cmd = _cmd; // 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); + if (!match.hasMatch()) { return false; } - cmd = num.cap(1); + cmd = match.captured(1); // identify the base unsigned short int number = 0; int base = 10; if (cmd[0] == QLatin1Char('x') || cmd.startsWith(QLatin1String("0x"))) { - cmd.remove(QRegExp(QLatin1String("^0?x"))); + cmd.remove(QRegularExpression(QStringLiteral("^0?x"))); base = 16; } else if (cmd[0] == QLatin1Char('0')) { base = 8;