SectionPairValueValidator.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2023-02-09
  6. * Changed: 2023-06-06
  7. *
  8. * */
  9. #include <ls-std/io/NewLine.hpp>
  10. #include <ls-std/io/section-pair/validator/SectionPairValueValidator.hpp>
  11. #include <regex>
  12. using ls::std::core::Class;
  13. using ls::std::io::section_pair_row_value;
  14. using ls::std::io::SectionPairValueValidator;
  15. using std::move;
  16. using std::regex;
  17. using std::regex_match;
  18. using std::string;
  19. SectionPairValueValidator::SectionPairValueValidator(section_pair_row_value _value) : Class("SectionPairValueValidator"), value(::move(_value))
  20. {}
  21. SectionPairValueValidator::~SectionPairValueValidator() noexcept = default;
  22. string SectionPairValueValidator::getValidationRegex()
  23. {
  24. return SectionPairValueValidator::_getValidationRegex();
  25. }
  26. bool SectionPairValueValidator::isValid()
  27. {
  28. string validationRegex = SectionPairValueValidator::_getValidationRegex();
  29. string concatenation = "(^" + validationRegex + ")|(^" + validationRegex + R"(\n{1})|(^)" + validationRegex + R"(\r{1}\n{1}))";
  30. static regex valueRegex{concatenation};
  31. return regex_match(this->value, valueRegex);
  32. }
  33. string SectionPairValueValidator::_getValidationRegex()
  34. {
  35. string value = R"([a-zA-Z0-9\-_#!?\[\]\{\}\(\)\$€\\§<>+:;., \*\/"]{1,512})";
  36. return value;
  37. }