From 2c1203f6f2c3e6bbaf527fa202425ed465e89d69 Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 10 Sep 2018 00:40:29 +0200 Subject: move filtering into own submodule --- src/filters.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/filters.rs (limited to 'src/filters.rs') diff --git a/src/filters.rs b/src/filters.rs new file mode 100644 index 0000000..1549c26 --- /dev/null +++ b/src/filters.rs @@ -0,0 +1,33 @@ +use evtclib::{AgentName, Log}; + +use super::{LogResult, Opt}; + +/// Do filtering based on the character or account name. +pub fn filter_name(log: &Log, opt: &Opt) -> bool { + for player in log.players() { + match player.name() { + AgentName::Player { + account_name, + character_name, + .. + } => { + if (opt.field.search_account() && opt.expression.is_match(account_name)) + || (opt.field.search_character() && opt.expression.is_match(character_name)) + { + return true; + } + } + _ => unreachable!(), + } + } + return false; +} + +/// Do filtering based on the fight outcome. +pub fn filter_outcome(result: &LogResult, opt: &Opt) -> bool { + match opt.outcome { + Some(o) if o == result.outcome => true, + None => true, + _ => false, + } +} -- cgit v1.2.3