Function broot::pattern::norm_chars
source · Examples found in repository?
src/pattern/tok_pattern.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
pub fn new(pattern: &str) -> Self {
// we accept several separators. The first one
// we encounter among the possible ones is the
// separator of the whole. This allows using the
// other char: In ";ab,er", the comma isn't seen
// as a separator but as part of a tok
let sep = pattern.chars().find(|c| SEPARATORS.contains(c));
let mut toks: Vec<Box<[char]>> = if let Some(sep) = sep {
pattern.split(sep)
.filter(|s| !s.is_empty())
.map(norm_chars)
.collect()
} else {
if pattern.is_empty() {
Vec::new()
} else {
vec![norm_chars(pattern)]
}
};
// we sort the tokens from biggest to smallest
// because the current algorithm stops at the
// first match for any tok. Thus it would fail
// to find "abc,b" in "abcdb" if it looked first
// at the "b" token
toks.sort_by_key(|t| Reverse(t.len()));
let sum_len = toks.iter().map(|s| s.len()).sum();
Self {
toks,
sum_len,
}
}