Unravel Engine C++ Reference
Loading...
Searching...
No Matches
pattern_filter.h
Go to the documentation of this file.
1#pragma once
2
3#include <string>
4#include <vector>
5#include <functional>
6#include "filesystem.h"
7
8namespace fs
9{
10
15{
16public:
21 explicit wildcard_pattern(const std::string& pattern);
22
28 auto matches(const std::string& str) const -> bool;
29
33 auto get_pattern() const -> const std::string& { return pattern_; }
34
35private:
36 std::string pattern_;
37
41 auto match_impl(const char* pattern, const char* str) const -> bool;
42};
43
48{
49public:
53 pattern_filter() = default;
54
59 explicit pattern_filter(const std::string& include_pattern);
60
66 pattern_filter(const std::vector<std::string>& include_patterns,
67 const std::vector<std::string>& exclude_patterns = {});
68
73 void add_include_pattern(const std::string& pattern);
74
79 void add_exclude_pattern(const std::string& pattern);
80
87 auto should_include(const fs::path& path) const -> bool;
88
94 auto should_include_filename(const std::string& filename) const -> bool;
95
99 auto has_patterns() const -> bool;
100
104 auto is_wildcard() const -> bool;
105
109 auto get_include_patterns() const -> const std::vector<wildcard_pattern>&;
110
114 auto get_exclude_patterns() const -> const std::vector<wildcard_pattern>&;
115
116private:
117 std::vector<wildcard_pattern> include_patterns_;
118 std::vector<wildcard_pattern> exclude_patterns_;
119};
120
127auto make_pattern_filter(const std::string& pattern) -> pattern_filter;
128
135auto make_pattern_filter(const std::vector<std::string>& includes,
136 const std::vector<std::string>& excludes = {}) -> pattern_filter;
137
138} // namespace fs
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)
auto get_pattern() const -> const std::string &
Gets the original pattern string.
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.
Definition cache.hpp:11
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...