From 0ff4af447d3b40d715d4adb8967d4d01776b6c05 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Tue, 18 Dec 2018 21:48:45 +0100 Subject: Make regex matches case insensitive. --- src/main.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 0c1a240..060dd84 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,7 +16,7 @@ use ical; use chrono::{DateTime, TimeZone, Utc}; -use regex::Regex; +use regex::RegexBuilder; use std::fs::File; use std::io::BufReader; @@ -71,7 +71,10 @@ fn match_event(event: &ical::parser::ical::component::IcalEvent, pattern: &str) let parts: Vec<&str> = pattern.split(':').collect(); let (key, pat) = (parts[0].to_uppercase(), parts[1]); - let re = Regex::new(&pat).unwrap(); + let re = RegexBuilder::new(&pat) + .case_insensitive(true) + .build() + .unwrap(); event.properties.iter() .filter(|ref p| p.name == key && re.is_match(&p.value.clone().unwrap())) @@ -112,6 +115,12 @@ fn match_events_by_regex() { assert_eq!(1, events.len()); } +#[test] +fn match_events_regardless_of_case() { + let events:Vec<_> = test_match_event_helper("summary:^aLl.+1$"); + assert_eq!(1, events.len()); +} + fn main() { let mut args = std::env::args().skip(1); let filename = args.next().unwrap(); -- cgit v1.2.3