| 123456789101112131415161718192021222324252627282930313233343536 |
- #pragma once
- #include <algorithm>
- #include <cstddef>
- #include <regex>
- #include <string>
- #include <vector>
- class Glob {
- private:
- std::regex re_;
- public:
- explicit Glob(std::string glob) {
- for (size_t i = glob.find('.'); i != std::string::npos; i = glob.find('.', i + 2)) {
- glob.insert(glob.begin() + static_cast<ptrdiff_t>(i), '\\');
- }
- for (size_t i = glob.find('*'); i != std::string::npos; i = glob.find('*', i + 2)) {
- glob.insert(glob.begin() + static_cast<ptrdiff_t>(i), '.');
- }
- re_ = std::regex(glob);
- }
- bool operator==(std::string const & str) const { return std::regex_search(str, re_); }
- };
- struct RecursiveTestFilter {
- std::vector<Glob> whitelist;
- std::vector<Glob> blacklist;
- bool accepts(std::string const & str) const {
- auto in = [&str](auto & glob) { return glob == str; };
- return std::ranges::count_if(blacklist, in) == 0 and
- (whitelist.empty() or std::ranges::count_if(whitelist, in) > 0);
- }
- };
|