SectionPairValueValidator.cpp 1.3 KB

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