Skip to content

Commit c536926

Browse files
Substitute QRegExp with QRegularExpression
1 parent 86daeac commit c536926

17 files changed

+83
-73
lines changed

Engine/CLArgs.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include <QDebug>
4040
#include <QFile>
4141
#include <QFileInfo>
42+
#include <QRegularExpression>
4243

4344
#include "Global/GlobalDefines.h"
4445
#include "Global/GitVersion.h"
@@ -1139,10 +1140,10 @@ CLArgsPrivate::parse()
11391140
// A clean solution would be to separate the scriptName and the fileName with a comma.
11401141
if ( it != args.end() && !it->startsWith( QChar::fromLatin1('-') ) ) {
11411142
// Check that it's neither a python script, a natron project, nor a frame range.
1142-
QRegExp re( QString::fromUtf8("[0-9\\-,]*") ); // Matches frame ranges.
1143+
QRegularExpression re( QString::fromUtf8("[0-9\\-,]*") ); // Matches frame ranges.
11431144
if (!it->endsWith(QString::fromUtf8(".py"), Qt::CaseInsensitive) &&
11441145
!it->endsWith(QString::fromUtf8(".ntp"), Qt::CaseInsensitive) &&
1145-
!re.exactMatch(*it)) {
1146+
!re.match(*it).hasMatch()) {
11461147
w.filename = *it;
11471148
#ifdef __NATRON_UNIX__
11481149
w.filename = AppManager::qt_tildeExpansion(w.filename);

Engine/FileSystemModel.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ CLANG_DIAG_OFF(uninitialized)
4747
#include <QDebug>
4848
#include <QUrl>
4949
#include <QMimeData>
50+
#include <QRegularExpression>
5051
CLANG_DIAG_ON(deprecated)
5152
CLANG_DIAG_ON(uninitialized)
5253

@@ -193,7 +194,7 @@ struct FileSystemModelPrivate
193194
QStringList headers;
194195
QDir::Filters filters;
195196
QString encodedRegexps;
196-
std::list<QRegExp> regexps;
197+
std::list<QRegularExpression> regexps;
197198
mutable QMutex filtersMutex;
198199
mutable QMutex sequenceModeEnabledMutex;
199200
bool sequenceModeEnabled;
@@ -1041,7 +1042,8 @@ FileSystemModel::setRegexpFilters(const QString& filters)
10411042
++i;
10421043
}
10431044
if ( regExp != QString( QLatin1Char('*') ) ) {
1044-
QRegExp rx(regExp, Qt::CaseInsensitive, QRegExp::Wildcard);
1045+
QRegularExpression rx(QRegularExpression::wildcardToRegularExpression(regExp));
1046+
rx.setPatternOptions(QRegularExpression::CaseInsensitiveOption);
10451047
if ( rx.isValid() ) {
10461048
_imp->regexps.push_back(rx);
10471049
}
@@ -1082,8 +1084,8 @@ FileSystemModel::isAcceptedByRegexps(const QString & path) const
10821084
return true;
10831085
}
10841086

1085-
for (std::list<QRegExp>::const_iterator it = _imp->regexps.begin(); it != _imp->regexps.end(); ++it) {
1086-
if ( it->exactMatch(path) ) {
1087+
for (std::list<QRegularExpression>::const_iterator it = _imp->regexps.begin(); it != _imp->regexps.end(); ++it) {
1088+
if ( it->match(path).hasMatch() ) {
10871089
return true;
10881090
}
10891091
}

Engine/Markdown.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
CLANG_DIAG_OFF(deprecated)
3131
CLANG_DIAG_OFF(uninitialized)
3232
#include <QTextStream>
33-
#include <QRegExp>
33+
#include <QRegularExpression>
3434
CLANG_DIAG_ON(deprecated)
3535
CLANG_DIAG_ON(uninitialized)
3636

@@ -79,7 +79,7 @@ QString
7979
Markdown::parseCustomLinksForHTML(const QString& markdown)
8080
{
8181
QString result = markdown;
82-
QRegExp rx( QString::fromUtf8("(\\|html::[^|]*\\|)\\|rst::[^|]*\\|") );
82+
QRegularExpression rx( QString::fromUtf8("(\\|html::[^|]*\\|)\\|rst::[^|]*\\|") );
8383
result.replace( rx, QString::fromUtf8("\\1") );
8484

8585
return result;
@@ -105,10 +105,9 @@ Markdown::fixSettingsHTML(const QString &html)
105105
QStringList list = html.split( QString::fromUtf8("\n") );
106106
Q_FOREACH(const QString &line, list) {
107107
if ( line.startsWith(QString::fromUtf8("<h2>")) ) {
108-
QRegExp rx( QString::fromUtf8("<h2>(.*)</h2>") );
109-
rx.indexIn(line);
110-
QString header = rx.cap(1);
111-
QString headerLink = header.toLower();
108+
QRegularExpression rx( QString::fromUtf8("<h2>(.*)</h2>") );
109+
QString header(rx.match(line).captured(1));
110+
QString headerLink(header.toLower());
112111
headerLink.replace( QString::fromUtf8(" "), QString::fromUtf8("-") );
113112
result.append(QString::fromUtf8("<h2 id=\"%1\">%2</h2>").arg(headerLink).arg(header));
114113
} else {

Engine/Node.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
#include <QWaitCondition>
4343
#include <QTextStream>
4444
#include <QFile>
45-
#include <QRegExp>
4645

4746
#include <ofxNatron.h>
4847

Engine/NodeDocumentation.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
#include <QTextStream>
2929
#include <QFile>
30+
#include <QRegularExpression>
3031

3132
#include "Engine/EffectInstance.h"
3233
#include "Engine/KnobTypes.h"
@@ -409,7 +410,7 @@ Node::makeDocumentation(bool genHTML) const
409410
pluginDescription = NATRON_NAMESPACE::convertFromPlainText(pluginDescription, NATRON_NAMESPACE::WhiteSpaceNormal);
410411

411412
// replace URLs with links
412-
QRegExp re( QString::fromUtf8("((http|ftp|https)://([\\w_-]+(?:(?:\\.[\\w_-]+)+))([\\w.,@?^=%&:/~+#-]*[\\w@?^=%&/~+#-])?)") );
413+
QRegularExpression re( QString::fromUtf8("((http|ftp|https)://([\\w_-]+(?:(?:\\.[\\w_-]+)+))([\\w.,@?^=%&:/~+#-]*[\\w@?^=%&/~+#-])?)") );
413414
pluginDescription.replace( re, QString::fromUtf8("<a href=\"\\1\">\\1</a>") );
414415
} else {
415416
pluginDescription = convertFromPlainTextToMarkdown(pluginDescription, genHTML, false);

Engine/OutputEffectInstance.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
#include <QReadWriteLock>
3636
#include <QCoreApplication>
3737
#include <QThread>
38-
#include <QRegExp>
38+
#include <QRegularExpression>
3939
#include <QtConcurrentMap> // QtCore on Qt4, QtConcurrent on Qt5
4040
#include <QtConcurrentRun> // QtCore on Qt4, QtConcurrent on Qt5
4141

@@ -268,7 +268,7 @@ OutputEffectInstance::renderFullSequence(bool isBlocking,
268268
std::size_t foundHash = pattern.find_first_of("#");
269269
if (foundHash == std::string::npos) {
270270
// Look for printf style numbering
271-
QRegExp exp(QString::fromUtf8("%[0-9]*d"));
271+
QRegularExpression exp(QString::fromUtf8("%[0-9]*d"));
272272
QString qp(QString::fromUtf8(pattern.c_str()));
273273
if (!qp.contains(exp)) {
274274
QString message = tr("You are trying to render the frame range [%1 - %2] but you did not specify any hash ('#') character(s) or printf-like format ('%d') for the padding. This will result in the same image being overwritten multiple times.").arg(first).arg(last);

Engine/Project.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
#include <QTextStream>
5656
#include <QHostInfo>
5757
#include <QtConcurrentRun> // QtCore on Qt4, QtConcurrent on Qt5
58+
#include <QRegularExpression>
5859

5960
#include <ofxhXml.h> // OFX::XML::escape
6061

@@ -504,7 +505,7 @@ findBackups(const QString & filePath)
504505
ret.append(filePath);
505506
}
506507
// find files matching filePath.~[0-9]+~
507-
QRegExp rx(QString::fromUtf8("\\.~(\\d+)~$"));
508+
QRegularExpression rx(QString::fromUtf8("\\.~(\\d+)~$"));
508509
QFileInfo fileInfo(filePath);
509510
QString fileName = fileInfo.fileName();
510511
QDirIterator it(fileInfo.dir());
@@ -518,7 +519,9 @@ findBackups(const QString & filePath)
518519

519520
// If the filename contains target string - put it in the hitlist
520521
QString fn = file.fileName();
521-
if (fn.startsWith(fileName) && rx.lastIndexIn(fn) == fileName.size()) {
522+
QRegularExpressionMatch match(rx.match(fileName));
523+
qsizetype pos = match.capturedEnd();
524+
if (fn.startsWith(fileName) && pos == fileName.size()) {
522525
ret.append(file.filePath());
523526
}
524527
}
@@ -532,10 +535,11 @@ findBackups(const QString & filePath)
532535
static QString
533536
nextBackup(const QString & filePath)
534537
{
535-
QRegExp rx(QString::fromUtf8("\\.~(\\d+)~$"));
536-
int pos = rx.lastIndexIn(filePath);
538+
QRegularExpression rx(QString::fromUtf8("\\.~(\\d+)~$"));
539+
QRegularExpressionMatch match(rx.match(filePath));
540+
int pos = match.capturedEnd();
537541
if (pos >= 0) {
538-
int i = rx.cap(1).toInt();
542+
int i = match.captured(1).toInt();
539543
return filePath.left(pos) + QString::fromUtf8(".~%1~").arg(i+1);
540544
} else {
541545
return filePath + QString::fromUtf8(".~1~");

Gui/FileTypeMainWindow_win.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
#include <QApplication>
5252
#include <QDir>
5353
#include <QFileInfo>
54-
#include <QRegExp>
54+
#include <QRegularExpression>
5555

5656
NATRON_NAMESPACE_ENTER
5757

@@ -283,9 +283,10 @@ DocumentWindow::ddeExecute(MSG* message,
283283
return true;
284284
}
285285

286-
QRegExp regCommand( QString::fromUtf8("^\\[(\\w+)\\((.*)\\)\\]$") );
287-
if ( regCommand.exactMatch(command) ) {
288-
executeDdeCommand( regCommand.cap(1), regCommand.cap(2) );
286+
QRegularExpression regCommand( QString::fromUtf8("^\\[(\\w+)\\((.*)\\)\\]$") );
287+
QRegularExpressionMatch match(regCommand.match(command));
288+
if ( match.hasMatch() ) {
289+
executeDdeCommand( match.captured(1), match.captured(2) );
289290
}
290291

291292
*result = 0;
@@ -345,15 +346,16 @@ void
345346
DocumentWindow::executeDdeCommand(const QString& command,
346347
const QString& params)
347348
{
348-
QRegExp regCommand( QString::fromUtf8("^\"(.*)\"$") );
349-
bool singleCommand = regCommand.exactMatch(params);
349+
QRegularExpression regCommand( QString::fromUtf8("^\"(.*)\"$") );
350+
QRegularExpressionMatch match(regCommand.match(params));
351+
bool singleCommand = match.hasMatch();
350352

351353
if ( ( 0 == command.compare(QString::fromUtf8("open"), Qt::CaseInsensitive) ) && singleCommand ) {
352-
ddeOpenFile( regCommand.cap(1) );
354+
ddeOpenFile( match.captured(1) );
353355
} else if ( ( 0 == command.compare(QString::fromUtf8("new"), Qt::CaseInsensitive) ) && singleCommand ) {
354-
ddeNewFile( regCommand.cap(1) );
356+
ddeNewFile( match.captured(1) );
355357
} else if ( ( 0 == command.compare(QString::fromUtf8("print"), Qt::CaseInsensitive) ) && singleCommand ) {
356-
ddePrintFile( regCommand.cap(1) );
358+
ddePrintFile( match.captured(1) );
357359
} else {
358360
executeUnknownDdeCommand(command, params);
359361
}

Gui/GuiFwd.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class QPoint;
8181
class QPointF;
8282
class QProgressDialog;
8383
class QRectF;
84+
class QRegularExpression;
8485
class QScrollArea;
8586
class QSplitter;
8687
class QStyleOptionViewItem;

Gui/NodeCreationDialog.cpp

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ CLANG_DIAG_OFF(uninitialized)
3737
#include <QApplication>
3838
#include <QListView>
3939
#include <QSettings>
40-
#include <QDesktopWidget>
41-
#include <QRegExp>
40+
#include <QRegularExpression>
4241
#include <QApplication>
4342
#include <QStringListModel>
4443
CLANG_DIAG_ON(deprecated)
@@ -151,12 +150,14 @@ CompleterLineEdit::filterText(const QString & txt)
151150
pattern.push_back(txt[i]);
152151
}
153152
pattern.push_back( QLatin1Char('*') );
154-
QRegExp expr(pattern, Qt::CaseInsensitive, QRegExp::WildcardUnix);
153+
QRegularExpression expr(QRegularExpression::wildcardToRegularExpression(pattern));
154+
expr.setPatternOptions(QRegularExpression::CaseInsensitiveOption);
155155

156156
#ifdef NODE_TAB_DIALOG_USE_MATCHED_LENGTH
157157
std::map<int, QStringList> matchOrdered;
158158
for (PluginsNamesMap::iterator it = _imp->names.begin(); it != _imp->names.end(); ++it) {
159-
if ( expr.exactMatch(it->second.first) ) {
159+
bool isMatch = expr.match(it->second.first).hasMatch();
160+
if ( isMatch ) {
160161
QStringList& matchedForLength = matchOrdered[expr.matchedLength()];
161162
matchedForLength.push_front(it->second.second);
162163
}
@@ -182,14 +183,6 @@ CompleterLineEdit::filterText(const QString & txt)
182183
}
183184

184185
QPoint p = mapToGlobal( QPoint( 0, height() ) );
185-
//QDesktopWidget* desktop = QApplication::desktop();
186-
//QRect screen = desktop->screenGeometry();
187-
//double maxHeight = ( screen.height() - p.y() ) * 0.8;
188-
//QFontMetrics fm = _imp->listView->fontMetrics();
189-
//maxHeight = std::min( maxHeight, ( rowCount * fm.height() * 1.2 + fm.height() ) );
190-
191-
// Position the text edit
192-
// _imp->listView->setFixedSize(width(),maxHeight);
193186

194187
_imp->listView->move(p);
195188
_imp->listView->show();

Gui/NodeGraph45.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ CLANG_DIAG_OFF(uninitialized)
3838
#include <QKeyEvent>
3939
#include <QApplication>
4040
#include <QCheckBox>
41+
#include <QRegularExpression>
4142
GCC_DIAG_UNUSED_PRIVATE_FIELD_ON
4243
CLANG_DIAG_ON(deprecated)
4344
CLANG_DIAG_ON(uninitialized)
@@ -366,16 +367,14 @@ FindNodeDialog::updateFindResults(const QString& filter)
366367

367368
return;
368369
}
369-
Qt::CaseSensitivity sensitivity = _imp->caseSensitivity->isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive;
370370
const NodesGuiList& activeNodes = _imp->graph->getAllActiveNodes();
371-
QRegExp exp(_imp->matchWhole->isChecked() ? filter :
372-
( QChar::fromLatin1('*') + filter + QChar::fromLatin1('*') ),
373-
sensitivity,
374-
QRegExp::Wildcard);
371+
QRegularExpression exp(QRegularExpression::wildcardToRegularExpression(
372+
_imp->matchWhole->isChecked() ? filter : ( QChar::fromLatin1('*') + filter + QChar::fromLatin1('*') )));
373+
exp.setPatternOptions(_imp->caseSensitivity->isChecked() ? QRegularExpression::NoPatternOption : QRegularExpression::CaseInsensitiveOption);
375374

376375
if ( exp.isValid() ) {
377376
for (NodesGuiList::const_iterator it = activeNodes.begin(); it != activeNodes.end(); ++it) {
378-
if ( (*it)->isVisible() && exp.exactMatch( QString::fromUtf8( (*it)->getNode()->getLabel().c_str() ) ) ) {
377+
if ( (*it)->isVisible() && exp.match( QString::fromUtf8( (*it)->getNode()->getLabel().c_str() ) ).hasMatch() ) {
379378
_imp->nodeResults.push_back(*it);
380379
}
381380
}

Gui/PreferencesPanel.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ CLANG_DIAG_OFF(uninitialized)
3737
#include <QApplication>
3838
#include <QKeyEvent>
3939
#include <QDesktopServices>
40+
#include <QRegularExpression>
4041
#include <QTreeWidget>
4142
#include <QTreeWidgetItem>
4243
#include <QStyledItemDelegate>
@@ -819,7 +820,8 @@ PreferencesPanel::filterPlugins(const QString & txt)
819820
pattern.push_back(txt[i]);
820821
}
821822
pattern.push_back( QLatin1Char('*') );
822-
QRegExp expr(pattern, Qt::CaseInsensitive, QRegExp::WildcardUnix);
823+
QRegularExpression expr(QRegularExpression::wildcardToRegularExpression(pattern));
824+
expr.setPatternOptions(QRegularExpression::CaseInsensitiveOption);
823825
std::list<QTreeWidgetItem*> itemsToDisplay;
824826
for (PluginTreeNodeList::iterator it = _imp->pluginsList.begin(); it != _imp->pluginsList.end(); ++it) {
825827
if ( it->plugin && it->plugin->getLabelWithoutSuffix().contains(expr) ) {

Gui/RenderStatsDialog.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#include <QHeaderView>
3535
#include <QCheckBox>
3636
#include <QItemSelectionModel>
37-
#include <QRegExp>
37+
#include <QRegularExpression>
3838

3939
#include "Engine/Node.h"
4040
#include "Engine/Timer.h"
@@ -1010,12 +1010,14 @@ RenderStatsDialogPrivate::updateVisibleRowsInternal(const QString& nameFilter,
10101010

10111011

10121012
if ( useUnixWildcardsCheckbox->isChecked() ) {
1013-
QRegExp nameExpr(nameFilter, Qt::CaseInsensitive, QRegExp::Wildcard);
1013+
QRegularExpression nameExpr(QRegularExpression::wildcardToRegularExpression(nameFilter));
1014+
nameExpr.setPatternOptions(QRegularExpression::CaseInsensitiveOption);
10141015
if ( !nameExpr.isValid() ) {
10151016
return;
10161017
}
10171018

1018-
QRegExp idExpr(pluginIDFilter, Qt::CaseInsensitive, QRegExp::Wildcard);
1019+
QRegularExpression idExpr(QRegularExpression::wildcardToRegularExpression(pluginIDFilter));
1020+
idExpr.setPatternOptions(QRegularExpression::CaseInsensitiveOption);
10191021
if ( !idExpr.isValid() ) {
10201022
return;
10211023
}
@@ -1028,8 +1030,8 @@ RenderStatsDialogPrivate::updateVisibleRowsInternal(const QString& nameFilter,
10281030
continue;
10291031
}
10301032

1031-
if ( ( nameFilter.isEmpty() || nameExpr.exactMatch( QString::fromUtf8( node->getLabel().c_str() ) ) ) &&
1032-
( pluginIDFilter.isEmpty() || idExpr.exactMatch( QString::fromUtf8( node->getPluginID().c_str() ) ) ) ) {
1033+
if ( ( nameFilter.isEmpty() || nameExpr.match( QString::fromUtf8( node->getLabel().c_str() ) ).hasMatch() ) &&
1034+
( pluginIDFilter.isEmpty() || idExpr.match( QString::fromUtf8( node->getPluginID().c_str() ) ).hasMatch() ) ) {
10331035
if ( view->isRowHidden(i, rootIdx) ) {
10341036
view->setRowHidden(i, rootIdx, false);
10351037
}

0 commit comments

Comments
 (0)