SectionPairRowListValueValidator.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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/SectionPairRowListValueValidator.hpp>
  11. #include <ls-std/io/section-pair/validator/SectionPairValueValidator.hpp>
  12. #include <regex>
  13. ls::std::io::SectionPairRowListValueValidator::SectionPairRowListValueValidator(::std::string _listValueRow) : ls::std::core::Class("SectionPairRowListValueValidator"), listValueRow(::std::move(_listValueRow))
  14. {}
  15. ls::std::io::SectionPairRowListValueValidator::~SectionPairRowListValueValidator() noexcept = default;
  16. ::std::string ls::std::io::SectionPairRowListValueValidator::getValidationRegex()
  17. {
  18. return ls::std::io::SectionPairRowListValueValidator::_getValidationRegex();
  19. }
  20. bool ls::std::io::SectionPairRowListValueValidator::isValid()
  21. {
  22. ::std::string validationRegex = ls::std::io::SectionPairRowListValueValidator::_getValidationRegex();
  23. static ::std::regex listValueRowRegex = ::std::regex{"^" + validationRegex};
  24. return ::std::regex_match(this->listValueRow, listValueRowRegex);
  25. }
  26. ::std::string ls::std::io::SectionPairRowListValueValidator::_getValidationRegex()
  27. {
  28. ::std::string identifierRegex = ls::std::io::SectionPairIdentifierValidator::getValidationRegex();
  29. ::std::string valueRegex = ls::std::io::SectionPairValueValidator::getValidationRegex();
  30. ::std::string lineBreak = R"(((\n{1})|(\r{1}\n{1})))";
  31. ::std::string firstLine = R"(((()" + identifierRegex + R"():{1}))" + lineBreak + R"())";
  32. return R"((()" + firstLine + R"(( {2})" + valueRegex + R"()" + lineBreak + R"()){1}(( {2})" + valueRegex + R"()" + lineBreak + R"()*)))";
  33. }