refactor: extract common fixup() logic for name/issuer validators

master
Johan Ouwerkerk 2020-07-27 21:22:03 +02:00
parent 3ccafda3a1
commit f632b5ecf3
4 changed files with 17 additions and 16 deletions

View File

@ -4,6 +4,7 @@
*/
#include "issuervalidator.h"
#include "util.h"
#include <QRegularExpression>
#include <QString>
@ -33,14 +34,7 @@ namespace validators
void IssuerValidator::fixup(QString &input) const
{
QString fixed = input.simplified().remove(QLatin1Char(':'));
// make sure the user can type in at least one space
if (input.endsWith(QLatin1Char(' ')) && fixed.size() > 0) {
fixed += QLatin1Char(' ');
}
input = fixed;
input = validators::simplify_spaces(input.remove(QLatin1Char(':')));
}
QValidator::State IssuerValidator::validate(QString &input, int &cursor) const

View File

@ -4,6 +4,7 @@
*/
#include "namevalidator.h"
#include "util.h"
#include <QRegularExpression>
#include <QString>
@ -25,14 +26,7 @@ namespace validators
void NameValidator::fixup(QString &input) const
{
QString fixed = input.simplified();
// make sure the user can type in at least one space
if (input.endsWith(QLatin1Char(' ')) && fixed.size() > 0) {
fixed += QLatin1Char(' ');
}
input = fixed;
input = validators::simplify_spaces(input);
}
QValidator::State NameValidator::validate(QString &input, int &cursor) const

View File

@ -17,6 +17,18 @@ QRegularExpression spaces_pattern(void)
namespace validators
{
QString simplify_spaces(QString &input)
{
QString fixed = input.simplified();
// make sure the user can type in at least one space
if (input.endsWith(QLatin1Char(' ')) && fixed.size() > 0) {
fixed += QLatin1Char(' ');
}
return fixed;
}
QString strip_spaces(QString &input)
{
static const QRegularExpression re = spaces_pattern();

View File

@ -10,6 +10,7 @@
namespace validators
{
QString simplify_spaces(QString &input);
QString strip_spaces(QString &input);
}