Struct broot::pattern::CompositePattern
source · pub struct CompositePattern {
pub expr: BeTree<PatternOperator, Pattern>,
}
Expand description
A pattern composing other ones with operators
Fields§
§expr: BeTree<PatternOperator, Pattern>
Implementations§
source§impl CompositePattern
impl CompositePattern
sourcepub fn new(expr: BeTree<PatternOperator, Pattern>) -> Self
pub fn new(expr: BeTree<PatternOperator, Pattern>) -> Self
Examples found in repository?
src/pattern/pattern.rs (line 91)
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
pub fn new(
raw_expr: &BeTree<PatternOperator, PatternParts>,
search_modes: &SearchModeMap,
content_search_max_file_size: usize,
) -> Result<Self, PatternError> {
let expr: BeTree<PatternOperator, Pattern> = raw_expr
.try_map_atoms::<_, PatternError, _>(|pattern_parts| {
let core = pattern_parts.core();
Ok(
if core.is_empty() {
Pattern::None
} else {
let parts_mode = pattern_parts.mode();
let mode = search_modes.search_mode(parts_mode)?;
let flags = pattern_parts.flags();
match mode {
SearchMode::NameExact => Self::NameExact(
ExactPattern::from(core)
),
SearchMode::NameFuzzy => Self::NameFuzzy(
FuzzyPattern::from(core)
),
SearchMode::NameRegex => Self::NameRegex(
RegexPattern::from(core, flags.unwrap_or(""))?
),
SearchMode::NameTokens => Self::NameTokens(
TokPattern::new(core)
),
SearchMode::PathExact => Self::PathExact(
ExactPattern::from(core)
),
SearchMode::PathFuzzy => Self::PathFuzzy(
FuzzyPattern::from(core)
),
SearchMode::PathRegex => Self::PathRegex(
RegexPattern::from(core, flags.unwrap_or(""))?
),
SearchMode::PathTokens => Self::PathTokens(
TokPattern::new(core)
),
SearchMode::ContentExact => Self::ContentExact(
ContentExactPattern::new(core, content_search_max_file_size)
),
SearchMode::ContentRegex => Self::ContentRegex(
ContentRegexPattern::new(
core,
flags.unwrap_or(""),
content_search_max_file_size,
)?
),
}
}
)
})?;
Ok(if expr.is_empty() {
Pattern::None
} else if expr.is_atomic() {
expr.atoms().pop().unwrap()
} else {
Self::Composite(CompositePattern::new(expr))
})
}
sourcepub fn score_of_string(&self, candidate: &str) -> Option<i32>
pub fn score_of_string(&self, candidate: &str) -> Option<i32>
Examples found in repository?
src/pattern/pattern.rs (line 188)
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
pub fn score_of_string(&self, candidate: &str) -> Option<i32> {
match self {
Self::NameExact(ep) => ep.score_of(candidate),
Self::NameFuzzy(fp) => fp.score_of(candidate),
Self::NameRegex(rp) => rp.find(candidate).map(|m| m.score),
Self::NameTokens(tp) => tp.score_of(candidate),
Self::PathExact(ep) => ep.score_of(candidate),
Self::PathFuzzy(fp) => fp.score_of(candidate),
Self::PathRegex(rp) => rp.find(candidate).map(|m| m.score),
Self::PathTokens(tp) => tp.score_of(candidate),
Self::ContentExact(_) => None, // this isn't suitable
Self::ContentRegex(_) => None, // this isn't suitable
Self::Composite(cp) => cp.score_of_string(candidate),
Self::None => Some(1),
}
}
sourcepub fn score_of(&self, candidate: Candidate<'_>) -> Option<i32>
pub fn score_of(&self, candidate: Candidate<'_>) -> Option<i32>
Examples found in repository?
src/pattern/pattern.rs (line 171)
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
pub fn score_of(&self, candidate: Candidate) -> Option<i32> {
match self {
Self::NameExact(ep) => ep.score_of(candidate.name),
Self::NameFuzzy(fp) => fp.score_of(candidate.name),
Self::NameRegex(rp) => rp.find(candidate.name).map(|m| m.score),
Self::NameTokens(tp) => tp.score_of(candidate.name),
Self::PathExact(ep) => ep.score_of(candidate.subpath),
Self::PathFuzzy(fp) => fp.score_of(candidate.subpath),
Self::PathRegex(rp) => rp.find(candidate.subpath).map(|m| m.score),
Self::PathTokens(tp) => tp.score_of(candidate.subpath),
Self::ContentExact(cp) => cp.score_of(candidate),
Self::ContentRegex(cp) => cp.score_of(candidate),
Self::Composite(cp) => cp.score_of(candidate),
Self::None => Some(1),
}
}
sourcepub fn search_string(&self, candidate: &str) -> Option<NameMatch>
pub fn search_string(&self, candidate: &str) -> Option<NameMatch>
Examples found in repository?
src/pattern/pattern.rs (line 126)
117 118 119 120 121 122 123 124 125 126 127 128 129
pub fn search_string(
&self,
candidate: &str,
) -> Option<NameMatch> {
match self {
Self::NameExact(ep) | Self::PathExact(ep) => ep.find(candidate),
Self::NameFuzzy(fp) | Self::PathFuzzy(fp) => fp.find(candidate),
Self::NameRegex(rp) | Self::PathRegex(rp) => rp.find(candidate),
Self::NameTokens(tp) | Self::PathTokens(tp) => tp.find(candidate),
Self::Composite(cp) => cp.search_string(candidate),
_ => None,
}
}
sourcepub fn search_content(
&self,
candidate: &Path,
desired_len: usize
) -> Option<ContentMatch>
pub fn search_content(
&self,
candidate: &Path,
desired_len: usize
) -> Option<ContentMatch>
Examples found in repository?
src/pattern/pattern.rs (line 141)
133 134 135 136 137 138 139 140 141 142 143 144
pub fn search_content(
&self,
candidate: &Path,
desired_len: usize, // available space for content match display
) -> Option<ContentMatch> {
match self {
Self::ContentExact(cp) => cp.get_content_match(candidate, desired_len),
Self::ContentRegex(cp) => cp.get_content_match(candidate, desired_len),
Self::Composite(cp) => cp.search_content(candidate, desired_len),
_ => None,
}
}
sourcepub fn get_match_line_count(&self, candidate: &Path) -> Option<usize>
pub fn get_match_line_count(&self, candidate: &Path) -> Option<usize>
sourcepub fn has_real_scores(&self) -> bool
pub fn has_real_scores(&self) -> bool
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Examples found in repository?
src/pattern/pattern.rs (line 207)
199 200 201 202 203 204 205 206 207 208 209 210
pub fn is_empty(&self) -> bool {
match self {
Self::NameExact(ep) | Self::PathExact(ep) => ep.is_empty(),
Self::ContentExact(ep) => ep.is_empty(),
Self::NameFuzzy(fp) | Self::PathFuzzy(fp) => fp.is_empty(),
Self::NameRegex(rp) | Self::PathRegex(rp) => rp.is_empty(),
Self::ContentRegex(rp) => rp.is_empty(),
Self::NameTokens(tp) | Self::PathTokens(tp) => tp.is_empty(),
Self::Composite(cp) => cp.is_empty(),
Self::None => true,
}
}
Trait Implementations§
source§impl Clone for CompositePattern
impl Clone for CompositePattern
source§fn clone(&self) -> CompositePattern
fn clone(&self) -> CompositePattern
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read more