aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2018-12-18 21:48:45 +0100
committerHarald Eilertsen <haraldei@anduin.net>2018-12-18 21:49:25 +0100
commit0ff4af447d3b40d715d4adb8967d4d01776b6c05 (patch)
tree47214d4a46a722f0aaf8d3df6b693dddad424b12
parentd33fbac4a8278cb4b17a7ea8ec6fb54c27166b1a (diff)
downloadicaltool-0ff4af447d3b40d715d4adb8967d4d01776b6c05.tar.gz
icaltool-0ff4af447d3b40d715d4adb8967d4d01776b6c05.tar.bz2
icaltool-0ff4af447d3b40d715d4adb8967d4d01776b6c05.zip
Make regex matches case insensitive.
-rw-r--r--src/main.rs13
1 files 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();