summaryrefslogtreecommitdiff
path: root/support/texlab/src/util/regex_filter.rs
blob: a33417464ebb19cfa6d75812297e8101a1d492c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
use regex::Regex;

pub fn filter(text: &str, allowed_patterns: &[Regex], ignored_patterns: &[Regex]) -> bool {
    if !allowed_patterns.is_empty()
        && !allowed_patterns
            .iter()
            .any(|pattern| pattern.is_match(text))
    {
        return false;
    }

    if ignored_patterns
        .iter()
        .any(|pattern| pattern.is_match(text))
    {
        return false;
    }

    true
}