SectionPairFileExtensionValidator.cpp 1.1 KB

123456789101112131415161718192021222324252627282930
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2023-02-21
  6. * Changed: 2023-02-23
  7. *
  8. * */
  9. #include <ls-std/io/section-pair/validator/SectionPairFileExtensionValidator.hpp>
  10. using ls::std::core::Class;
  11. using ls::std::io::SectionPairFileExtensionValidator;
  12. using std::move;
  13. using std::string;
  14. SectionPairFileExtensionValidator::SectionPairFileExtensionValidator(string _fileName) : Class("SectionPairFileExtensionValidator"), fileName(::move(_fileName))
  15. {}
  16. SectionPairFileExtensionValidator::~SectionPairFileExtensionValidator() noexcept = default;
  17. bool SectionPairFileExtensionValidator::isValid()
  18. {
  19. string textFileExtension = ".txt";
  20. string sectionPairFileExtension = ".sp";
  21. bool endsWithTextFileExtension = this->fileName.rfind(textFileExtension) == (this->fileName.size() - textFileExtension.size());
  22. bool endsWithSectionPairFileExtension = this->fileName.rfind(sectionPairFileExtension) == (this->fileName.size() - sectionPairFileExtension.size());
  23. return endsWithTextFileExtension || endsWithSectionPairFileExtension;
  24. }