Skip to content

Commit

Permalink
Substitute QRegExp with QRegularExpression
Browse files Browse the repository at this point in the history
  • Loading branch information
YakoYakoYokuYoku committed Dec 21, 2024
1 parent 2c70fde commit 453d0c7
Show file tree
Hide file tree
Showing 17 changed files with 83 additions and 73 deletions.
5 changes: 3 additions & 2 deletions Engine/CLArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <QDebug>
#include <QFile>
#include <QFileInfo>
#include <QRegularExpression>

#include "Global/GlobalDefines.h"
#include "Global/GitVersion.h"
Expand Down Expand Up @@ -1139,10 +1140,10 @@ CLArgsPrivate::parse()
// A clean solution would be to separate the scriptName and the fileName with a comma.
if ( it != args.end() && !it->startsWith( QChar::fromLatin1('-') ) ) {
// Check that it's neither a python script, a natron project, nor a frame range.
QRegExp re( QString::fromUtf8("[0-9\\-,]*") ); // Matches frame ranges.
QRegularExpression re( QString::fromUtf8("[0-9\\-,]*") ); // Matches frame ranges.
if (!it->endsWith(QString::fromUtf8(".py"), Qt::CaseInsensitive) &&
!it->endsWith(QString::fromUtf8(".ntp"), Qt::CaseInsensitive) &&
!re.exactMatch(*it)) {
!re.match(*it).hasMatch()) {
w.filename = *it;
#ifdef __NATRON_UNIX__
w.filename = AppManager::qt_tildeExpansion(w.filename);
Expand Down
10 changes: 6 additions & 4 deletions Engine/FileSystemModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ CLANG_DIAG_OFF(uninitialized)
#include <QDebug>
#include <QUrl>
#include <QMimeData>
#include <QRegularExpression>
CLANG_DIAG_ON(deprecated)
CLANG_DIAG_ON(uninitialized)

Expand Down Expand Up @@ -193,7 +194,7 @@ struct FileSystemModelPrivate
QStringList headers;
QDir::Filters filters;
QString encodedRegexps;
std::list<QRegExp> regexps;
std::list<QRegularExpression> regexps;
mutable QMutex filtersMutex;
mutable QMutex sequenceModeEnabledMutex;
bool sequenceModeEnabled;
Expand Down Expand Up @@ -1041,7 +1042,8 @@ FileSystemModel::setRegexpFilters(const QString& filters)
++i;
}
if ( regExp != QString( QLatin1Char('*') ) ) {
QRegExp rx(regExp, Qt::CaseInsensitive, QRegExp::Wildcard);
QRegularExpression rx(QRegularExpression::wildcardToRegularExpression(regExp));
rx.setPatternOptions(QRegularExpression::CaseInsensitiveOption);
if ( rx.isValid() ) {
_imp->regexps.push_back(rx);
}
Expand Down Expand Up @@ -1082,8 +1084,8 @@ FileSystemModel::isAcceptedByRegexps(const QString & path) const
return true;
}

for (std::list<QRegExp>::const_iterator it = _imp->regexps.begin(); it != _imp->regexps.end(); ++it) {
if ( it->exactMatch(path) ) {
for (std::list<QRegularExpression>::const_iterator it = _imp->regexps.begin(); it != _imp->regexps.end(); ++it) {
if ( it->match(path).hasMatch() ) {
return true;
}
}
Expand Down
11 changes: 5 additions & 6 deletions Engine/Markdown.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
CLANG_DIAG_OFF(deprecated)
CLANG_DIAG_OFF(uninitialized)
#include <QTextStream>
#include <QRegExp>
#include <QRegularExpression>
CLANG_DIAG_ON(deprecated)
CLANG_DIAG_ON(uninitialized)

Expand Down Expand Up @@ -79,7 +79,7 @@ QString
Markdown::parseCustomLinksForHTML(const QString& markdown)
{
QString result = markdown;
QRegExp rx( QString::fromUtf8("(\\|html::[^|]*\\|)\\|rst::[^|]*\\|") );
QRegularExpression rx( QString::fromUtf8("(\\|html::[^|]*\\|)\\|rst::[^|]*\\|") );
result.replace( rx, QString::fromUtf8("\\1") );

return result;
Expand All @@ -105,10 +105,9 @@ Markdown::fixSettingsHTML(const QString &html)
QStringList list = html.split( QString::fromUtf8("\n") );
Q_FOREACH(const QString &line, list) {
if ( line.startsWith(QString::fromUtf8("<h2>")) ) {
QRegExp rx( QString::fromUtf8("<h2>(.*)</h2>") );
rx.indexIn(line);
QString header = rx.cap(1);
QString headerLink = header.toLower();
QRegularExpression rx( QString::fromUtf8("<h2>(.*)</h2>") );
QString header(rx.match(line).captured(1));
QString headerLink(header.toLower());
headerLink.replace( QString::fromUtf8(" "), QString::fromUtf8("-") );
result.append(QString::fromUtf8("<h2 id=\"%1\">%2</h2>").arg(headerLink).arg(header));
} else {
Expand Down
1 change: 0 additions & 1 deletion Engine/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
#include <QWaitCondition>
#include <QTextStream>
#include <QFile>
#include <QRegExp>

#include <ofxNatron.h>

Expand Down
3 changes: 2 additions & 1 deletion Engine/NodeDocumentation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include <QTextStream>
#include <QFile>
#include <QRegularExpression>

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

// replace URLs with links
QRegExp re( QString::fromUtf8("((http|ftp|https)://([\\w_-]+(?:(?:\\.[\\w_-]+)+))([\\w.,@?^=%&:/~+#-]*[\\w@?^=%&/~+#-])?)") );
QRegularExpression re( QString::fromUtf8("((http|ftp|https)://([\\w_-]+(?:(?:\\.[\\w_-]+)+))([\\w.,@?^=%&:/~+#-]*[\\w@?^=%&/~+#-])?)") );
pluginDescription.replace( re, QString::fromUtf8("<a href=\"\\1\">\\1</a>") );
} else {
pluginDescription = convertFromPlainTextToMarkdown(pluginDescription, genHTML, false);
Expand Down
4 changes: 2 additions & 2 deletions Engine/OutputEffectInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#include <QReadWriteLock>
#include <QCoreApplication>
#include <QThread>
#include <QRegExp>
#include <QRegularExpression>
#include <QtConcurrentMap> // QtCore on Qt4, QtConcurrent on Qt5
#include <QtConcurrentRun> // QtCore on Qt4, QtConcurrent on Qt5

Expand Down Expand Up @@ -268,7 +268,7 @@ OutputEffectInstance::renderFullSequence(bool isBlocking,
std::size_t foundHash = pattern.find_first_of("#");
if (foundHash == std::string::npos) {
// Look for printf style numbering
QRegExp exp(QString::fromUtf8("%[0-9]*d"));
QRegularExpression exp(QString::fromUtf8("%[0-9]*d"));
QString qp(QString::fromUtf8(pattern.c_str()));
if (!qp.contains(exp)) {
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);
Expand Down
14 changes: 9 additions & 5 deletions Engine/Project.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
#include <QTextStream>
#include <QHostInfo>
#include <QtConcurrentRun> // QtCore on Qt4, QtConcurrent on Qt5
#include <QRegularExpression>

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

Expand Down Expand Up @@ -504,7 +505,7 @@ findBackups(const QString & filePath)
ret.append(filePath);
}
// find files matching filePath.~[0-9]+~
QRegExp rx(QString::fromUtf8("\\.~(\\d+)~$"));
QRegularExpression rx(QString::fromUtf8("\\.~(\\d+)~$"));
QFileInfo fileInfo(filePath);
QString fileName = fileInfo.fileName();
QDirIterator it(fileInfo.dir());
Expand All @@ -518,7 +519,9 @@ findBackups(const QString & filePath)

// If the filename contains target string - put it in the hitlist
QString fn = file.fileName();
if (fn.startsWith(fileName) && rx.lastIndexIn(fn) == fileName.size()) {
QRegularExpressionMatch match(rx.match(fileName));
qsizetype pos = match.capturedEnd();
if (fn.startsWith(fileName) && pos == fileName.size()) {
ret.append(file.filePath());
}
}
Expand All @@ -532,10 +535,11 @@ findBackups(const QString & filePath)
static QString
nextBackup(const QString & filePath)
{
QRegExp rx(QString::fromUtf8("\\.~(\\d+)~$"));
int pos = rx.lastIndexIn(filePath);
QRegularExpression rx(QString::fromUtf8("\\.~(\\d+)~$"));
QRegularExpressionMatch match(rx.match(filePath));
int pos = match.capturedEnd();
if (pos >= 0) {
int i = rx.cap(1).toInt();
int i = match.captured(1).toInt();
return filePath.left(pos) + QString::fromUtf8(".~%1~").arg(i+1);
} else {
return filePath + QString::fromUtf8(".~1~");
Expand Down
20 changes: 11 additions & 9 deletions Gui/FileTypeMainWindow_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
#include <QApplication>
#include <QDir>
#include <QFileInfo>
#include <QRegExp>
#include <QRegularExpression>

NATRON_NAMESPACE_ENTER

Expand Down Expand Up @@ -283,9 +283,10 @@ DocumentWindow::ddeExecute(MSG* message,
return true;
}

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

*result = 0;
Expand Down Expand Up @@ -345,15 +346,16 @@ void
DocumentWindow::executeDdeCommand(const QString& command,
const QString& params)
{
QRegExp regCommand( QString::fromUtf8("^\"(.*)\"$") );
bool singleCommand = regCommand.exactMatch(params);
QRegularExpression regCommand( QString::fromUtf8("^\"(.*)\"$") );
QRegularExpressionMatch match(regCommand.match(params));
bool singleCommand = match.hasMatch();

if ( ( 0 == command.compare(QString::fromUtf8("open"), Qt::CaseInsensitive) ) && singleCommand ) {
ddeOpenFile( regCommand.cap(1) );
ddeOpenFile( match.captured(1) );
} else if ( ( 0 == command.compare(QString::fromUtf8("new"), Qt::CaseInsensitive) ) && singleCommand ) {
ddeNewFile( regCommand.cap(1) );
ddeNewFile( match.captured(1) );
} else if ( ( 0 == command.compare(QString::fromUtf8("print"), Qt::CaseInsensitive) ) && singleCommand ) {
ddePrintFile( regCommand.cap(1) );
ddePrintFile( match.captured(1) );
} else {
executeUnknownDdeCommand(command, params);
}
Expand Down
1 change: 1 addition & 0 deletions Gui/GuiFwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class QPoint;
class QPointF;
class QProgressDialog;
class QRectF;
class QRegularExpression;
class QScrollArea;
class QSplitter;
class QStyleOptionViewItem;
Expand Down
17 changes: 5 additions & 12 deletions Gui/NodeCreationDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ CLANG_DIAG_OFF(uninitialized)
#include <QApplication>
#include <QListView>
#include <QSettings>
#include <QDesktopWidget>
#include <QRegExp>
#include <QRegularExpression>
#include <QApplication>
#include <QStringListModel>
CLANG_DIAG_ON(deprecated)
Expand Down Expand Up @@ -151,12 +150,14 @@ CompleterLineEdit::filterText(const QString & txt)
pattern.push_back(txt[i]);
}
pattern.push_back( QLatin1Char('*') );
QRegExp expr(pattern, Qt::CaseInsensitive, QRegExp::WildcardUnix);
QRegularExpression expr(QRegularExpression::wildcardToRegularExpression(pattern));
expr.setPatternOptions(QRegularExpression::CaseInsensitiveOption);

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

QPoint p = mapToGlobal( QPoint( 0, height() ) );
//QDesktopWidget* desktop = QApplication::desktop();
//QRect screen = desktop->screenGeometry();
//double maxHeight = ( screen.height() - p.y() ) * 0.8;
//QFontMetrics fm = _imp->listView->fontMetrics();
//maxHeight = std::min( maxHeight, ( rowCount * fm.height() * 1.2 + fm.height() ) );

// Position the text edit
// _imp->listView->setFixedSize(width(),maxHeight);

_imp->listView->move(p);
_imp->listView->show();
Expand Down
11 changes: 5 additions & 6 deletions Gui/NodeGraph45.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ CLANG_DIAG_OFF(uninitialized)
#include <QKeyEvent>
#include <QApplication>
#include <QCheckBox>
#include <QRegularExpression>
GCC_DIAG_UNUSED_PRIVATE_FIELD_ON
CLANG_DIAG_ON(deprecated)
CLANG_DIAG_ON(uninitialized)
Expand Down Expand Up @@ -366,16 +367,14 @@ FindNodeDialog::updateFindResults(const QString& filter)

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

if ( exp.isValid() ) {
for (NodesGuiList::const_iterator it = activeNodes.begin(); it != activeNodes.end(); ++it) {
if ( (*it)->isVisible() && exp.exactMatch( QString::fromUtf8( (*it)->getNode()->getLabel().c_str() ) ) ) {
if ( (*it)->isVisible() && exp.match( QString::fromUtf8( (*it)->getNode()->getLabel().c_str() ) ).hasMatch() ) {
_imp->nodeResults.push_back(*it);
}
}
Expand Down
4 changes: 3 additions & 1 deletion Gui/PreferencesPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ CLANG_DIAG_OFF(uninitialized)
#include <QApplication>
#include <QKeyEvent>
#include <QDesktopServices>
#include <QRegularExpression>
#include <QTreeWidget>
#include <QTreeWidgetItem>
#include <QStyledItemDelegate>
Expand Down Expand Up @@ -819,7 +820,8 @@ PreferencesPanel::filterPlugins(const QString & txt)
pattern.push_back(txt[i]);
}
pattern.push_back( QLatin1Char('*') );
QRegExp expr(pattern, Qt::CaseInsensitive, QRegExp::WildcardUnix);
QRegularExpression expr(QRegularExpression::wildcardToRegularExpression(pattern));
expr.setPatternOptions(QRegularExpression::CaseInsensitiveOption);
std::list<QTreeWidgetItem*> itemsToDisplay;
for (PluginTreeNodeList::iterator it = _imp->pluginsList.begin(); it != _imp->pluginsList.end(); ++it) {
if ( it->plugin && it->plugin->getLabelWithoutSuffix().contains(expr) ) {
Expand Down
12 changes: 7 additions & 5 deletions Gui/RenderStatsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include <QHeaderView>
#include <QCheckBox>
#include <QItemSelectionModel>
#include <QRegExp>
#include <QRegularExpression>

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


if ( useUnixWildcardsCheckbox->isChecked() ) {
QRegExp nameExpr(nameFilter, Qt::CaseInsensitive, QRegExp::Wildcard);
QRegularExpression nameExpr(QRegularExpression::wildcardToRegularExpression(nameFilter));
nameExpr.setPatternOptions(QRegularExpression::CaseInsensitiveOption);
if ( !nameExpr.isValid() ) {
return;
}

QRegExp idExpr(pluginIDFilter, Qt::CaseInsensitive, QRegExp::Wildcard);
QRegularExpression idExpr(QRegularExpression::wildcardToRegularExpression(pluginIDFilter));
idExpr.setPatternOptions(QRegularExpression::CaseInsensitiveOption);
if ( !idExpr.isValid() ) {
return;
}
Expand All @@ -1028,8 +1030,8 @@ RenderStatsDialogPrivate::updateVisibleRowsInternal(const QString& nameFilter,
continue;
}

if ( ( nameFilter.isEmpty() || nameExpr.exactMatch( QString::fromUtf8( node->getLabel().c_str() ) ) ) &&
( pluginIDFilter.isEmpty() || idExpr.exactMatch( QString::fromUtf8( node->getPluginID().c_str() ) ) ) ) {
if ( ( nameFilter.isEmpty() || nameExpr.match( QString::fromUtf8( node->getLabel().c_str() ) ).hasMatch() ) &&
( pluginIDFilter.isEmpty() || idExpr.match( QString::fromUtf8( node->getPluginID().c_str() ) ).hasMatch() ) ) {
if ( view->isRowHidden(i, rootIdx) ) {
view->setRowHidden(i, rootIdx, false);
}
Expand Down
Loading

0 comments on commit 453d0c7

Please sign in to comment.