6#include "validatorsize_p.h"
15 :
ValidatorRule(*new ValidatorSizePrivate(field, type, size, messages, defValKey))
40 if (Q_UNLIKELY(!ok)) {
42 qCWarning(C_VALIDATOR).noquote().nospace()
43 <<
debugString(c) <<
"Failed to parse \"" << v <<
"\" into an integer number";
45 const qlonglong size =
46 ValidatorSizePrivate::extractLongLong(c, params, d->
size, &ok);
47 if (Q_UNLIKELY(!ok)) {
49 qCWarning(C_VALIDATOR).noquote() <<
debugString(c) <<
"Invalid comparison size";
53 qCDebug(C_VALIDATOR).noquote() <<
debugString(c) << val <<
"!=" << size;
66 if (Q_UNLIKELY(!ok)) {
68 qCWarning(C_VALIDATOR).noquote().nospace()
70 <<
"\" into an unsigned integer number";
72 const qulonglong size =
73 ValidatorSizePrivate::extractULongLong(c, params, d->
size, &ok);
74 if (Q_UNLIKELY(!ok)) {
76 qCWarning(C_VALIDATOR).noquote() <<
debugString(c) <<
"Invalid comparison size";
80 qCDebug(C_VALIDATOR).noquote() <<
debugString(c) << val <<
"!=" << size;
91 if (Q_UNLIKELY(!ok)) {
93 qCWarning(C_VALIDATOR).noquote().nospace()
95 <<
"\" into a floating point number";
97 const double size = ValidatorSizePrivate::extractDouble(c, params, d->
size, &ok);
98 if (Q_UNLIKELY(!ok)) {
100 qCWarning(C_VALIDATOR).noquote() <<
debugString(c) <<
"Invalid comparison size";
104 qCDebug(C_VALIDATOR).noquote() <<
debugString(c) << val <<
"!=" << size;
113 const auto val =
static_cast<qlonglong
>(v.
length());
114 const qlonglong size = ValidatorSizePrivate::extractLongLong(c, params, d->
size, &ok);
115 if (Q_UNLIKELY(!ok)) {
117 qCWarning(C_VALIDATOR).noquote() <<
debugString(c) <<
"Invalid comparison size";
121 qCDebug(C_VALIDATOR).noquote()
122 <<
debugString(c) <<
"string length" << val <<
"!=" << size;
129 qCWarning(C_VALIDATOR).noquote()
130 <<
debugString(c) <<
"The comparison type" << d->type <<
"is not supported";
137 const QVariant _v = ValidatorSizePrivate::valueToNumber(c, v, d->type);
191 return c->
qtTrId(
"cutelyst-valsize-genvalerr-str").
arg(size);
194 return c->
qtTrId(
"cutelyst-valsize-genvalerr-num").
arg(size);
201 return c->
qtTrId(
"cutelyst-valsize-genvalerr-str-label").
arg(_label, size);
206 return c->
qtTrId(
"cutelyst-valsize-genvalerr-num-label").
arg(_label, size);
220 return c->
qtTrId(
"cutelyst-validator-genvaldataerr-type")
223 return c->
qtTrId(
"cutelyst-validator-genvaldataerr-type-label")
229 return c->
qtTrId(
"cutelyst-valsize-genvaldataerr-size");
233 return c->
qtTrId(
"cutelyst-valsize-genvaldataerr-size-label").
arg(_label);
248 return c->
qtTrId(
"cutelyst-validator-genparseerr-float");
250 return c->
qtTrId(
"cutelyst-validator-genparseerr-float-label").
arg(_label);
254 return c->
qtTrId(
"cutelyst-validator-genparseerr-int");
256 return c->
qtTrId(
"cutelyst-validator-genparseerr-int-label").
arg(_label);
QLocale locale() const noexcept
QString qtTrId(const char *id, int n=-1) const
Base class for all validator rules.
QString field() const noexcept
QString validationError(Context *c, const QVariant &errorData={}) const
QString label(const Context *c) const
QString debugString(const Context *c) const
QString validationDataError(Context *c, const QVariant &errorData={}) const
std::function< void(ValidatorReturnType &&result)> ValidatorRtFn
Void callback function for validator rules that processes the ValidatorReturnType.
void defaultValue(Context *c, ValidatorReturnType *result) const
QString value(const ParamsMultiMap ¶ms) const
QString parsingError(Context *c, const QVariant &errorData={}) const
The field under validation must have a size matching the given value.
~ValidatorSize() override
QString genericValidationError(Context *c, const QVariant &errorData=QVariant()) const override
ValidatorSize(const QString &field, QMetaType::Type type, const QVariant &size, const ValidatorMessages &messages=ValidatorMessages(), const QString &defValKey={})
QString genericParsingError(Context *c, const QVariant &errorData) const override
void validateCb(Context *c, const ParamsMultiMap ¶ms, ValidatorRtFn cb) const override
QString genericValidationDataError(Context *c, const QVariant &errorData) const override
ValidatorReturnType validate(Context *c, const ParamsMultiMap ¶ms) const override
The Cutelyst namespace holds all public Cutelyst API.
qlonglong toLongLong(QStringView s, bool *ok) const const
QString toString(QDate date, QLocale::FormatType format) const const
QMultiMap::size_type size() const const
QString arg(Args &&... args) const const
QString fromLatin1(QByteArrayView str)
bool isEmpty() const const
qsizetype length() const const
double toDouble(bool *ok) const const
qulonglong toULongLong(bool *ok, int base) const const
bool isValid() const const
void setValue(QVariant &&value)
double toDouble(bool *ok) const const
int toInt(bool *ok) const const
qlonglong toLongLong(bool *ok) const const
qulonglong toULongLong(bool *ok) const const
Stores custom error messages and the input field label.
Contains the result of a single input parameter validation.