14 return match_impl(pattern_.c_str(), str.c_str());
17auto wildcard_pattern::match_impl(
const char* pattern,
const char* str)
const ->
bool
29 while (*pattern ==
'*')
43 if (match_impl(pattern, str))
51 return match_impl(pattern, str);
55 if (*pattern ==
'?' && *str !=
'\0')
57 return match_impl(pattern + 1, str + 1);
63 return match_impl(pattern + 1, str + 1);
72 if (!include_pattern.empty())
79 const std::vector<std::string>& exclude_patterns)
81 for (
const auto& pattern : include_patterns)
85 for (
const auto& pattern : exclude_patterns)
95 include_patterns_.emplace_back(pattern);
101 if (!pattern.empty())
103 exclude_patterns_.emplace_back(pattern);
109 return should_include_filename(path.filename().string());
115 for (
const auto& exclude_pattern : exclude_patterns_)
117 if (exclude_pattern.matches(filename))
124 if (include_patterns_.empty())
130 for (
const auto& include_pattern : include_patterns_)
132 if (include_pattern.matches(filename))
144 return !include_patterns_.empty() || !exclude_patterns_.empty();
157 if (include_patterns_.size() == 1 && exclude_patterns_.empty())
159 return include_patterns_[0].get_pattern() ==
"*";
167 return include_patterns_;
172 return exclude_patterns_;
A filter that combines include and exclude patterns for file/directory filtering.
pattern_filter()=default
Default constructor creates a filter that accepts everything.
auto has_patterns() const -> bool
Checks if this filter has any patterns.
void add_exclude_pattern(const std::string &pattern)
Adds an exclude pattern to the filter.
auto get_include_patterns() const -> const std::vector< wildcard_pattern > &
Gets all include patterns.
auto get_exclude_patterns() const -> const std::vector< wildcard_pattern > &
Gets all exclude patterns.
auto should_include_filename(const std::string &filename) const -> bool
Tests if a filename should be included based on the filter rules.
void add_include_pattern(const std::string &pattern)
Adds an include pattern to the filter.
auto should_include(const fs::path &path) const -> bool
Tests if a path should be included based on the filter rules Logic: (matches any include pattern OR n...
auto is_wildcard() const -> bool
Checks if this filter is effectively a wildcard (no restrictions)
A wildcard pattern matcher that supports * (match any sequence) and ? (match single character)
wildcard_pattern(const std::string &pattern)
Constructs a wildcard pattern from a string.
auto matches(const std::string &str) const -> bool
Tests if the given string matches this pattern.
auto make_pattern_filter(const std::string &pattern) -> pattern_filter
Convenience function to create a pattern filter from a single wildcard string Maintains backward comp...