diff --git a/src/common/ColorThemeWorker.cpp b/src/common/ColorThemeWorker.cpp index e2acb849..7e3cb086 100644 --- a/src/common/ColorThemeWorker.cpp +++ b/src/common/ColorThemeWorker.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include "common/Configuration.h" @@ -313,13 +314,14 @@ bool ColorThemeWorker::isFileTheme(const QString& filePath, bool* ok) const QString options = (Core()->cmdj("ecj").object().keys() << cutterSpecificOptions) .join('|') .replace(".", "\\."); - QRegExp regexp = QRegExp(QString("((ec\\s+(%1)\\s+(((rgb:|#)[0-9a-fA-F]{3,8})|(%2))))\\s*") - .arg(options) - .arg(colors)); + + QString pattern = QString("((ec\\s+(%1)\\s+(((rgb:|#)[0-9a-fA-F]{3,8})|(%2))))\\s*").arg(options).arg(colors); + // The below construct mimics the behaviour of QRegexP::exactMatch(), which was here before + QRegularExpression regexp("\\A(?:" + pattern + ")\\z"); for (auto &line : QString(f.readAll()).split('\n', QString::SkipEmptyParts)) { line.replace("#~", "ec "); - if (!line.isEmpty() && !regexp.exactMatch(line)) { + if (!line.isEmpty() && !regexp.match(line).hasMatch()) { *ok = true; return false; } diff --git a/src/common/HexAsciiHighlighter.cpp b/src/common/HexAsciiHighlighter.cpp index 4b46500a..af3f1a17 100644 --- a/src/common/HexAsciiHighlighter.cpp +++ b/src/common/HexAsciiHighlighter.cpp @@ -8,42 +8,43 @@ AsciiHighlighter::AsciiHighlighter(QTextDocument *parent) HighlightingRule rule; asciiFormat.setForeground(QColor(65, 131, 215)); - rule.pattern = QRegExp("\\b[A-Za-z0-9]+\\b"); + rule.pattern.setPattern("\\b[A-Za-z0-9]+\\b"); rule.format = asciiFormat; highlightingRules.append(rule); - commentStartExpression = QRegExp("/\\*"); - commentEndExpression = QRegExp("\\*/"); + commentStartRegularExpression.setPattern("/\\*"); + commentEndRegularExpression.setPattern("\\*/"); } void AsciiHighlighter::highlightBlock(const QString &text) { for (const HighlightingRule &rule : highlightingRules) { - QRegExp expression(rule.pattern); - int index = expression.indexIn(text); + QRegularExpression expression(rule.pattern); + int index = expression.match(text).capturedStart(); while (index >= 0) { - int length = expression.matchedLength(); + int length = expression.match(text).capturedLength(); setFormat(index, length, rule.format); - index = expression.indexIn(text, index + length); + index = expression.match(text.mid(index + length)).capturedStart(); } } setCurrentBlockState(0); int startIndex = 0; if (previousBlockState() != 1) - startIndex = commentStartExpression.indexIn(text); + startIndex = QRegularExpression(commentStartRegularExpression).match(text).capturedStart(); while (startIndex >= 0) { - int endIndex = commentEndExpression.indexIn(text, startIndex); + QRegularExpressionMatch commentEndMatch = QRegularExpression(commentEndRegularExpression).match(text.mid(startIndex)); + int endIndex = commentEndMatch.capturedStart(); int commentLength; if (endIndex == -1) { setCurrentBlockState(1); commentLength = text.length() - startIndex; } else { commentLength = endIndex - startIndex - + commentEndExpression.matchedLength(); + + commentEndMatch.capturedLength(); } setFormat(startIndex, commentLength, multiLineCommentFormat); - startIndex = commentStartExpression.indexIn(text, startIndex + commentLength); + startIndex = QRegularExpression(commentStartRegularExpression).match(text.mid(startIndex + commentLength)).capturedStart(); } } diff --git a/src/common/HexAsciiHighlighter.h b/src/common/HexAsciiHighlighter.h index 407980ca..fb08ddbd 100644 --- a/src/common/HexAsciiHighlighter.h +++ b/src/common/HexAsciiHighlighter.h @@ -5,6 +5,7 @@ #include #include +#include class QTextDocument; @@ -20,13 +21,13 @@ protected: private: struct HighlightingRule { - QRegExp pattern; + QRegularExpression pattern; QTextCharFormat format; }; QVector highlightingRules; - QRegExp commentStartExpression; - QRegExp commentEndExpression; + QRegularExpression commentStartRegularExpression; + QRegularExpression commentEndRegularExpression; QTextCharFormat keywordFormat; QTextCharFormat classFormat; diff --git a/src/common/HexHighlighter.cpp b/src/common/HexHighlighter.cpp index c9f5e050..0a18bfb3 100644 --- a/src/common/HexHighlighter.cpp +++ b/src/common/HexHighlighter.cpp @@ -27,51 +27,51 @@ HexHighlighter::HexHighlighter(QTextDocument *parent) << "\\b75\\b" << "\\b76\\b" << "\\b77\\b" << "\\b78\\b" << "\\b79\\b" << "\\b7a\\b" << "\\b7b\\b" << "\\b7c\\b" << "\\b7d\\b" << "\\b7e\\b" << "\\b7f\\b"; for (const QString &pattern : keywordPatterns) { - rule.pattern = QRegExp(pattern); - rule.pattern.setCaseSensitivity(Qt::CaseInsensitive); + rule.pattern.setPattern(pattern); + rule.pattern.setPatternOptions(QRegularExpression::CaseInsensitiveOption); rule.format = keywordFormat; highlightingRules.append(rule); } singleLineCommentFormat.setFontWeight(QFont::Bold); singleLineCommentFormat.setForeground(Qt::darkGreen); - rule.pattern = QRegExp(";[^\n]*"); + rule.pattern.setPattern(";[^\n]*"); rule.format = singleLineCommentFormat; highlightingRules.append(rule); - commentStartExpression = QRegExp("/\\*"); - commentEndExpression = QRegExp("\\*/"); + commentStartRegularExpression.setPattern("/\\*"); + commentEndRegularExpression.setPattern("\\*/"); } void HexHighlighter::highlightBlock(const QString &text) { for (const HighlightingRule &rule : highlightingRules) { - QRegExp expression(rule.pattern); - int index = expression.indexIn(text); + QRegularExpression expression(rule.pattern); + int index = expression.match(text).capturedStart(); while (index >= 0) { - int length = expression.matchedLength(); + int length = expression.match(text).capturedLength(); setFormat(index, length, rule.format); - index = expression.indexIn(text, index + length); + index = expression.match(text.mid(index + length)).capturedStart(); } } setCurrentBlockState(0); int startIndex = 0; if (previousBlockState() != 1) - startIndex = commentStartExpression.indexIn(text); + startIndex = QRegularExpression(commentStartRegularExpression).match(text).capturedStart(); while (startIndex >= 0) { - int endIndex = commentEndExpression.indexIn(text, startIndex); + QRegularExpressionMatch commentEndMatch = QRegularExpression(commentEndRegularExpression).match(text.mid(startIndex)); + int endIndex = commentEndMatch.capturedStart(); int commentLength; if (endIndex == -1) { setCurrentBlockState(1); commentLength = text.length() - startIndex; } else { commentLength = endIndex - startIndex - + commentEndExpression.matchedLength(); + + commentEndMatch.capturedLength(); } setFormat(startIndex, commentLength, multiLineCommentFormat); - startIndex = commentStartExpression.indexIn(text, startIndex + commentLength); + startIndex = QRegularExpression(commentStartRegularExpression).match(text.mid(startIndex + commentLength)).capturedStart(); } } - diff --git a/src/common/HexHighlighter.h b/src/common/HexHighlighter.h index 1de74666..47b95711 100644 --- a/src/common/HexHighlighter.h +++ b/src/common/HexHighlighter.h @@ -5,6 +5,7 @@ #include #include +#include class QTextDocument; @@ -20,13 +21,13 @@ protected: private: struct HighlightingRule { - QRegExp pattern; + QRegularExpression pattern; QTextCharFormat format; }; QVector highlightingRules; - QRegExp commentStartExpression; - QRegExp commentEndExpression; + QRegularExpression commentStartRegularExpression; + QRegularExpression commentEndRegularExpression; QTextCharFormat keywordFormat; QTextCharFormat classFormat; diff --git a/src/common/Highlighter.cpp b/src/common/Highlighter.cpp index b4fec783..44021b0a 100644 --- a/src/common/Highlighter.cpp +++ b/src/common/Highlighter.cpp @@ -13,8 +13,8 @@ Highlighter::Highlighter(QTextDocument *parent) : keywordFormat.setForeground(QColor(65, 131, 215)); for (const QString &pattern : this->core->opcodes) { - rule.pattern = QRegExp("\\b" + pattern + "\\b"); - rule.pattern.setCaseSensitivity(Qt::CaseInsensitive); + rule.pattern.setPattern("\\b" + pattern + "\\b"); + rule.pattern.setPatternOptions(QRegularExpression::CaseInsensitiveOption); rule.format = keywordFormat; highlightingRules.append(rule); } @@ -22,8 +22,8 @@ Highlighter::Highlighter(QTextDocument *parent) : regFormat.setForeground(QColor(236, 100, 75)); for (const QString &pattern : this->core->regs) { - rule.pattern = QRegExp("\\b" + pattern + "\\b"); - rule.pattern.setCaseSensitivity(Qt::CaseInsensitive); + rule.pattern.setPattern("\\b" + pattern + "\\b"); + rule.pattern.setPatternOptions(QRegularExpression::CaseInsensitiveOption); rule.format = regFormat; highlightingRules.append(rule); } @@ -31,42 +31,43 @@ Highlighter::Highlighter(QTextDocument *parent) : singleLineCommentFormat.setFontWeight(QFont::Bold); singleLineCommentFormat.setForeground(QColor(63, 195, 128)); - rule.pattern = QRegExp(";[^\n]*"); + rule.pattern.setPattern(";[^\n]*"); rule.format = singleLineCommentFormat; highlightingRules.append(rule); - commentStartExpression = QRegExp("/\\*"); - commentEndExpression = QRegExp("\\*/"); + commentStartRegularExpression.setPattern("/\\*"); + commentEndRegularExpression.setPattern("\\*/"); } void Highlighter::highlightBlock(const QString &text) { for (const HighlightingRule &rule : highlightingRules) { - QRegExp expression(rule.pattern); - int index = expression.indexIn(text); + QRegularExpression expression(rule.pattern); + int index = expression.match(text).capturedStart(); while (index >= 0) { - int length = expression.matchedLength(); + int length = expression.match(text).capturedLength(); setFormat(index, length, rule.format); - index = expression.indexIn(text, index + length); + index = expression.match(text.mid(index + length)).capturedStart(); } } setCurrentBlockState(0); int startIndex = 0; if (previousBlockState() != 1) - startIndex = commentStartExpression.indexIn(text); + startIndex = QRegularExpression(commentStartRegularExpression).match(text).capturedStart(); while (startIndex >= 0) { - int endIndex = commentEndExpression.indexIn(text, startIndex); + QRegularExpressionMatch commentEndMatch = QRegularExpression(commentEndRegularExpression).match(text.mid(startIndex)); + int endIndex = commentEndMatch.capturedStart(); int commentLength; if (endIndex == -1) { setCurrentBlockState(1); commentLength = text.length() - startIndex; } else { commentLength = endIndex - startIndex - + commentEndExpression.matchedLength(); + + commentEndMatch.capturedLength(); } setFormat(startIndex, commentLength, multiLineCommentFormat); - startIndex = commentStartExpression.indexIn(text, startIndex + commentLength); + startIndex = QRegularExpression(commentStartRegularExpression).match(text.mid(startIndex + commentLength)).capturedStart(); } } diff --git a/src/common/Highlighter.h b/src/common/Highlighter.h index 3e49f2e2..31732047 100644 --- a/src/common/Highlighter.h +++ b/src/common/Highlighter.h @@ -6,6 +6,7 @@ #include #include #include +#include class QTextDocument; class MainWindow; @@ -24,13 +25,13 @@ private: CutterCore *core; struct HighlightingRule { - QRegExp pattern; + QRegularExpression pattern; QTextCharFormat format; }; QVector highlightingRules; - QRegExp commentStartExpression; - QRegExp commentEndExpression; + QRegularExpression commentStartRegularExpression; + QRegularExpression commentEndRegularExpression; QTextCharFormat keywordFormat; QTextCharFormat regFormat; diff --git a/src/common/MdHighlighter.cpp b/src/common/MdHighlighter.cpp index 4ae0d839..9d6bacc4 100644 --- a/src/common/MdHighlighter.cpp +++ b/src/common/MdHighlighter.cpp @@ -16,14 +16,14 @@ MdHighlighter::MdHighlighter(QTextDocument *parent) << "\\_\\_([^\\\\]+)\\_\\_"; for (const QString &pattern : keywordPatterns) { - rule.pattern = QRegExp(pattern); + rule.pattern.setPattern(pattern); rule.format = keywordFormat; highlightingRules.append(rule); } singleLineCommentFormat.setFontWeight(QFont::Bold); singleLineCommentFormat.setForeground(Qt::darkGreen); - rule.pattern = QRegExp(";[^\n]*"); + rule.pattern.setPattern(";[^\n]*"); rule.format = singleLineCommentFormat; highlightingRules.append(rule); } @@ -31,12 +31,12 @@ MdHighlighter::MdHighlighter(QTextDocument *parent) void MdHighlighter::highlightBlock(const QString &text) { for (const HighlightingRule &rule : highlightingRules) { - QRegExp expression(rule.pattern); - int index = expression.indexIn(text); + QRegularExpression expression(rule.pattern); + int index = expression.match(text).capturedStart(); while (index >= 0) { - int length = expression.matchedLength(); + int length = expression.match(text).capturedLength(); setFormat(index, length, rule.format); - index = expression.indexIn(text, index + length); + index = expression.match(text.mid(index + length)).capturedStart(); } } setCurrentBlockState(0); diff --git a/src/common/MdHighlighter.h b/src/common/MdHighlighter.h index 57817191..71fcf424 100644 --- a/src/common/MdHighlighter.h +++ b/src/common/MdHighlighter.h @@ -5,6 +5,7 @@ #include #include +#include class QTextDocument; @@ -20,14 +21,11 @@ protected: private: struct HighlightingRule { - QRegExp pattern; + QRegularExpression pattern; QTextCharFormat format; }; QVector highlightingRules; - QRegExp commentStartExpression; - QRegExp commentEndExpression; - QTextCharFormat keywordFormat; QTextCharFormat classFormat; QTextCharFormat singleLineCommentFormat; diff --git a/src/core/Cutter.cpp b/src/core/Cutter.cpp index 885979c1..d625ed3f 100644 --- a/src/core/Cutter.cpp +++ b/src/core/Cutter.cpp @@ -293,7 +293,7 @@ bool CutterCore::sdbSet(QString path, QString key, QString val) QString CutterCore::sanitizeStringForCommand(QString s) { - static const QRegExp regexp(";|@"); + static const QRegularExpression regexp(";|@"); return s.replace(regexp, QStringLiteral("_")); } @@ -955,7 +955,7 @@ QString CutterCore::createFunctionAt(RVA addr) QString CutterCore::createFunctionAt(RVA addr, QString name) { - static const QRegExp regExp("[^a-zA-Z0-9_]"); + static const QRegularExpression regExp("[^a-zA-Z0-9_]"); name.remove(regExp); QString command = "af " + name + " " + RAddressString(addr); QString ret = cmd(command); @@ -2727,9 +2727,12 @@ void CutterCore::deleteProject(const QString &name) bool CutterCore::isProjectNameValid(const QString &name) { - // see is_valid_project_name() in libr/core/project.c - static const QRegExp regexp(R"(^[a-zA-Z0-9\\\._:-]{1,}$)"); - return regexp.exactMatch(name) && !name.endsWith(".zip") ; + // see is_valid_project_name() in libr/core/project. + + QString pattern(R"(^[a-zA-Z0-9\\\._:-]{1,}$)"); + // The below construct mimics the behaviour of QRegexP::exactMatch(), which was here before + static const QRegularExpression regexp("\\A(?:" + pattern + ")\\z"); + return regexp.match(name).hasMatch() && !name.endsWith(".zip") ; } QList CutterCore::disassembleLines(RVA offset, int lines) diff --git a/src/core/MainWindow.cpp b/src/core/MainWindow.cpp index d80e509a..d383e737 100644 --- a/src/core/MainWindow.cpp +++ b/src/core/MainWindow.cpp @@ -1126,7 +1126,7 @@ void MainWindow::resetDockWidgetList() for (auto it : dockWidgets) { if (isLeft.contains(it->metaObject()->className())) { toClose.append(it); - } else if (QRegExp("\\w+ \\d+").exactMatch(it->objectName())) { + } else if (QRegularExpression("\\A(?:\\w+ \\d+)\\z").match(it->objectName()).hasMatch()) { isLeft.append(it->metaObject()->className()); } } diff --git a/src/dialogs/HexdumpRangeDialog.cpp b/src/dialogs/HexdumpRangeDialog.cpp index 008b0be2..4e8f0b8e 100644 --- a/src/dialogs/HexdumpRangeDialog.cpp +++ b/src/dialogs/HexdumpRangeDialog.cpp @@ -1,7 +1,7 @@ #include "HexdumpRangeDialog.h" #include "ui_HexdumpRangeDialog.h" -#include +#include #include #include #include "core/Cutter.h" @@ -12,7 +12,7 @@ HexdumpRangeDialog::HexdumpRangeDialog(QWidget *parent, bool allowEmpty) : allowEmpty(allowEmpty) { ui->setupUi(this); - QRegExpValidator *v = new QRegExpValidator(QRegExp("(?:0[xX])?[0-9a-fA-F]+"), this); + QRegularExpressionValidator *v = new QRegularExpressionValidator(QRegularExpression("(?:0[xX])?[0-9a-fA-F]+"), this); ui->lengthLineEdit->setValidator(v); ui->startAddressLineEdit->setValidator(v); ui->endAddressLineEdit->setValidator(v); diff --git a/src/dialogs/preferences/AppearanceOptionsWidget.cpp b/src/dialogs/preferences/AppearanceOptionsWidget.cpp index 0391ca50..31762640 100644 --- a/src/dialogs/preferences/AppearanceOptionsWidget.cpp +++ b/src/dialogs/preferences/AppearanceOptionsWidget.cpp @@ -271,7 +271,7 @@ QIcon AppearanceOptionsWidget::getIconFromSvg(const QString& fileName, const QCo return QIcon(); } QString data = file.readAll(); - data.replace(QRegExp(QString("#%1").arg(before.isValid() ? before.name().remove(0, 1) : "[0-9a-fA-F]{6}")), + data.replace(QRegularExpression(QString("#%1").arg(before.isValid() ? before.name().remove(0, 1) : "[0-9a-fA-F]{6}")), QString("%1").arg(after.name())); QSvgRenderer svgRenderer(data.toUtf8()); diff --git a/src/widgets/ColorPicker.cpp b/src/widgets/ColorPicker.cpp index eab813b5..25df2e3a 100644 --- a/src/widgets/ColorPicker.cpp +++ b/src/widgets/ColorPicker.cpp @@ -225,7 +225,8 @@ void ColorPicker::setColor(const QColor& color) void ColorPicker::colorChannelChanged() { QString txt = ui->hexLineEdit->text(); - if (!QRegExp("#[0-9a-fA-F]{6}").exactMatch(txt)) { + // Regex pattern below mimics the behaviour of former RegExp::exactMatch() + if (!QRegularExpression("\\A(?:#[0-9a-fA-F]{6})\\z").match(txt).hasMatch()) { return; } QColor hexColor = txt; diff --git a/src/widgets/ColorThemeListView.cpp b/src/widgets/ColorThemeListView.cpp index c04480a5..d9ef0e2f 100644 --- a/src/widgets/ColorThemeListView.cpp +++ b/src/widgets/ColorThemeListView.cpp @@ -192,7 +192,7 @@ QPixmap ColorOptionDelegate::getPixmapFromSvg(const QString& fileName, const QCo return QPixmap(); } QString data = file.readAll(); - data.replace(QRegExp("#[0-9a-fA-F]{6}"), QString("%1").arg(after.name())); + data.replace(QRegularExpression("#[0-9a-fA-F]{6}"), QString("%1").arg(after.name())); QSvgRenderer svgRenderer(data.toUtf8()); QPixmap pix(QSize(qApp->fontMetrics().height(), qApp->fontMetrics().height()));