29 #include "Requirement.h"
78 virtual void Parse(Value json,
const std::string& path)
override
83 if(json.isMember(
"minLength") && json[
"minLength"].isUInt())
89 if(json.isMember(
"maxLength") && json[
"maxLength"].isUInt())
96 if(json.isMember(
"pattern") && json[
"pattern"].isString())
99 expr_ = json[
"pattern"].asString();
100 regex_ = std::regex(
expr_, std::regex::ECMAScript);
103 if(json.isMember(
"enum") && json[
"enum"].isArray())
105 for(
const auto& val : json[
"enum"])
106 enum_.push_back(val.asString());
120 virtual void Validate(
const Value& json,
const std::string& path)
override
124 PushError(path +
": Must be of type \"string\"");
135 PushError(path +
": String must match regular expression \"" +
expr_ +
"\"");
138 PushError(path +
": String is not a valid entry");
Requirements on input files.
virtual void ClearNotices()
Clear list of notice messages.
virtual void ClearErrors()
Clear list of error messages.
void PushError(const std::string &error)
Add error to list of error messages.
size_t minLength_
Minimum string length;.
std::string path_
Path for JSON path specification.
std::vector< std::string > enum_
Enum values.
virtual void Validate(const Value &json, const std::string &path) override
Validate string value.
virtual void Reset() override
Reset Requirement.
bool minSet_
If True, minimum length requirement is active.
std::regex regex_
Regular expression to match string to.
std::string expr_
Expression.
size_t maxLength_
Maximum string length;.
bool maxSet_
If True, maximum length requirement is active.
virtual void Parse(Value json, const std::string &path) override
Parse JSON value to generate Requirement.
bool rgxSet_
If True, string has to match regular expression.
StringRequirement()
Constructor.