Refactor: extract strip_spaces() utility function.
parent
668e912dfe
commit
f0b5f8121f
|
@ -7,6 +7,7 @@ set(validator_SRCS
|
||||||
qmlsupport.cpp
|
qmlsupport.cpp
|
||||||
namevalidator.cpp
|
namevalidator.cpp
|
||||||
secretvalidator.cpp
|
secretvalidator.cpp
|
||||||
|
util.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library(validator_lib STATIC ${validator_SRCS})
|
add_library(validator_lib STATIC ${validator_SRCS})
|
||||||
|
|
|
@ -18,6 +18,8 @@
|
||||||
|
|
||||||
#include "secretvalidator.h"
|
#include "secretvalidator.h"
|
||||||
|
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
|
@ -38,13 +40,6 @@ static QValidator::State check_padding(int length)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static QString strip_spaces(QString &input)
|
|
||||||
{
|
|
||||||
static const QRegularExpression re("\\s*");
|
|
||||||
re.optimize();
|
|
||||||
return input.replace(re, QLatin1String(""));
|
|
||||||
}
|
|
||||||
|
|
||||||
static const QRegularExpression& match_pattern(void)
|
static const QRegularExpression& match_pattern(void)
|
||||||
{
|
{
|
||||||
static const QRegularExpression re(QLatin1String("^[A-Za-z2-7]+=*$"));
|
static const QRegularExpression re(QLatin1String("^[A-Za-z2-7]+=*$"));
|
||||||
|
@ -62,7 +57,7 @@ namespace validators
|
||||||
|
|
||||||
void Base32Validator::fixup(QString &input) const
|
void Base32Validator::fixup(QString &input) const
|
||||||
{
|
{
|
||||||
input = strip_spaces(input);
|
input = validators::strip_spaces(input);
|
||||||
input = input.toUpper();
|
input = input.toUpper();
|
||||||
m_pattern.fixup(input);
|
m_pattern.fixup(input);
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
/*****************************************************************************
|
||||||
|
* Copyright: 2019 Johan Ouwerkerk <jm.ouwerkerk@gmail.com> *
|
||||||
|
* *
|
||||||
|
* This project is free software: you can redistribute it and/or modify *
|
||||||
|
* it under the terms of the GNU General Public License as published by *
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or *
|
||||||
|
* (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This project is distributed in the hope that it will be useful, *
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||||
|
* GNU General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU General Public License *
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
|
#include <QRegularExpression>
|
||||||
|
|
||||||
|
QRegularExpression spaces_patern(void)
|
||||||
|
{
|
||||||
|
static const QRegularExpression re("\\s*");
|
||||||
|
re.optimize();
|
||||||
|
return re;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace validators
|
||||||
|
{
|
||||||
|
|
||||||
|
QString strip_spaces(QString &input)
|
||||||
|
{
|
||||||
|
static const QRegularExpression re = spaces_patern();
|
||||||
|
return input.replace(re, QLatin1String(""));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
/*****************************************************************************
|
||||||
|
* Copyright: 2019 Johan Ouwerkerk <jm.ouwerkerk@gmail.com> *
|
||||||
|
* *
|
||||||
|
* This project is free software: you can redistribute it and/or modify *
|
||||||
|
* it under the terms of the GNU General Public License as published by *
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or *
|
||||||
|
* (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This project is distributed in the hope that it will be useful, *
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||||
|
* GNU General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU General Public License *
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef VALIDATOR_UTIL_H
|
||||||
|
#define VALIDATOR_UTIL_H
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
namespace validators
|
||||||
|
{
|
||||||
|
QString strip_spaces(QString &input);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue