File indexing completed on 2024-04-28 05:50:09
0001 /* 0002 * SPDX-License-Identifier: GPL-3.0-or-later 0003 * SPDX-FileCopyrightText: 2019-2020 Johan Ouwerkerk <jm.ouwerkerk@gmail.com> 0004 */ 0005 0006 #include "namevalidator.h" 0007 #include "util.h" 0008 0009 #include <QRegularExpression> 0010 #include <QString> 0011 0012 static const QRegularExpression& match_pattern(void) 0013 { 0014 static const QRegularExpression re(QLatin1String("^\\S+( \\S+)*$")); 0015 re.optimize(); 0016 return re; 0017 } 0018 0019 namespace validators 0020 { 0021 NameValidator::NameValidator(QObject *parent): 0022 QValidator(parent), 0023 m_pattern(match_pattern()) 0024 { 0025 } 0026 0027 void NameValidator::fixup(QString &input) const 0028 { 0029 input = validators::simplify_spaces(input); 0030 } 0031 0032 QValidator::State NameValidator::validate(QString &input, int &cursor) const 0033 { 0034 return m_pattern.validate(input, cursor); 0035 } 0036 }