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)
{
QRegularExpression re(".*server fingerprint: ([A-F0-9:]+)");
static const QRegularExpression re(".*server fingerprint: ([A-F0-9:]+)");
auto match = re.match(line);
if (!match.hasMatch()) {
return;

View File

@ -86,11 +86,12 @@ int VersionChecker::getStageVersion(QString stage)
if (stage.isEmpty() || stage == stableName) {
return stableValue;
} else if (stage.toLower().startsWith(rcName)) {
QRegularExpression re("\\d*", QRegularExpression::CaseInsensitiveOption);
if (re.match(stage).hasMatch()) {
static QRegularExpression re("\\d*", QRegularExpression::CaseInsensitiveOption);
auto match = re.match(stage);
if (match.hasMatch()) {
// return the rc value plus the rc number (e.g. 2 + 1)
// 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) {
return betaValue;

View File

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

View File

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