cutelyst 4.8.0
A C++ Web Framework built on top of Qt, using the simple approach of Catalyst (Perl) framework.
validatoraccepted.cpp
1/*
2 * SPDX-FileCopyrightText: (C) 2017-2023 Matthias Fehring <mf@huessenbergnetz.de>
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6#include "validatoraccepted_p.h"
7
8#include <QStringList>
9
10using namespace Cutelyst;
11using namespace Qt::Literals::StringLiterals;
12
13const QStringList ValidatorAcceptedPrivate::trueVals{u"yes"_s, u"on"_s, u"1"_s, u"true"_s};
14
16 const Cutelyst::ValidatorMessages &messages)
17 : ValidatorRule(*new ValidatorAcceptedPrivate(field, messages))
18{
19}
20
22
24 const Cutelyst::ParamsMultiMap &params) const
25{
27
28 if (Q_LIKELY(ValidatorAccepted::validate(value(params)))) {
29 result.value.setValue<bool>(true);
30 } else {
31 result.errorMessage = validationError(c);
32 result.value.setValue<bool>(false);
33 qCDebug(C_VALIDATOR).noquote() << debugString(c);
34 }
35
36 return result;
37}
38
40{
41 return ValidatorAcceptedPrivate::trueVals.contains(value, Qt::CaseInsensitive);
42}
43
45 const QVariant &errorData) const
46{
47 Q_UNUSED(errorData)
48 const QString _label = label(c);
49 if (_label.isEmpty()) {
50 //% "Has to be accepted."
51 return c->qtTrId("cutelyst-valaccepted-genvalerr");
52 } else {
53 //: %1 will be replaced by the field label
54 //% "“%1” has to be accepted."
55 return c->qtTrId("cutelyst-valaccepted-genvalerr-label").arg(_label);
56 }
57}
The Cutelyst Context.
Definition context.h:42
QString qtTrId(const char *id, int n=-1) const
Definition context.h:656
ValidatorAccepted(const QString &field, const ValidatorMessages &messages=ValidatorMessages())
QString genericValidationError(Context *c, const QVariant &errorData=QVariant()) const override
QString field() const noexcept
QString validationError(Context *c, const QVariant &errorData={}) const
QString label(Context *c) const
ValidatorRule(const QString &field, const ValidatorMessages &messages={}, const QString &defValKey={}, QByteArrayView validatorName=nullptr)
QString value(const ParamsMultiMap &params) const
QString debugString(Context *c) const
QMultiMap< QString, QString > ParamsMultiMap
static bool validate(const QString &value)
Returns true if the value is equal to yes, on, 1, or true.
The Cutelyst namespace holds all public Cutelyst API.
Stores custom error messages and the input field label.
Contains the result of a single input parameter validation.