refactor: use static regularexpressions and matches
This commit is contained in:
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
Reference in New Issue
Block a user