diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2018-12-18 21:35:07 +0100 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2018-12-18 21:37:39 +0100 |
commit | d33fbac4a8278cb4b17a7ea8ec6fb54c27166b1a (patch) | |
tree | 09d7821c348c92f87982abeb245ecf71164ee9e2 /src | |
parent | 35227ce437838bc8d0664ff21c2826679b8b9d4f (diff) | |
download | icaltool-d33fbac4a8278cb4b17a7ea8ec6fb54c27166b1a.tar.gz icaltool-d33fbac4a8278cb4b17a7ea8ec6fb54c27166b1a.tar.bz2 icaltool-d33fbac4a8278cb4b17a7ea8ec6fb54c27166b1a.zip |
Use regex for matching values.
Decided on the regex crate to begin with. An alternative with a more
complete regex implementation is the onig crate. If we find we need
more powerful regexes, we may switch to that later.
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs index a7747c7..0c1a240 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,6 +16,7 @@ use ical; use chrono::{DateTime, TimeZone, Utc}; +use regex::Regex; use std::fs::File; use std::io::BufReader; @@ -70,8 +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(); + event.properties.iter() - .filter(|ref p| p.name == key && p.value.clone().unwrap().matches(&pat).count() > 0) + .filter(|ref p| p.name == key && re.is_match(&p.value.clone().unwrap())) .count() > 0 } } @@ -103,6 +106,12 @@ fn match_events_by_summary() { assert_eq!(2, events.len()); } +#[test] +fn match_events_by_regex() { + 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(); |