Skip to content

Commit

Permalink
using QRegularExpression over QRegExp where easy to do so
Browse files Browse the repository at this point in the history
  • Loading branch information
eteran committed Mar 27, 2024
1 parent 1359622 commit 61f2344
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 29 deletions.
8 changes: 5 additions & 3 deletions plugins/Assembler/DialogAssembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QLineEdit>
#include <QMessageBox>
#include <QProcess>
#include <QRegExp>
#include <QRegularExpression>
#include <QSettings>
#include <QTemporaryFile>
#include <QTextDocument>
Expand Down Expand Up @@ -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);
}
}

Expand Down
11 changes: 6 additions & 5 deletions plugins/ODbgRegisterView/DialogEditSimdRegister.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QLineEdit>
#include <QRadioButton>
#include <QRegExp>
#include <QRegExpValidator>
#include <QRegularExpression>
#include <QRegularExpressionValidator>
#include <cstring>
#include <limits>
#include <type_traits>
Expand All @@ -56,10 +57,10 @@ void DialogEditSimdRegister::setupEntries(const QString &label, std::array<Numbe

DialogEditSimdRegister::DialogEditSimdRegister(QWidget *parent, Qt::WindowFlags f)
: QDialog(parent, f),
byteHexValidator_(new QRegExpValidator(QRegExp("[0-9a-fA-F]{0,2}"), this)),
wordHexValidator_(new QRegExpValidator(QRegExp("[0-9a-fA-F]{0,4}"), this)),
dwordHexValidator_(new QRegExpValidator(QRegExp("[0-9a-fA-F]{0,8}"), this)),
qwordHexValidator_(new QRegExpValidator(QRegExp("[0-9a-fA-F]{0,16}"), this)),
byteHexValidator_(new QRegularExpressionValidator(QRegularExpression("[0-9a-fA-F]{0,2}"), this)),
wordHexValidator_(new QRegularExpressionValidator(QRegularExpression("[0-9a-fA-F]{0,4}"), this)),
dwordHexValidator_(new QRegularExpressionValidator(QRegularExpression("[0-9a-fA-F]{0,8}"), this)),
qwordHexValidator_(new QRegularExpressionValidator(QRegularExpression("[0-9a-fA-F]{0,16}"), this)),
byteSignedValidator_(new QLongValidator(INT8_MIN, INT8_MAX, this)),
wordSignedValidator_(new QLongValidator(INT16_MIN, INT16_MAX, this)),
dwordSignedValidator_(new QLongValidator(INT32_MIN, INT32_MAX, this)),
Expand Down
10 changes: 5 additions & 5 deletions plugins/ODbgRegisterView/DialogEditSimdRegister.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class QDialogButtonBox;
class QHBoxLayout;
class QLongValidator;
class QRadioButton;
class QRegExpValidator;
class QRegularExpressionValidator;
class QULongValidator;
class QValidator;

Expand Down Expand Up @@ -128,10 +128,10 @@ private Q_SLOTS:
std::array<NumberEdit *, NumBytes> bytes_;
std::array<QLabel *, NumBytes> columnLabels_;

QRegExpValidator *byteHexValidator_;
QRegExpValidator *wordHexValidator_;
QRegExpValidator *dwordHexValidator_;
QRegExpValidator *qwordHexValidator_;
QRegularExpressionValidator *byteHexValidator_;
QRegularExpressionValidator *wordHexValidator_;
QRegularExpressionValidator *dwordHexValidator_;
QRegularExpressionValidator *qwordHexValidator_;

QLongValidator *byteSignedValidator_;
QLongValidator *wordSignedValidator_;
Expand Down
12 changes: 6 additions & 6 deletions plugins/ODbgRegisterView/GprEdit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "QULongValidator.h"
#include "util/Font.h"
#include <QApplication>
#include <QRegExpValidator>
#include <QRegularExpressionValidator>
#include <cmath>
#include <cstring>

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);
Expand All @@ -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<int, const QRegExpValidator *> hexValidators = {
const std::map<int, const QRegularExpressionValidator *> hexValidators = {
{1, &byteHexValidator},
{2, &wordHexValidator},
{4, &dwordHexValidator},
Expand Down
5 changes: 3 additions & 2 deletions plugins/ODbgRegisterView/arch/x86-generic/DialogEditFPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QGridLayout>
#include <QLabel>
#include <QLineEdit>
#include <QRegExp>
#include <QRegularExpression>
#include <QRegularExpressionValidator>
#include <QVBoxLayout>
#include <array>
#include <cmath>
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/DialogInputValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "edb.h"

#include <QDebug>
#include <QRegExpValidator>
#include <QRegularExpressionValidator>

#include <limits>

Expand All @@ -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<long long>::min(), std::numeric_limits<long long>::max(), this));
ui.unsignedInput->setValidator(new QULongValidator(0, std::numeric_limits<unsigned long long>::max(), this));
}
Expand Down Expand Up @@ -72,7 +72,7 @@ void DialogInputValue::setValue(Register &reg) {
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));
}
Expand Down
8 changes: 4 additions & 4 deletions src/FloatX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,10 +379,10 @@ QValidator::State FloatXValidator<Float>::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;
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/QDisassemblyView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 61f2344

Please sign in to comment.