From 61f2344a1a471bb671e5c6caae747a9579e33616 Mon Sep 17 00:00:00 2001 From: Evan Teran Date: Wed, 27 Mar 2024 10:19:58 -0400 Subject: [PATCH] using QRegularExpression over QRegExp where easy to do so --- plugins/Assembler/DialogAssembler.cpp | 8 +++++--- plugins/ODbgRegisterView/DialogEditSimdRegister.cpp | 11 ++++++----- plugins/ODbgRegisterView/DialogEditSimdRegister.h | 10 +++++----- plugins/ODbgRegisterView/GprEdit.cpp | 12 ++++++------ .../arch/x86-generic/DialogEditFPU.cpp | 5 +++-- src/DialogInputValue.cpp | 6 +++--- src/FloatX.cpp | 8 ++++---- src/widgets/QDisassemblyView.cpp | 2 +- 8 files changed, 33 insertions(+), 29 deletions(-) diff --git a/plugins/Assembler/DialogAssembler.cpp b/plugins/Assembler/DialogAssembler.cpp index 78fd62af3..8e4765f3a 100644 --- a/plugins/Assembler/DialogAssembler.cpp +++ b/plugins/Assembler/DialogAssembler.cpp @@ -29,7 +29,7 @@ along with this program. If not, see . #include #include #include -#include +#include #include #include #include @@ -104,12 +104,14 @@ QString fixup_syntax(QString insn) { "tbyte", "xmmword", "ymmword", - "zmmword"}; + "zmmword", + }; for (const QString &size : sizes) { const QString replacement = opSizes.attribute(size); if (!replacement.isEmpty()) { - insn.replace(QRegExp("\\b" + size + "\\b"), replacement); + const QRegularExpression re("\\b" + size + "\\b"); + insn.replace(re, replacement); } } diff --git a/plugins/ODbgRegisterView/DialogEditSimdRegister.cpp b/plugins/ODbgRegisterView/DialogEditSimdRegister.cpp index 4808776fe..56d172f74 100644 --- a/plugins/ODbgRegisterView/DialogEditSimdRegister.cpp +++ b/plugins/ODbgRegisterView/DialogEditSimdRegister.cpp @@ -31,7 +31,8 @@ along with this program. If not, see . #include #include #include -#include +#include +#include #include #include #include @@ -56,10 +57,10 @@ void DialogEditSimdRegister::setupEntries(const QString &label, std::array bytes_; std::array columnLabels_; - QRegExpValidator *byteHexValidator_; - QRegExpValidator *wordHexValidator_; - QRegExpValidator *dwordHexValidator_; - QRegExpValidator *qwordHexValidator_; + QRegularExpressionValidator *byteHexValidator_; + QRegularExpressionValidator *wordHexValidator_; + QRegularExpressionValidator *dwordHexValidator_; + QRegularExpressionValidator *qwordHexValidator_; QLongValidator *byteSignedValidator_; QLongValidator *wordSignedValidator_; diff --git a/plugins/ODbgRegisterView/GprEdit.cpp b/plugins/ODbgRegisterView/GprEdit.cpp index c538ea962..6993e2e21 100644 --- a/plugins/ODbgRegisterView/GprEdit.cpp +++ b/plugins/ODbgRegisterView/GprEdit.cpp @@ -20,17 +20,17 @@ along with this program. If not, see . #include "QULongValidator.h" #include "util/Font.h" #include -#include +#include #include #include namespace ODbgRegisterView { namespace { -const QRegExpValidator byteHexValidator(QRegExp("[0-9a-fA-F]{0,2}")); -const QRegExpValidator wordHexValidator(QRegExp("[0-9a-fA-F]{0,4}")); -const QRegExpValidator dwordHexValidator(QRegExp("[0-9a-fA-F]{0,8}")); -const QRegExpValidator qwordHexValidator(QRegExp("[0-9a-fA-F]{0,16}")); +const QRegularExpressionValidator byteHexValidator(QRegularExpression("[0-9a-fA-F]{0,2}")); +const QRegularExpressionValidator wordHexValidator(QRegularExpression("[0-9a-fA-F]{0,4}")); +const QRegularExpressionValidator dwordHexValidator(QRegularExpression("[0-9a-fA-F]{0,8}")); +const QRegularExpressionValidator qwordHexValidator(QRegularExpression("[0-9a-fA-F]{0,16}")); const QLongValidator byteSignedValidator(INT8_MIN, INT8_MAX); const QLongValidator wordSignedValidator(INT16_MIN, INT16_MAX); const QLongValidator dwordSignedValidator(INT32_MIN, INT32_MAX); @@ -40,7 +40,7 @@ const QULongValidator wordUnsignedValidator(0, UINT16_MAX); const QULongValidator dwordUnsignedValidator(0, UINT32_MAX); const QULongValidator qwordUnsignedValidator(0, UINT64_MAX); -const std::map hexValidators = { +const std::map hexValidators = { {1, &byteHexValidator}, {2, &wordHexValidator}, {4, &dwordHexValidator}, diff --git a/plugins/ODbgRegisterView/arch/x86-generic/DialogEditFPU.cpp b/plugins/ODbgRegisterView/arch/x86-generic/DialogEditFPU.cpp index 2429057f7..fb8353ed8 100644 --- a/plugins/ODbgRegisterView/arch/x86-generic/DialogEditFPU.cpp +++ b/plugins/ODbgRegisterView/arch/x86-generic/DialogEditFPU.cpp @@ -25,7 +25,8 @@ along with this program. If not, see . #include #include #include -#include +#include +#include #include #include #include @@ -95,7 +96,7 @@ DialogEditFPU::DialogEditFPU(QWidget *parent, Qt::WindowFlags f) connect(floatEntry_, &Float80Edit::textEdited, this, &DialogEditFPU::onFloatEdited); connect(hexEntry_, &QLineEdit::textEdited, this, &DialogEditFPU::onHexEdited); - hexEntry_->setValidator(new QRegExpValidator(QRegExp("[0-9a-fA-F ]{,20}"), this)); + hexEntry_->setValidator(new QRegularExpressionValidator(QRegularExpression("[0-9a-fA-F ]{,20}"), this)); connect(floatEntry_, &Float80Edit::defocussed, this, &DialogEditFPU::updateFloatEntry); hexEntry_->installEventFilter(this); diff --git a/src/DialogInputValue.cpp b/src/DialogInputValue.cpp index 78595bd88..9ea283fa4 100644 --- a/src/DialogInputValue.cpp +++ b/src/DialogInputValue.cpp @@ -23,7 +23,7 @@ along with this program. If not, see . #include "edb.h" #include -#include +#include #include @@ -37,7 +37,7 @@ DialogInputValue::DialogInputValue(QWidget *parent, Qt::WindowFlags f) ui.setupUi(this); // Apply some defaults - ui.hexInput->setValidator(new QRegExpValidator(QRegExp("[A-Fa-f0-9]{0,16}"), this)); + ui.hexInput->setValidator(new QRegularExpressionValidator(QRegularExpression("[A-Fa-f0-9]{0,16}"), this)); ui.signedInput->setValidator(new QLongValidator(std::numeric_limits::min(), std::numeric_limits::max(), this)); ui.unsignedInput->setValidator(new QULongValidator(0, std::numeric_limits::max(), this)); } @@ -72,7 +72,7 @@ void DialogInputValue::setValue(Register ®) { mask_ = unsignedMax; valueLength_ = reg.bitSize() / 8; - ui.hexInput->setValidator(new QRegExpValidator(QRegExp(regex), this)); + ui.hexInput->setValidator(new QRegularExpressionValidator(QRegularExpression(regex), this)); ui.signedInput->setValidator(new QLongValidator(signedMin, signedMax, this)); ui.unsignedInput->setValidator(new QULongValidator(0, unsignedMax, this)); } diff --git a/src/FloatX.cpp b/src/FloatX.cpp index 2c2fbbedf..6f0bc1d7e 100644 --- a/src/FloatX.cpp +++ b/src/FloatX.cpp @@ -379,10 +379,10 @@ QValidator::State FloatXValidator::validate(QString &input, int &) const } // OK, so we failed to read it or it is unfinished. Let's check whether it's intermediate or invalid. - QRegExp basicFormat("[+-]?[0-9]*\\.?[0-9]*(e([+-]?[0-9]*)?)?"); - QRegExp specialFormat("[+-]?[sq]?nan|[+-]?inf", Qt::CaseInsensitive); - QRegExp hexfloatFormat("[+-]?0x[0-9a-f]*\\.?[0-9a-f]*(p([+-]?[0-9]*)?)?", Qt::CaseInsensitive); - QRegExp specialFormatUnfinished("[+-]?[sq]?(n(an?)?)?|[+-]?(i(nf?)?)?", Qt::CaseInsensitive); + static const QRegExp basicFormat("[+-]?[0-9]*\\.?[0-9]*(e([+-]?[0-9]*)?)?"); + static const QRegExp specialFormat("[+-]?[sq]?nan|[+-]?inf", Qt::CaseInsensitive); + static const QRegExp hexfloatFormat("[+-]?0x[0-9a-f]*\\.?[0-9a-f]*(p([+-]?[0-9]*)?)?", Qt::CaseInsensitive); + static const QRegExp specialFormatUnfinished("[+-]?[sq]?(n(an?)?)?|[+-]?(i(nf?)?)?", Qt::CaseInsensitive); if (hexfloatFormat.exactMatch(input)) { return QValidator::Intermediate; diff --git a/src/widgets/QDisassemblyView.cpp b/src/widgets/QDisassemblyView.cpp index 50ec49fd9..95365c92a 100644 --- a/src/widgets/QDisassemblyView.cpp +++ b/src/widgets/QDisassemblyView.cpp @@ -576,7 +576,7 @@ QString QDisassemblyView::instructionString(const edb::Instruction &inst) const const bool showSymbolicAddresses = edb::v1::config().show_symbolic_addresses; - static const QRegExp addrPattern(QLatin1String("#?0x[0-9a-fA-F]+")); + static const QRegularExpression addrPattern(QLatin1String("#?0x[0-9a-fA-F]+")); const edb::address_t target = oper->imm; const bool showLocalModuleNames = edb::v1::config().show_local_module_name_in_jump_targets;