SectionPairRowListValueValidator.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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/SectionPairRowListValueValidator.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::SectionPairRowListValueValidator;
  16. using ls::std::io::SectionPairValueValidator;
  17. using std::move;
  18. using std::regex;
  19. using std::regex_match;
  20. using std::string;
  21. SectionPairRowListValueValidator::SectionPairRowListValueValidator(string _listValueRow) : Class("SectionPairRowListValueValidator"), listValueRow(::move(_listValueRow))
  22. {}
  23. SectionPairRowListValueValidator::~SectionPairRowListValueValidator() noexcept = default;
  24. string SectionPairRowListValueValidator::getValidationRegex()
  25. {
  26. return SectionPairRowListValueValidator::_getValidationRegex();
  27. }
  28. bool SectionPairRowListValueValidator::isValid()
  29. {
  30. string validationRegex = SectionPairRowListValueValidator::_getValidationRegex();
  31. static auto listValueRowRegex = regex{"^" + validationRegex};
  32. return regex_match(this->listValueRow, listValueRowRegex);
  33. }
  34. string SectionPairRowListValueValidator::_getValidationRegex()
  35. {
  36. string identifierRegex = SectionPairIdentifierValidator::getValidationRegex();
  37. string valueRegex = SectionPairValueValidator::getValidationRegex();
  38. string lineBreak = R"(((\n{1})|(\r{1}\n{1})))";
  39. string firstLine = R"(((()" + identifierRegex + R"():{1}))" + lineBreak + R"())";
  40. return R"((()" + firstLine + R"(( {2})" + valueRegex + R"()" + lineBreak + R"()){1}(( {2})" + valueRegex + R"()" + lineBreak + R"()*)))";
  41. }