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 ical = Regex::new(
+ r"^\s*([\[\(#]+)[A-C][0-9]*([\]\)]+)\s*").unwrap();
if DEBUG { eprintln!( // debug patterns
- "Matches first item: '{}', '{}', '{}'",
+ "Matches first item: '{}', '{}', '{}', '{}'",
match bullet.captures(&list[0]){
None => "",
Some(x) => x.get(0).unwrap().as_str()},
Some(x) => x.get(0).unwrap().as_str()},
match prio.captures(&list[0]){
None => "",
- Some(x) => x.get(0).unwrap().as_str()});}
+ Some(x) => x.get(0).unwrap().as_str()},
+ match ical.captures(
+ & {let tmp = bullet.replace(&list[0], "");
+ let tmp = number.replace(&tmp, "");
+ prio.replace(&tmp, "").into_owned()} ){
+ None => "",
+ Some(x) => x.get(0).unwrap().as_str()},
+ ) };
// Use index of the longest relevant group match to create conf
// template. Call this "the rule of index of the longest match".
x.get(1).unwrap().as_str(),
x.get(3).unwrap().as_str())
},
+ ical: match ical.captures(
+ & {let tmp = bullet.replace(&list[0], "");
+ let tmp = number.replace(&tmp, "");
+ prio.replace(&tmp, "").into_owned()} ){
+ None => "".to_string(),
+ Some(x) => format!(
+ "{}{{}}{}",
+ x.get(1).unwrap().as_str(),
+ x.get(2).unwrap().as_str())
+ },
};
if DEBUG {
*l = bullet.replace_all(&l, "").to_string();
*l = number.replace_all(&l, "").to_string();
*l = prio.replace_all(&l, "").to_string();
+ *l = ical.replace_all(&l, "").to_string();
*l = l.trim().to_owned();
}
list.retain(|x| x != ""); // again
pub struct Conf {
bullet: String,
number: String,
+ ical: String,
}
#[derive(Parser, Debug)]
#[test]
+fn icalinput() {
+
+ let arg: Vec<String> =
+ "(A) Hej du\n(B2) glade (C)\nta en"
+ .split("\n").map(|x| x.to_owned()).collect();
+ let exp: Vec<String> =
+ "Hej du\nglade (C)\nta en"
+ .split("\n").map(|x| x.to_owned()).collect();
+ let(conf, res) = winnow(arg);
+ assert_eq!(exp, res);
+ assert_eq!(conf.ical, "({})");
+}
+
+#[test]
+
fn bullout() {
let conf = Conf {
bullet: " * ".to_owned(),
- number: "".to_owned()};
+ number: "".to_owned(),
+ ical: "".to_owned(),
+ };
let prio = vec![0.6, 0.3, 0.1];
let ranked: Vec<String> =
"Hej du\nglade\nta en"