refactor: use static regularexpressions and matches

This commit is contained in:
sithlord48 2024-10-20 23:54:50 -04:00 committed by Nick Bolton
parent 58323f515f
commit 498e3aa015
4 changed files with 11 additions and 8 deletions

View file

@ -691,7 +691,7 @@ void MainWindow::checkConnected(const QString &line)
void MainWindow::checkFingerprint(const QString &line) void MainWindow::checkFingerprint(const QString &line)
{ {
QRegularExpression re(".*server fingerprint: ([A-F0-9:]+)"); static const QRegularExpression re(".*server fingerprint: ([A-F0-9:]+)");
auto match = re.match(line); auto match = re.match(line);
if (!match.hasMatch()) { if (!match.hasMatch()) {
return; return;

View file

@ -86,11 +86,12 @@ int VersionChecker::getStageVersion(QString stage)
if (stage.isEmpty() || stage == stableName) { if (stage.isEmpty() || stage == stableName) {
return stableValue; return stableValue;
} else if (stage.toLower().startsWith(rcName)) { } else if (stage.toLower().startsWith(rcName)) {
QRegularExpression re("\\d*", QRegularExpression::CaseInsensitiveOption); static QRegularExpression re("\\d*", QRegularExpression::CaseInsensitiveOption);
if (re.match(stage).hasMatch()) { auto match = re.match(stage);
if (match.hasMatch()) {
// return the rc value plus the rc number (e.g. 2 + 1) // return the rc value plus the rc number (e.g. 2 + 1)
// this should be ok since stable is max int. // this should be ok since stable is max int.
return rcValue + re.match(stage).captured(1).toInt(); return rcValue + match.captured(1).toInt();
} }
} else if (stage == betaName) { } else if (stage == betaName) {
return betaValue; return betaValue;

View file

@ -27,10 +27,8 @@ ComputerNameValidator::ComputerNameValidator(const QString &message) : IStringVa
bool ComputerNameValidator::validate(const QString &input) const bool ComputerNameValidator::validate(const QString &input) const
{ {
const QRegularExpression re("^[\\w\\._-]{0,255}$", QRegularExpression::CaseInsensitiveOption); auto match = m_nameValidator.match(input);
auto match = re.match(input); return match.hasMatch();
auto result = match.hasMatch();
return result;
} }
} // namespace validators } // namespace validators

View file

@ -28,6 +28,10 @@ class ComputerNameValidator : public IStringValidator
public: public:
explicit ComputerNameValidator(const QString &message); explicit ComputerNameValidator(const QString &message);
bool validate(const QString &input) const override; bool validate(const QString &input) const override;
private:
inline static const QRegularExpression m_nameValidator =
QRegularExpression(QStringLiteral("^[\\w\\._-]{0,255}$"), QRegularExpression::CaseInsensitiveOption);
}; };
} // namespace validators } // namespace validators