SectionPairIdentifierValidator.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2023-02-09
  6. * Changed: 2023-02-23
  7. *
  8. * */
  9. #include <ls-std/io/section-pair/validator/SectionPairIdentifierValidator.hpp>
  10. #include <regex>
  11. using ls::std::core::Class;
  12. using ls::std::io::section_pair_identifier;
  13. using ls::std::io::SectionPairIdentifierValidator;
  14. using std::move;
  15. using std::regex;
  16. using std::regex_match;
  17. using std::string;
  18. SectionPairIdentifierValidator::SectionPairIdentifierValidator(section_pair_identifier _identifier) : Class("SectionPairIdentifierValidator"), identifier(::move(_identifier))
  19. {}
  20. SectionPairIdentifierValidator::~SectionPairIdentifierValidator() noexcept = default;
  21. string SectionPairIdentifierValidator::getValidationRegex()
  22. {
  23. return SectionPairIdentifierValidator::_getValidationRegex();
  24. }
  25. bool SectionPairIdentifierValidator::isValid()
  26. {
  27. static regex identifierRegex("^" + SectionPairIdentifierValidator::_getValidationRegex());
  28. return regex_match(this->identifier, identifierRegex);
  29. }
  30. string SectionPairIdentifierValidator::_getValidationRegex()
  31. {
  32. return R"([a-z]([a-z0-9-]){1,31})";
  33. }