Skip to content

Commit

Permalink
Replace QRegExp with QRegularExpression (#7133)
Browse files Browse the repository at this point in the history
* replace QRegExp with QRegularExpression (find n replace)

* follow up to fix errors

* removed rpmalloc

* Fix compilation for qt5, to be fixed when qt6 fully supported.

Co-authored-by: Kevin Zander <veratil@gmail.com>

* Added QtGlobal header for version finding fix

* Use the other syntax to try fix compilation.

* Check for 5.12 instead.

* Fix the header

* Attempt at fixing it further.

* Use version checks properly in header file

* Use QT_VERSION_CHECK macro in sources

* Apply suggestions from messmerd's review

Co-authored-by: Dalton Messmer <messmer.dalton@gmail.com>

---------

Co-authored-by: Kevin Zander <veratil@gmail.com>
Co-authored-by: Dalton Messmer <messmer.dalton@gmail.com>
  • Loading branch information
3 people authored Mar 16, 2024
1 parent b9ebc24 commit 4120a04
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 27 deletions.
3 changes: 2 additions & 1 deletion include/AutomatableModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
#ifndef LMMS_AUTOMATABLE_MODEL_H
#define LMMS_AUTOMATABLE_MODEL_H

#include <cmath>
#include <QMap>
#include <QMutex>
#include <cmath>
#include <QRegularExpression>

#include "JournallingObject.h"
#include "Model.h"
Expand Down
17 changes: 13 additions & 4 deletions include/EffectSelectDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include <QKeyEvent>
#include <QMouseEvent>
#include <QPushButton>
#include <QRegExp>
#include <QRegularExpression>
#include <QScrollArea>
#include <QSortFilterProxyModel>
#include <QStandardItemModel>
Expand Down Expand Up @@ -65,10 +65,19 @@ class DualColumnFilterProxyModel : public QSortFilterProxyModel
QString name = sourceModel()->data(nameIndex, Qt::DisplayRole).toString();
QString type = sourceModel()->data(typeIndex, Qt::DisplayRole).toString();

QRegExp nameRegExp(filterRegExp());
nameRegExp.setCaseSensitivity(Qt::CaseInsensitive);
// TODO: cleanup once we drop Qt5 support
#if (QT_VERSION >= QT_VERSION_CHECK(5,12,0))
QRegularExpression nameRegularExpression(filterRegularExpression());
nameRegularExpression.setPatternOptions(QRegularExpression::CaseInsensitiveOption);

bool nameFilterPassed = nameRegularExpression.match(name).capturedStart() != -1;
#else
QRegExp nameRegularExpression(filterRegExp());
nameRegularExpression.setCaseSensitivity(Qt::CaseInsensitive);

bool nameFilterPassed = nameRegularExpression.indexIn(name) != -1;
#endif

bool nameFilterPassed = nameRegExp.indexIn(name) != -1;
bool typeFilterPassed = type.contains(m_effectTypeFilter, Qt::CaseInsensitive);

return nameFilterPassed && typeFilterPassed;
Expand Down
4 changes: 3 additions & 1 deletion include/LadspaBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#ifndef LMMS_LADSPA_BASE_H
#define LMMS_LADSPA_BASE_H

#include <QRegularExpression>

#include "LadspaManager.h"
#include "Plugin.h"

Expand Down Expand Up @@ -75,7 +77,7 @@ inline Plugin::Descriptor::SubPluginFeatures::Key ladspaKeyToSubPluginKey(
{
Plugin::Descriptor::SubPluginFeatures::Key::AttributeMap m;
QString file = _key.first;
m["file"] = file.remove( QRegExp( "\\.so$" ) ).remove( QRegExp( "\\.dll$" ) );
m["file"] = file.remove(QRegularExpression("\\.so$")).remove(QRegularExpression("\\.dll$"));
m["plugin"] = _key.second;
return Plugin::Descriptor::SubPluginFeatures::Key( _desc, _name, m );
}
Expand Down
5 changes: 3 additions & 2 deletions plugins/CarlaBase/Carla.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <QCloseEvent>
#include <QDomElement>
#include <QMutex>
#include <QRegularExpression>

// carla/source/includes
#include "carlabase_export.h"
Expand Down Expand Up @@ -89,8 +90,8 @@ class CarlaParamFloatModel : public FloatModel
// From AutomatableModel.h, it's private there.
inline static bool mustQuoteName(const QString &name)
{
QRegExp reg("^[A-Za-z0-9._-]+$");
return !reg.exactMatch(name);
QRegularExpression reg("^[A-Za-z0-9._-]+$");
return !reg.match(name).hasMatch();
}

inline void loadSettings(const QDomElement& element, const QString& name = QString("value")) override
Expand Down
3 changes: 1 addition & 2 deletions plugins/LadspaEffect/LadspaSubPluginFeatures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,7 @@ ladspa_key_t LadspaSubPluginFeatures::subPluginKeyToLadspaKey(
const Key * _key )
{
QString file = _key->attributes["file"];
return( ladspa_key_t( file.remove( QRegExp( "\\.so$" ) ).
remove( QRegExp( "\\.dll$" ) ) +
return(ladspa_key_t(file.remove(QRegularExpression("\\.so$")).remove(QRegularExpression("\\.dll$")) +
#ifdef LMMS_BUILD_WIN32
".dll"
#else
Expand Down
2 changes: 1 addition & 1 deletion plugins/ZynAddSubFx/ZynAddSubFx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ void ZynAddSubFxInstrument::loadFile( const QString & _file )
m_pluginMutex.unlock();
}

instrumentTrack()->setName( QFileInfo( _file ).baseName().replace( QRegExp( "^[0-9]{4}-" ), QString() ) );
instrumentTrack()->setName(QFileInfo(_file).baseName().replace(QRegularExpression("^[0-9]{4}-"), QString()));

m_modifiedControllers.clear();

Expand Down
4 changes: 2 additions & 2 deletions src/core/AutomatableModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ bool AutomatableModel::isAutomated() const

bool AutomatableModel::mustQuoteName(const QString& name)
{
QRegExp reg("^[A-Za-z0-9._-]+$");
return !reg.exactMatch(name);
QRegularExpression reg("^[A-Za-z0-9._-]+$");
return !reg.match(name).hasMatch();
}

void AutomatableModel::saveSettings( QDomDocument& doc, QDomElement& element, const QString& name )
Expand Down
6 changes: 3 additions & 3 deletions src/core/DataFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <QFileInfo>
#include <QDir>
#include <QMessageBox>
#include <QRegularExpression>
#include <QSaveFile>

#include "base64.h"
Expand Down Expand Up @@ -973,8 +974,7 @@ void DataFile::upgrade_0_4_0_20080622()
{
QDomElement el = list.item( i ).toElement();
QString s = el.attribute( "name" );
s.replace( QRegExp( "^Beat/Baseline " ),
"Beat/Bassline " );
s.replace(QRegularExpression("^Beat/Baseline "), "Beat/Bassline");
el.setAttribute( "name", s );
}
}
Expand Down Expand Up @@ -1109,7 +1109,7 @@ void DataFile::upgrade_1_1_91()
{
QDomElement el = list.item( i ).toElement();
QString s = el.attribute( "src" );
s.replace( QRegExp("/samples/bassloopes/"), "/samples/bassloops/" );
s.replace(QRegularExpression("/samples/bassloopes/"), "/samples/bassloops/");
el.setAttribute( "src", s );
}

Expand Down
3 changes: 2 additions & 1 deletion src/core/RenderManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/

#include <QDir>
#include <QRegularExpression>

#include "RenderManager.h"

Expand Down Expand Up @@ -182,7 +183,7 @@ QString RenderManager::pathForTrack(const Track *track, int num)
{
QString extension = ProjectRenderer::getFileExtensionFromFormat( m_format );
QString name = track->name();
name = name.remove(QRegExp(FILENAME_FILTER));
name = name.remove(QRegularExpression(FILENAME_FILTER));
name = QString( "%1_%2%3" ).arg( num ).arg( name ).arg( extension );
return QDir(m_outputPath).filePath(name);
}
Expand Down
14 changes: 7 additions & 7 deletions src/gui/MicrotunerConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include <QMessageBox>
#include <QPlainTextEdit>
#include <QPushButton>
#include <QRegExp>
#include <QRegularExpression>
#include <QTextStream>

#include "ComboBox.h"
Expand Down Expand Up @@ -342,7 +342,7 @@ bool MicrotunerConfig::validateScaleForm()
{
if (line.isEmpty()) {continue;}
if (line[0] == '!') {continue;} // comment
QString firstSection = line.section(QRegExp("\\s+|/"), 0, 0, QString::SectionSkipEmpty);
QString firstSection = line.section(QRegularExpression("\\s+|/"), 0, 0, QString::SectionSkipEmpty);
if (firstSection.contains('.')) // cent mode
{
bool ok = true;
Expand All @@ -357,7 +357,7 @@ bool MicrotunerConfig::validateScaleForm()
if (!ok) {fail(tr("Numerator of an interval defined as a ratio cannot be converted to a number")); return false;}
if (line.contains('/'))
{
den = line.split('/').at(1).section(QRegExp("\\s+"), 0, 0, QString::SectionSkipEmpty).toInt(&ok);
den = line.split('/').at(1).section(QRegularExpression("\\s+"), 0, 0, QString::SectionSkipEmpty).toInt(&ok);
}
if (!ok) {fail(tr("Denominator of an interval defined as a ratio cannot be converted to a number")); return false;}
if (num * den < 0) {fail(tr("Interval defined as a ratio cannot be negative")); return false;}
Expand Down Expand Up @@ -390,7 +390,7 @@ bool MicrotunerConfig::validateKeymapForm()
{
if (line.isEmpty()) {continue;}
if (line[0] == '!') {continue;} // comment
QString firstSection = line.section(QRegExp("\\s+"), 0, 0, QString::SectionSkipEmpty);
QString firstSection = line.section(QRegularExpression("\\s+"), 0, 0, QString::SectionSkipEmpty);
if (firstSection == "x") {continue;} // not mapped
// otherwise must contain a number
bool ok = true;
Expand Down Expand Up @@ -424,7 +424,7 @@ bool MicrotunerConfig::applyScale()
{
if (line.isEmpty()) {continue;}
if (line[0] == '!') {continue;} // comment
QString firstSection = line.section(QRegExp("\\s+|/"), 0, 0, QString::SectionSkipEmpty);
QString firstSection = line.section(QRegularExpression("\\s+|/"), 0, 0, QString::SectionSkipEmpty);
if (firstSection.contains('.')) // cent mode
{
newIntervals.emplace_back(firstSection.toFloat());
Expand All @@ -435,7 +435,7 @@ bool MicrotunerConfig::applyScale()
num = firstSection.toInt();
if (line.contains('/'))
{
den = line.split('/').at(1).section(QRegExp("\\s+"), 0, 0, QString::SectionSkipEmpty).toInt();
den = line.split('/').at(1).section(QRegularExpression("\\s+"), 0, 0, QString::SectionSkipEmpty).toInt();
}
newIntervals.emplace_back(num, den);
}
Expand Down Expand Up @@ -470,7 +470,7 @@ bool MicrotunerConfig::applyKeymap()
{
if (line.isEmpty()) {continue;}
if (line[0] == '!') {continue;} // comment
QString firstSection = line.section(QRegExp("\\s+"), 0, 0, QString::SectionSkipEmpty);
QString firstSection = line.section(QRegularExpression("\\s+"), 0, 0, QString::SectionSkipEmpty);
if (firstSection == "x")
{
newMap.push_back(-1); // not mapped
Expand Down
2 changes: 1 addition & 1 deletion src/gui/instrument/InstrumentTrackWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ void InstrumentTrackWindow::saveSettingsBtnClicked()
sfd.setDirectory(presetRoot + m_track->instrumentName());
sfd.setFileMode( FileDialog::AnyFile );
QString fname = m_track->name();
sfd.selectFile(fname.remove(QRegExp(FILENAME_FILTER)));
sfd.selectFile(fname.remove(QRegularExpression(FILENAME_FILTER)));
sfd.setDefaultSuffix( "xpf");

if( sfd.exec() == QDialog::Accepted &&
Expand Down
6 changes: 6 additions & 0 deletions src/gui/modals/EffectSelectDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <QHBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <QRegularExpression>
#include <QScrollArea>
#include <QVBoxLayout>

Expand Down Expand Up @@ -126,7 +127,12 @@ EffectSelectDialog::EffectSelectDialog(QWidget* parent) :

m_filterEdit = new QLineEdit(this);
connect(m_filterEdit, &QLineEdit::textChanged, this, [this](const QString &text) {
// TODO: Cleanup when we don't support Qt5 anymore
#if (QT_VERSION >= QT_VERSION_CHECK(5,12,0))
m_model.setFilterRegularExpression(QRegularExpression(text, QRegularExpression::CaseInsensitiveOption));
#else
m_model.setFilterRegExp(QRegExp(text, Qt::CaseInsensitive));
#endif
});
connect(m_filterEdit, &QLineEdit::textChanged, this, &EffectSelectDialog::updateSelection);
m_filterEdit->setFocus();
Expand Down
4 changes: 2 additions & 2 deletions src/gui/modals/VersionedSaveDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ VersionedSaveDialog::VersionedSaveDialog( QWidget *parent,

bool VersionedSaveDialog::changeFileNameVersion(QString &fileName, bool increment )
{
static QRegExp regexp( "[- ]\\d+(\\.\\w+)?$" );
static QRegularExpression regex( "[- ]\\d+(\\.\\w+)?$" );

int idx = regexp.indexIn( fileName );
int idx = regex.match(fileName).capturedStart();
// For file names without extension (no ".mmpz")
int insertIndex = fileName.lastIndexOf( '.' );
if ( insertIndex < idx+1 )
Expand Down

0 comments on commit 4120a04

Please sign in to comment.