Mantid
Loading...
Searching...
No Matches
StringContainsValidator.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
8#include <memory>
9
10namespace Mantid::Kernel {
11
14StringContainsValidator::StringContainsValidator() : m_requiredStrings(std::vector<std::string>()) {}
15
18StringContainsValidator::StringContainsValidator(const std::vector<std::string> &strings)
19 : m_requiredStrings(strings) {}
20
24IValidator_sptr StringContainsValidator::clone() const { return std::make_shared<StringContainsValidator>(*this); }
25
30void StringContainsValidator::setRequiredStrings(const std::vector<std::string> &strings) {
31 m_requiredStrings = strings;
32}
33
39std::string StringContainsValidator::checkValidity(const std::string &value) const {
40 std::string error;
41 if (m_requiredStrings.empty() && !value.empty()) {
42 return "";
43 } else {
44 if (value.empty()) {
45 error += "A value must be entered for this parameter.";
46 } else {
47 size_t validityCount = 0;
48 const size_t total = m_requiredStrings.size();
49 for (size_t i = 0; i < total; i++) {
50 auto position = value.find(m_requiredStrings.at(i));
51 if (position != std::string::npos) {
52 validityCount++;
53 }
54 }
55 if (validityCount != total) {
56 error += "Error not all the required substrings were contained within "
57 "the input '" +
58 value + "'.";
59 }
60 }
61 }
62 return error;
63}
64
65} // namespace Mantid::Kernel
double value
The value of the point.
Definition: FitMW.cpp:51
double position
Definition: GetAllEi.cpp:154
double error
Definition: IndexPeaks.cpp:133
void setRequiredStrings(const std::vector< std::string > &)
Allows a for a vector of required strings to be passed to the validator.
std::string checkValidity(const std::string &value) const override
Checks the value is valid.
IValidator_sptr clone() const override
Clone the current state.
std::vector< std::string > m_requiredStrings
A vector of the sub strings the string must contain in order to pass validation.
std::shared_ptr< IValidator > IValidator_sptr
A shared_ptr to an IValidator.
Definition: IValidator.h:26
STL namespace.