6#include "validatorcharnotallowed_p.h"
14 :
ValidatorRule(*new ValidatorCharNotAllowedPrivate(
field, forbiddenChars, messages, defValKey))
28 for (
const QChar &forbiddenChar : forbiddenChars) {
29 if (
value.contains(forbiddenChar)) {
32 *foundChar = forbiddenChar;
50 if (Q_LIKELY(!d->forbiddenChars.isEmpty())) {
58 qCWarning(C_VALIDATOR)
59 <<
"ValidatorCharNotAllowed: Empty validation data for field" <<
field() <<
"at"
60 << c->controllerName() <<
"::" << c->actionName();
77 error = c->
translate(
"Cutelyst::ValidatorCharNotAllowed",
78 "Must not contain the following characters: “%1”. But contains the "
79 "following illegal character: “%2”.")
83 c->
translate(
"Cutelyst::ValidatorCharNotAllowed",
84 "The text in the “%1“ field must not contain the following characters: "
85 "“%2“. But contains the following illegal character: “%3”.")
86 .
arg(_label, d->forbiddenChars,
QString(foundChar));
99 error = c->
translate(
"Cutelyst::ValidatorCharNotAllowed",
100 "The list of illegal characters for this field is empty.");
102 error = c->
translate(
"Cutelyst::ValidatorCharNotAllowed",
103 "The list of illegal characters for the “%1“ field is empty.")
QString translate(const char *context, const char *sourceText, const char *disambiguation=nullptr, int n=-1) const
QString genericValidationDataError(Context *c, const QVariant &errorData=QVariant()) const override
Returns a generic error if the list of forbidden characters is empty.
QString genericValidationError(Context *c, const QVariant &errorData=QVariant()) const override
Returns a generic error message if validation failed.
~ValidatorCharNotAllowed() override
Deconstructs the char not allowed validator.
ValidatorCharNotAllowed(const QString &field, const QString &forbiddenChars, const ValidatorMessages &messages=ValidatorMessages(), const QString &defValKey=QString())
Constructs a new char not allowed validator.
QString label(Context *c) const
Returns the human readable field label used for generic error messages.
QString field() const
Returns the name of the field to validate.
void defaultValue(Context *c, ValidatorReturnType *result, const char *validatorName) const
I a defValKey has been set in the constructor, this will try to get the default value from the stash ...
ValidatorRule(const QString &field, const ValidatorMessages &messages=ValidatorMessages(), const QString &defValKey=QString())
Constructs a new ValidatorRule with the given parameters.
QString value(const ParamsMultiMap ¶ms) const
Returns the value of the field from the input params.
QString validationDataError(Context *c, const QVariant &errorData=QVariant()) const
Returns an error message if any validation data is missing or invalid.
QString validationError(Context *c, const QVariant &errorData=QVariant()) const
Returns a descriptive error message if validation failed.
static bool validate(const QString &value, const QString &forbiddenChars, QChar *foundChar=nullptr)
Returns true if value does not contain any of the characters in forbiddenChars.
The Cutelyst namespace holds all public Cutelyst API.
QMultiMap< QString, QString > ParamsMultiMap
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
bool isEmpty() const const
void setValue(const T &value)
QChar toChar() const const
Stores custom error messages and the input field label.
Contains the result of a single input parameter validation.