mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-20 11:56:12 +00:00
Replacing all QRegExp with QRegularExpression (#1820)
* Replacing all QRegExp with QRegularExpression
This commit is contained in:
parent
9d2a8d9deb
commit
b81eed7f22
@ -5,6 +5,7 @@
|
|||||||
#include <QColor>
|
#include <QColor>
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
|
#include <QRegularExpression>
|
||||||
|
|
||||||
#include "common/Configuration.h"
|
#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)
|
QString options = (Core()->cmdj("ecj").object().keys() << cutterSpecificOptions)
|
||||||
.join('|')
|
.join('|')
|
||||||
.replace(".", "\\.");
|
.replace(".", "\\.");
|
||||||
QRegExp regexp = QRegExp(QString("((ec\\s+(%1)\\s+(((rgb:|#)[0-9a-fA-F]{3,8})|(%2))))\\s*")
|
|
||||||
.arg(options)
|
QString pattern = QString("((ec\\s+(%1)\\s+(((rgb:|#)[0-9a-fA-F]{3,8})|(%2))))\\s*").arg(options).arg(colors);
|
||||||
.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)) {
|
for (auto &line : QString(f.readAll()).split('\n', QString::SkipEmptyParts)) {
|
||||||
line.replace("#~", "ec ");
|
line.replace("#~", "ec ");
|
||||||
if (!line.isEmpty() && !regexp.exactMatch(line)) {
|
if (!line.isEmpty() && !regexp.match(line).hasMatch()) {
|
||||||
*ok = true;
|
*ok = true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -8,42 +8,43 @@ AsciiHighlighter::AsciiHighlighter(QTextDocument *parent)
|
|||||||
HighlightingRule rule;
|
HighlightingRule rule;
|
||||||
|
|
||||||
asciiFormat.setForeground(QColor(65, 131, 215));
|
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;
|
rule.format = asciiFormat;
|
||||||
highlightingRules.append(rule);
|
highlightingRules.append(rule);
|
||||||
|
|
||||||
commentStartExpression = QRegExp("/\\*");
|
commentStartRegularExpression.setPattern("/\\*");
|
||||||
commentEndExpression = QRegExp("\\*/");
|
commentEndRegularExpression.setPattern("\\*/");
|
||||||
}
|
}
|
||||||
|
|
||||||
void AsciiHighlighter::highlightBlock(const QString &text)
|
void AsciiHighlighter::highlightBlock(const QString &text)
|
||||||
{
|
{
|
||||||
for (const HighlightingRule &rule : highlightingRules) {
|
for (const HighlightingRule &rule : highlightingRules) {
|
||||||
QRegExp expression(rule.pattern);
|
QRegularExpression expression(rule.pattern);
|
||||||
int index = expression.indexIn(text);
|
int index = expression.match(text).capturedStart();
|
||||||
while (index >= 0) {
|
while (index >= 0) {
|
||||||
int length = expression.matchedLength();
|
int length = expression.match(text).capturedLength();
|
||||||
setFormat(index, length, rule.format);
|
setFormat(index, length, rule.format);
|
||||||
index = expression.indexIn(text, index + length);
|
index = expression.match(text.mid(index + length)).capturedStart();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setCurrentBlockState(0);
|
setCurrentBlockState(0);
|
||||||
|
|
||||||
int startIndex = 0;
|
int startIndex = 0;
|
||||||
if (previousBlockState() != 1)
|
if (previousBlockState() != 1)
|
||||||
startIndex = commentStartExpression.indexIn(text);
|
startIndex = QRegularExpression(commentStartRegularExpression).match(text).capturedStart();
|
||||||
|
|
||||||
while (startIndex >= 0) {
|
while (startIndex >= 0) {
|
||||||
int endIndex = commentEndExpression.indexIn(text, startIndex);
|
QRegularExpressionMatch commentEndMatch = QRegularExpression(commentEndRegularExpression).match(text.mid(startIndex));
|
||||||
|
int endIndex = commentEndMatch.capturedStart();
|
||||||
int commentLength;
|
int commentLength;
|
||||||
if (endIndex == -1) {
|
if (endIndex == -1) {
|
||||||
setCurrentBlockState(1);
|
setCurrentBlockState(1);
|
||||||
commentLength = text.length() - startIndex;
|
commentLength = text.length() - startIndex;
|
||||||
} else {
|
} else {
|
||||||
commentLength = endIndex - startIndex
|
commentLength = endIndex - startIndex
|
||||||
+ commentEndExpression.matchedLength();
|
+ commentEndMatch.capturedLength();
|
||||||
}
|
}
|
||||||
setFormat(startIndex, commentLength, multiLineCommentFormat);
|
setFormat(startIndex, commentLength, multiLineCommentFormat);
|
||||||
startIndex = commentStartExpression.indexIn(text, startIndex + commentLength);
|
startIndex = QRegularExpression(commentStartRegularExpression).match(text.mid(startIndex + commentLength)).capturedStart();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
#include <QTextCharFormat>
|
#include <QTextCharFormat>
|
||||||
|
#include <QRegularExpression>
|
||||||
|
|
||||||
class QTextDocument;
|
class QTextDocument;
|
||||||
|
|
||||||
@ -20,13 +21,13 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
struct HighlightingRule {
|
struct HighlightingRule {
|
||||||
QRegExp pattern;
|
QRegularExpression pattern;
|
||||||
QTextCharFormat format;
|
QTextCharFormat format;
|
||||||
};
|
};
|
||||||
QVector<HighlightingRule> highlightingRules;
|
QVector<HighlightingRule> highlightingRules;
|
||||||
|
|
||||||
QRegExp commentStartExpression;
|
QRegularExpression commentStartRegularExpression;
|
||||||
QRegExp commentEndExpression;
|
QRegularExpression commentEndRegularExpression;
|
||||||
|
|
||||||
QTextCharFormat keywordFormat;
|
QTextCharFormat keywordFormat;
|
||||||
QTextCharFormat classFormat;
|
QTextCharFormat classFormat;
|
||||||
|
@ -27,51 +27,51 @@ HexHighlighter::HexHighlighter(QTextDocument *parent)
|
|||||||
<< "\\b75\\b" << "\\b76\\b" << "\\b77\\b" << "\\b78\\b" << "\\b79\\b" << "\\b7a\\b" << "\\b7b\\b"
|
<< "\\b75\\b" << "\\b76\\b" << "\\b77\\b" << "\\b78\\b" << "\\b79\\b" << "\\b7a\\b" << "\\b7b\\b"
|
||||||
<< "\\b7c\\b" << "\\b7d\\b" << "\\b7e\\b" << "\\b7f\\b";
|
<< "\\b7c\\b" << "\\b7d\\b" << "\\b7e\\b" << "\\b7f\\b";
|
||||||
for (const QString &pattern : keywordPatterns) {
|
for (const QString &pattern : keywordPatterns) {
|
||||||
rule.pattern = QRegExp(pattern);
|
rule.pattern.setPattern(pattern);
|
||||||
rule.pattern.setCaseSensitivity(Qt::CaseInsensitive);
|
rule.pattern.setPatternOptions(QRegularExpression::CaseInsensitiveOption);
|
||||||
rule.format = keywordFormat;
|
rule.format = keywordFormat;
|
||||||
highlightingRules.append(rule);
|
highlightingRules.append(rule);
|
||||||
}
|
}
|
||||||
|
|
||||||
singleLineCommentFormat.setFontWeight(QFont::Bold);
|
singleLineCommentFormat.setFontWeight(QFont::Bold);
|
||||||
singleLineCommentFormat.setForeground(Qt::darkGreen);
|
singleLineCommentFormat.setForeground(Qt::darkGreen);
|
||||||
rule.pattern = QRegExp(";[^\n]*");
|
rule.pattern.setPattern(";[^\n]*");
|
||||||
rule.format = singleLineCommentFormat;
|
rule.format = singleLineCommentFormat;
|
||||||
highlightingRules.append(rule);
|
highlightingRules.append(rule);
|
||||||
|
|
||||||
commentStartExpression = QRegExp("/\\*");
|
commentStartRegularExpression.setPattern("/\\*");
|
||||||
commentEndExpression = QRegExp("\\*/");
|
commentEndRegularExpression.setPattern("\\*/");
|
||||||
}
|
}
|
||||||
|
|
||||||
void HexHighlighter::highlightBlock(const QString &text)
|
void HexHighlighter::highlightBlock(const QString &text)
|
||||||
{
|
{
|
||||||
for (const HighlightingRule &rule : highlightingRules) {
|
for (const HighlightingRule &rule : highlightingRules) {
|
||||||
QRegExp expression(rule.pattern);
|
QRegularExpression expression(rule.pattern);
|
||||||
int index = expression.indexIn(text);
|
int index = expression.match(text).capturedStart();
|
||||||
while (index >= 0) {
|
while (index >= 0) {
|
||||||
int length = expression.matchedLength();
|
int length = expression.match(text).capturedLength();
|
||||||
setFormat(index, length, rule.format);
|
setFormat(index, length, rule.format);
|
||||||
index = expression.indexIn(text, index + length);
|
index = expression.match(text.mid(index + length)).capturedStart();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setCurrentBlockState(0);
|
setCurrentBlockState(0);
|
||||||
|
|
||||||
int startIndex = 0;
|
int startIndex = 0;
|
||||||
if (previousBlockState() != 1)
|
if (previousBlockState() != 1)
|
||||||
startIndex = commentStartExpression.indexIn(text);
|
startIndex = QRegularExpression(commentStartRegularExpression).match(text).capturedStart();
|
||||||
|
|
||||||
while (startIndex >= 0) {
|
while (startIndex >= 0) {
|
||||||
int endIndex = commentEndExpression.indexIn(text, startIndex);
|
QRegularExpressionMatch commentEndMatch = QRegularExpression(commentEndRegularExpression).match(text.mid(startIndex));
|
||||||
|
int endIndex = commentEndMatch.capturedStart();
|
||||||
int commentLength;
|
int commentLength;
|
||||||
if (endIndex == -1) {
|
if (endIndex == -1) {
|
||||||
setCurrentBlockState(1);
|
setCurrentBlockState(1);
|
||||||
commentLength = text.length() - startIndex;
|
commentLength = text.length() - startIndex;
|
||||||
} else {
|
} else {
|
||||||
commentLength = endIndex - startIndex
|
commentLength = endIndex - startIndex
|
||||||
+ commentEndExpression.matchedLength();
|
+ commentEndMatch.capturedLength();
|
||||||
}
|
}
|
||||||
setFormat(startIndex, commentLength, multiLineCommentFormat);
|
setFormat(startIndex, commentLength, multiLineCommentFormat);
|
||||||
startIndex = commentStartExpression.indexIn(text, startIndex + commentLength);
|
startIndex = QRegularExpression(commentStartRegularExpression).match(text.mid(startIndex + commentLength)).capturedStart();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
#include <QTextCharFormat>
|
#include <QTextCharFormat>
|
||||||
|
#include <QRegularExpression>
|
||||||
|
|
||||||
class QTextDocument;
|
class QTextDocument;
|
||||||
|
|
||||||
@ -20,13 +21,13 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
struct HighlightingRule {
|
struct HighlightingRule {
|
||||||
QRegExp pattern;
|
QRegularExpression pattern;
|
||||||
QTextCharFormat format;
|
QTextCharFormat format;
|
||||||
};
|
};
|
||||||
QVector<HighlightingRule> highlightingRules;
|
QVector<HighlightingRule> highlightingRules;
|
||||||
|
|
||||||
QRegExp commentStartExpression;
|
QRegularExpression commentStartRegularExpression;
|
||||||
QRegExp commentEndExpression;
|
QRegularExpression commentEndRegularExpression;
|
||||||
|
|
||||||
QTextCharFormat keywordFormat;
|
QTextCharFormat keywordFormat;
|
||||||
QTextCharFormat classFormat;
|
QTextCharFormat classFormat;
|
||||||
|
@ -13,8 +13,8 @@ Highlighter::Highlighter(QTextDocument *parent) :
|
|||||||
keywordFormat.setForeground(QColor(65, 131, 215));
|
keywordFormat.setForeground(QColor(65, 131, 215));
|
||||||
|
|
||||||
for (const QString &pattern : this->core->opcodes) {
|
for (const QString &pattern : this->core->opcodes) {
|
||||||
rule.pattern = QRegExp("\\b" + pattern + "\\b");
|
rule.pattern.setPattern("\\b" + pattern + "\\b");
|
||||||
rule.pattern.setCaseSensitivity(Qt::CaseInsensitive);
|
rule.pattern.setPatternOptions(QRegularExpression::CaseInsensitiveOption);
|
||||||
rule.format = keywordFormat;
|
rule.format = keywordFormat;
|
||||||
highlightingRules.append(rule);
|
highlightingRules.append(rule);
|
||||||
}
|
}
|
||||||
@ -22,8 +22,8 @@ Highlighter::Highlighter(QTextDocument *parent) :
|
|||||||
regFormat.setForeground(QColor(236, 100, 75));
|
regFormat.setForeground(QColor(236, 100, 75));
|
||||||
|
|
||||||
for (const QString &pattern : this->core->regs) {
|
for (const QString &pattern : this->core->regs) {
|
||||||
rule.pattern = QRegExp("\\b" + pattern + "\\b");
|
rule.pattern.setPattern("\\b" + pattern + "\\b");
|
||||||
rule.pattern.setCaseSensitivity(Qt::CaseInsensitive);
|
rule.pattern.setPatternOptions(QRegularExpression::CaseInsensitiveOption);
|
||||||
rule.format = regFormat;
|
rule.format = regFormat;
|
||||||
highlightingRules.append(rule);
|
highlightingRules.append(rule);
|
||||||
}
|
}
|
||||||
@ -31,42 +31,43 @@ Highlighter::Highlighter(QTextDocument *parent) :
|
|||||||
|
|
||||||
singleLineCommentFormat.setFontWeight(QFont::Bold);
|
singleLineCommentFormat.setFontWeight(QFont::Bold);
|
||||||
singleLineCommentFormat.setForeground(QColor(63, 195, 128));
|
singleLineCommentFormat.setForeground(QColor(63, 195, 128));
|
||||||
rule.pattern = QRegExp(";[^\n]*");
|
rule.pattern.setPattern(";[^\n]*");
|
||||||
rule.format = singleLineCommentFormat;
|
rule.format = singleLineCommentFormat;
|
||||||
highlightingRules.append(rule);
|
highlightingRules.append(rule);
|
||||||
|
|
||||||
commentStartExpression = QRegExp("/\\*");
|
commentStartRegularExpression.setPattern("/\\*");
|
||||||
commentEndExpression = QRegExp("\\*/");
|
commentEndRegularExpression.setPattern("\\*/");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Highlighter::highlightBlock(const QString &text)
|
void Highlighter::highlightBlock(const QString &text)
|
||||||
{
|
{
|
||||||
for (const HighlightingRule &rule : highlightingRules) {
|
for (const HighlightingRule &rule : highlightingRules) {
|
||||||
QRegExp expression(rule.pattern);
|
QRegularExpression expression(rule.pattern);
|
||||||
int index = expression.indexIn(text);
|
int index = expression.match(text).capturedStart();
|
||||||
while (index >= 0) {
|
while (index >= 0) {
|
||||||
int length = expression.matchedLength();
|
int length = expression.match(text).capturedLength();
|
||||||
setFormat(index, length, rule.format);
|
setFormat(index, length, rule.format);
|
||||||
index = expression.indexIn(text, index + length);
|
index = expression.match(text.mid(index + length)).capturedStart();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setCurrentBlockState(0);
|
setCurrentBlockState(0);
|
||||||
|
|
||||||
int startIndex = 0;
|
int startIndex = 0;
|
||||||
if (previousBlockState() != 1)
|
if (previousBlockState() != 1)
|
||||||
startIndex = commentStartExpression.indexIn(text);
|
startIndex = QRegularExpression(commentStartRegularExpression).match(text).capturedStart();
|
||||||
|
|
||||||
while (startIndex >= 0) {
|
while (startIndex >= 0) {
|
||||||
int endIndex = commentEndExpression.indexIn(text, startIndex);
|
QRegularExpressionMatch commentEndMatch = QRegularExpression(commentEndRegularExpression).match(text.mid(startIndex));
|
||||||
|
int endIndex = commentEndMatch.capturedStart();
|
||||||
int commentLength;
|
int commentLength;
|
||||||
if (endIndex == -1) {
|
if (endIndex == -1) {
|
||||||
setCurrentBlockState(1);
|
setCurrentBlockState(1);
|
||||||
commentLength = text.length() - startIndex;
|
commentLength = text.length() - startIndex;
|
||||||
} else {
|
} else {
|
||||||
commentLength = endIndex - startIndex
|
commentLength = endIndex - startIndex
|
||||||
+ commentEndExpression.matchedLength();
|
+ commentEndMatch.capturedLength();
|
||||||
}
|
}
|
||||||
setFormat(startIndex, commentLength, multiLineCommentFormat);
|
setFormat(startIndex, commentLength, multiLineCommentFormat);
|
||||||
startIndex = commentStartExpression.indexIn(text, startIndex + commentLength);
|
startIndex = QRegularExpression(commentStartRegularExpression).match(text.mid(startIndex + commentLength)).capturedStart();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include <QSyntaxHighlighter>
|
#include <QSyntaxHighlighter>
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
#include <QTextCharFormat>
|
#include <QTextCharFormat>
|
||||||
|
#include <QRegularExpression>
|
||||||
|
|
||||||
class QTextDocument;
|
class QTextDocument;
|
||||||
class MainWindow;
|
class MainWindow;
|
||||||
@ -24,13 +25,13 @@ private:
|
|||||||
CutterCore *core;
|
CutterCore *core;
|
||||||
|
|
||||||
struct HighlightingRule {
|
struct HighlightingRule {
|
||||||
QRegExp pattern;
|
QRegularExpression pattern;
|
||||||
QTextCharFormat format;
|
QTextCharFormat format;
|
||||||
};
|
};
|
||||||
QVector<HighlightingRule> highlightingRules;
|
QVector<HighlightingRule> highlightingRules;
|
||||||
|
|
||||||
QRegExp commentStartExpression;
|
QRegularExpression commentStartRegularExpression;
|
||||||
QRegExp commentEndExpression;
|
QRegularExpression commentEndRegularExpression;
|
||||||
|
|
||||||
QTextCharFormat keywordFormat;
|
QTextCharFormat keywordFormat;
|
||||||
QTextCharFormat regFormat;
|
QTextCharFormat regFormat;
|
||||||
|
@ -16,14 +16,14 @@ MdHighlighter::MdHighlighter(QTextDocument *parent)
|
|||||||
<< "\\_\\_([^\\\\]+)\\_\\_";
|
<< "\\_\\_([^\\\\]+)\\_\\_";
|
||||||
|
|
||||||
for (const QString &pattern : keywordPatterns) {
|
for (const QString &pattern : keywordPatterns) {
|
||||||
rule.pattern = QRegExp(pattern);
|
rule.pattern.setPattern(pattern);
|
||||||
rule.format = keywordFormat;
|
rule.format = keywordFormat;
|
||||||
highlightingRules.append(rule);
|
highlightingRules.append(rule);
|
||||||
}
|
}
|
||||||
|
|
||||||
singleLineCommentFormat.setFontWeight(QFont::Bold);
|
singleLineCommentFormat.setFontWeight(QFont::Bold);
|
||||||
singleLineCommentFormat.setForeground(Qt::darkGreen);
|
singleLineCommentFormat.setForeground(Qt::darkGreen);
|
||||||
rule.pattern = QRegExp(";[^\n]*");
|
rule.pattern.setPattern(";[^\n]*");
|
||||||
rule.format = singleLineCommentFormat;
|
rule.format = singleLineCommentFormat;
|
||||||
highlightingRules.append(rule);
|
highlightingRules.append(rule);
|
||||||
}
|
}
|
||||||
@ -31,12 +31,12 @@ MdHighlighter::MdHighlighter(QTextDocument *parent)
|
|||||||
void MdHighlighter::highlightBlock(const QString &text)
|
void MdHighlighter::highlightBlock(const QString &text)
|
||||||
{
|
{
|
||||||
for (const HighlightingRule &rule : highlightingRules) {
|
for (const HighlightingRule &rule : highlightingRules) {
|
||||||
QRegExp expression(rule.pattern);
|
QRegularExpression expression(rule.pattern);
|
||||||
int index = expression.indexIn(text);
|
int index = expression.match(text).capturedStart();
|
||||||
while (index >= 0) {
|
while (index >= 0) {
|
||||||
int length = expression.matchedLength();
|
int length = expression.match(text).capturedLength();
|
||||||
setFormat(index, length, rule.format);
|
setFormat(index, length, rule.format);
|
||||||
index = expression.indexIn(text, index + length);
|
index = expression.match(text.mid(index + length)).capturedStart();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setCurrentBlockState(0);
|
setCurrentBlockState(0);
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
#include <QTextCharFormat>
|
#include <QTextCharFormat>
|
||||||
|
#include <QRegularExpression>
|
||||||
|
|
||||||
class QTextDocument;
|
class QTextDocument;
|
||||||
|
|
||||||
@ -20,14 +21,11 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
struct HighlightingRule {
|
struct HighlightingRule {
|
||||||
QRegExp pattern;
|
QRegularExpression pattern;
|
||||||
QTextCharFormat format;
|
QTextCharFormat format;
|
||||||
};
|
};
|
||||||
QVector<HighlightingRule> highlightingRules;
|
QVector<HighlightingRule> highlightingRules;
|
||||||
|
|
||||||
QRegExp commentStartExpression;
|
|
||||||
QRegExp commentEndExpression;
|
|
||||||
|
|
||||||
QTextCharFormat keywordFormat;
|
QTextCharFormat keywordFormat;
|
||||||
QTextCharFormat classFormat;
|
QTextCharFormat classFormat;
|
||||||
QTextCharFormat singleLineCommentFormat;
|
QTextCharFormat singleLineCommentFormat;
|
||||||
|
@ -293,7 +293,7 @@ bool CutterCore::sdbSet(QString path, QString key, QString val)
|
|||||||
|
|
||||||
QString CutterCore::sanitizeStringForCommand(QString s)
|
QString CutterCore::sanitizeStringForCommand(QString s)
|
||||||
{
|
{
|
||||||
static const QRegExp regexp(";|@");
|
static const QRegularExpression regexp(";|@");
|
||||||
return s.replace(regexp, QStringLiteral("_"));
|
return s.replace(regexp, QStringLiteral("_"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -955,7 +955,7 @@ QString CutterCore::createFunctionAt(RVA addr)
|
|||||||
|
|
||||||
QString CutterCore::createFunctionAt(RVA addr, QString name)
|
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);
|
name.remove(regExp);
|
||||||
QString command = "af " + name + " " + RAddressString(addr);
|
QString command = "af " + name + " " + RAddressString(addr);
|
||||||
QString ret = cmd(command);
|
QString ret = cmd(command);
|
||||||
@ -2727,9 +2727,12 @@ void CutterCore::deleteProject(const QString &name)
|
|||||||
|
|
||||||
bool CutterCore::isProjectNameValid(const QString &name)
|
bool CutterCore::isProjectNameValid(const QString &name)
|
||||||
{
|
{
|
||||||
// see is_valid_project_name() in libr/core/project.c
|
// see is_valid_project_name() in libr/core/project.
|
||||||
static const QRegExp regexp(R"(^[a-zA-Z0-9\\\._:-]{1,}$)");
|
|
||||||
return regexp.exactMatch(name) && !name.endsWith(".zip") ;
|
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<DisassemblyLine> CutterCore::disassembleLines(RVA offset, int lines)
|
QList<DisassemblyLine> CutterCore::disassembleLines(RVA offset, int lines)
|
||||||
|
@ -1126,7 +1126,7 @@ void MainWindow::resetDockWidgetList()
|
|||||||
for (auto it : dockWidgets) {
|
for (auto it : dockWidgets) {
|
||||||
if (isLeft.contains(it->metaObject()->className())) {
|
if (isLeft.contains(it->metaObject()->className())) {
|
||||||
toClose.append(it);
|
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());
|
isLeft.append(it->metaObject()->className());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#include "HexdumpRangeDialog.h"
|
#include "HexdumpRangeDialog.h"
|
||||||
#include "ui_HexdumpRangeDialog.h"
|
#include "ui_HexdumpRangeDialog.h"
|
||||||
|
|
||||||
#include <QRegExpValidator>
|
#include <QRegularExpressionValidator>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include "core/Cutter.h"
|
#include "core/Cutter.h"
|
||||||
@ -12,7 +12,7 @@ HexdumpRangeDialog::HexdumpRangeDialog(QWidget *parent, bool allowEmpty) :
|
|||||||
allowEmpty(allowEmpty)
|
allowEmpty(allowEmpty)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
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->lengthLineEdit->setValidator(v);
|
||||||
ui->startAddressLineEdit->setValidator(v);
|
ui->startAddressLineEdit->setValidator(v);
|
||||||
ui->endAddressLineEdit->setValidator(v);
|
ui->endAddressLineEdit->setValidator(v);
|
||||||
|
@ -271,7 +271,7 @@ QIcon AppearanceOptionsWidget::getIconFromSvg(const QString& fileName, const QCo
|
|||||||
return QIcon();
|
return QIcon();
|
||||||
}
|
}
|
||||||
QString data = file.readAll();
|
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()));
|
QString("%1").arg(after.name()));
|
||||||
|
|
||||||
QSvgRenderer svgRenderer(data.toUtf8());
|
QSvgRenderer svgRenderer(data.toUtf8());
|
||||||
|
@ -225,7 +225,8 @@ void ColorPicker::setColor(const QColor& color)
|
|||||||
void ColorPicker::colorChannelChanged()
|
void ColorPicker::colorChannelChanged()
|
||||||
{
|
{
|
||||||
QString txt = ui->hexLineEdit->text();
|
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;
|
return;
|
||||||
}
|
}
|
||||||
QColor hexColor = txt;
|
QColor hexColor = txt;
|
||||||
|
@ -192,7 +192,7 @@ QPixmap ColorOptionDelegate::getPixmapFromSvg(const QString& fileName, const QCo
|
|||||||
return QPixmap();
|
return QPixmap();
|
||||||
}
|
}
|
||||||
QString data = file.readAll();
|
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());
|
QSvgRenderer svgRenderer(data.toUtf8());
|
||||||
QPixmap pix(QSize(qApp->fontMetrics().height(), qApp->fontMetrics().height()));
|
QPixmap pix(QSize(qApp->fontMetrics().height(), qApp->fontMetrics().height()));
|
||||||
|
Loading…
Reference in New Issue
Block a user