SectionPairRowSingleValueValidator.cpp 1.7 KB

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