list.retain(|x| x != ""); // only keep nonempty
- // Search patterns
+ // Search patterns. Find pipe tables as a bullet item
- let bullet = Regex::new(r"^(\s*[\*-]\s*)").unwrap();
+ let bullet = Regex::new(r"^(\s*[\*|-]\s*)").unwrap();
let number = Regex::new(r"^(\s*)([0-9]+)([).]\s*)").unwrap();
- let prio = Regex::new(r"^\s*[0-9]+\s*%\s*").unwrap();
+ let prio = Regex::new(r"^\s*[0-9]+\s*%[|\s]*").unwrap();
if DEBUG { eprintln!( // debug patterns
"Matches first item: '{}', '{}', '{}'",
for (i, (p, l)) in prio.iter().zip(ranked).enumerate() {
- let item = if conf.number != "" {
+ let pre = if conf.number != "" {
conf.number.replace("{}", format!( // Replace template due
"{:digs$}", i + 1).as_str()) // to smt::fmt
} else {
conf.bullet.clone()
};
+ let pst = if conf.bullet.contains("|") {" | "} else {"\t"};
- println!("{}{:2.0} %\t{}", item, 100.0 * p, l)
+ println!("{}{:2.0} %{}{}", pre, 100.0 * p, pst, l)
}
}
#[test]
+fn pipe() {
+
+ let arg: Vec<String> =
+ "\n| Hej du\n | glade\n| ta en\n"
+ .split("\n").map(|x| x.to_owned())
+ .collect();
+ let exp: Vec<String> =
+ "Hej du\nglade\nta en"
+ .split("\n").map(|x| x.to_owned()).collect();
+ let (conf, res) = winnow(arg);
+ assert_eq!(exp, res);
+ assert_eq!(conf.bullet, " | ".to_owned());
+ assert_eq!(conf.number, "".to_owned());
+}
+
+#[test]
+
fn bullout() {
let conf = Conf {