debian_analyzer/
rules.rs

1//! This module provides functions to manipulate debian/rules file.
2
3/// Add a particular value to a with argument.
4pub fn dh_invoke_add_with(line: &str, with_argument: &str) -> String {
5    if line.contains(with_argument) {
6        return line.to_owned();
7    }
8    if !line.contains(" --with") {
9        return format!("{} --with={}", line, with_argument);
10    }
11
12    lazy_regex::regex_replace!(
13        r"([ \t])--with([ =])([^ \t]+)",
14        line,
15        |_, head, with, tail| format!("{}--with={},{}{}", head, with_argument, with, tail)
16    )
17    .to_string()
18}
19
20/// Obtain the value of a with argument.
21pub fn dh_invoke_get_with(line: &str) -> Vec<String> {
22    let mut ret = Vec::new();
23    for m in lazy_regex::regex!("[ \t]--with[ =]([^ \t]+)").find_iter(line) {
24        ret.extend(m.as_str().split(',').map(|s| s.to_owned()));
25    }
26    ret
27}