| 12345678910111213141516171819202122232425262728293031323334 |
- #pragma once
- #include <algorithm>
- #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() + i, '\\');
- }
- for (size_t i = glob.find('*'); i != std::string::npos; i = glob.find('*', i + 2)) {
- glob.insert(glob.begin() + 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 {
- return std::count(blacklist.begin(), blacklist.end(), str) == 0 and
- (whitelist.empty() or std::count(whitelist.begin(), whitelist.end(), str) > 0);
- }
- };
|