SectionPairValueValidator.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Co-Author: Claude Sonnet 4.6 (LLM)
  4. * Company: Lynar Studios
  5. * E-Mail: webmaster@lynarstudios.com
  6. * Created: 2023-02-09
  7. * Changed: 2026-06-23
  8. *
  9. * */
  10. #include <ls-std/io/section-pair/validator/SectionPairValueValidator.hpp>
  11. #include <regex>
  12. using ls::standard::core::Class;
  13. using ls::standard::io::section_pair_row_value;
  14. using ls::standard::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 _getValidationRegex();
  25. }
  26. bool SectionPairValueValidator::isValid()
  27. {
  28. const string validationRegex = _getValidationRegex();
  29. const 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. }