SectionPairRowSingleValueValidator.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2023-02-19
  6. * Changed: 2023-02-22
  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. ls::std::io::SectionPairRowSingleValueValidator::SectionPairRowSingleValueValidator(::std::string _singleValueRow) : ls::std::core::Class("SectionPairRowSingleValueValidator"), singleValueRow(::std::move(_singleValueRow))
  14. {}
  15. ls::std::io::SectionPairRowSingleValueValidator::~SectionPairRowSingleValueValidator() noexcept = default;
  16. ::std::string ls::std::io::SectionPairRowSingleValueValidator::getValidationRegex()
  17. {
  18. return ls::std::io::SectionPairRowSingleValueValidator::_getValidationRegex();
  19. }
  20. bool ls::std::io::SectionPairRowSingleValueValidator::isValid()
  21. {
  22. ::std::string validationRegex = ls::std::io::SectionPairRowSingleValueValidator::_getValidationRegex();
  23. static ::std::regex singleValueRowRegex = ::std::regex{"^" + validationRegex};
  24. return ::std::regex_match(this->singleValueRow, singleValueRowRegex);
  25. }
  26. ::std::string ls::std::io::SectionPairRowSingleValueValidator::_getValidationRegex()
  27. {
  28. ::std::string identifierRegex = ls::std::io::SectionPairIdentifierValidator::getValidationRegex();
  29. ::std::string valueRegex = ls::std::io::SectionPairValueValidator::getValidationRegex();
  30. return R"(()" + identifierRegex + R"()={1}()" + valueRegex + R"(){1}($|\n{1}|\r{1}\n{1}))";
  31. }