SectionPairRowValidator.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2023-02-20
  6. * Changed: 2023-05-18
  7. *
  8. * */
  9. #include <ls-std/io/section-pair/validator/SectionPairRowListValueValidator.hpp>
  10. #include <ls-std/io/section-pair/validator/SectionPairRowSingleValueValidator.hpp>
  11. #include <ls-std/io/section-pair/validator/SectionPairRowValidator.hpp>
  12. #include <regex>
  13. using ls::std::core::Class;
  14. using ls::std::io::SectionPairRowListValueValidator;
  15. using ls::std::io::SectionPairRowValidator;
  16. using std::move;
  17. using std::regex;
  18. using std::regex_match;
  19. using std::string;
  20. SectionPairRowValidator::SectionPairRowValidator(string _row) : Class("SectionPairRowValidator"), row(::move(_row))
  21. {}
  22. SectionPairRowValidator::~SectionPairRowValidator() noexcept = default;
  23. string SectionPairRowValidator::getValidationRegex()
  24. {
  25. return SectionPairRowValidator::_getValidationRegex();
  26. }
  27. bool SectionPairRowValidator::isValid()
  28. {
  29. string validationRegex = SectionPairRowValidator::_getValidationRegex();
  30. static auto sectionPairRowRegex = regex{R"(^()" + validationRegex + R"())"};
  31. return regex_match(this->row, sectionPairRowRegex);
  32. }
  33. string SectionPairRowValidator::_getValidationRegex()
  34. {
  35. string listValueRowRegex = SectionPairRowListValueValidator::getValidationRegex();
  36. string singleValueRowRegex = SectionPairRowSingleValueValidator::getValidationRegex();
  37. return R"(()" + singleValueRowRegex + R"()|()" + listValueRowRegex + R"())";
  38. }