Add keyword validation using a predicate function

This commit is contained in:
Peter Verveer
2021-06-11 18:22:29 +02:00
parent f9618faceb
commit fd753e20c4
6 changed files with 145 additions and 49 deletions

View File

@@ -109,6 +109,7 @@ namespace KeywordValidation
// Otherwise, check all its items.
validateKeywordItems(keyword, m_string_items, errors);
validateKeywordItems(keyword, m_int_items, errors);
validateKeywordItems(keyword, m_double_items, errors);
}
}
@@ -152,8 +153,7 @@ namespace KeywordValidation
const T& item_value,
std::vector<ValidationError>& errors) const
{
const auto& permitted = properties.permitted_values;
if (std::find(permitted.begin(), permitted.end(), item_value) == permitted.end()) {
if (!properties.validator(item_value)) {
// If the value is not permitted, format the value to report it.
std::string formatted_value;
if constexpr (std::is_arithmetic<T>::value)