Expand description
A NameMatch is a positive result of pattern matching inside a filename or subpath
Fields§
§score: i32
§pos: Pos
Implementations§
source§impl NameMatch
impl NameMatch
sourcepub fn wrap(&self, name: &str, match_start: &str, match_end: &str) -> String
pub fn wrap(&self, name: &str, match_start: &str, match_end: &str) -> String
wraps any group of matching characters with match_start and match_end
Examples found in repository?
src/help/help_verbs.rs (line 58)
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
pub fn matching_verb_rows<'v>(
pat: &Pattern,
con: &'v AppContext,
) -> Vec<MatchingVerbRow<'v>> {
let mut rows = Vec::new();
for verb in &con.verb_store.verbs {
if !verb.show_in_doc {
continue;
}
let mut name = None;
let mut shortcut = None;
if pat.is_some() {
let mut ok = false;
name = verb.names.get(0).and_then(|s| {
pat.search_string(s).map(|nm| {
ok = true;
nm.wrap(s, "**", "**")
})
});
shortcut = verb.names.get(1).and_then(|s| {
pat.search_string(s).map(|nm| {
ok = true;
nm.wrap(s, "**", "**")
})
});
if !ok {
continue;
}
}
rows.push(MatchingVerbRow {
name,
shortcut,
verb,
});
}
rows
}
sourcepub fn cut_after(&mut self, chars_count: usize) -> Self
pub fn cut_after(&mut self, chars_count: usize) -> Self
Examples found in repository?
src/display/matched_string.rs (line 52)
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
pub fn split_on_last(&mut self, sep: char) -> Option<Self> {
if self.display_width.is_some() {
// the proper algo would need measuring the left part I guess
None
} else {
self.string
.rfind(sep)
.map(|sep_idx| {
let right = &self.string[sep_idx+1..];
self.string = &self.string[..sep_idx+1];
let left_chars_count = self.string.chars().count();
let right_name_match = self.name_match.as_mut()
.map(|nm| nm.cut_after(left_chars_count));
MatchedString {
name_match: right_name_match,
string: right,
base_style: self.base_style,
match_style: self.match_style,
display_width: None,
align: self.align,
}
})
}
}