SectionPairRowListValueValidator.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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-20
  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() = 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 windowsFirstLine = R"(((()" + identifierRegex + R"():{1})\r{1}\n{1}))";
  31. ::std::string unixFirstLine = R"(((()" + identifierRegex + R"():{1})\n{1}))";
  32. ::std::string windowsValidationRegex = R"((()" + windowsFirstLine + R"(( {2})" + valueRegex + R"(\r{1}\n{1})){1}(( {2})" + valueRegex + R"(\r{1}\n{1})*)))";
  33. ::std::string unixValidationRegex = R"(|(()" + unixFirstLine + R"(( {2})" + valueRegex + R"(\n{1})){1}(( {2})" + valueRegex + R"(\n{1})*)))";
  34. return windowsValidationRegex + unixValidationRegex;
  35. }