diff options
author | Mario Krehl <mario-krehl@gmx.de> | 2017-12-16 11:52:36 +0100 |
---|---|---|
committer | Mario Krehl <mario-krehl@gmx.de> | 2017-12-16 11:52:36 +0100 |
commit | 4736031a1b46924ac0aff584c74b4fb957f9ff98 (patch) | |
tree | 61ad92ad58f468e21f862dd29f838caf750df6c6 | |
parent | 32cfc8d684b8cda57f122fc13d7b89f9efa2050c (diff) |
Add helper function to get a capture group name out of a target
-rw-r--r-- | src/main.rs | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/src/main.rs b/src/main.rs index 4e4492c..56cf351 100644 --- a/src/main.rs +++ b/src/main.rs @@ -108,26 +108,17 @@ fn hash_map_targets<'a>(c : &'a Config, targets : Vec<Target>) if _res.contains_key(&li.alias()) { if let Some(&mut (_litem, ref mut cnames)) = _res.get_mut(&li.alias()) { cnames.push(( - t.target - .split('.') - .nth(1) - .ok_or(Error::from("no capture name found"))? - .into(), + cname_from_target(&t.target)?, t.target.clone()) - ); + ); } } else { _res.insert( li.alias(), - (&li, vec![( - t.target - .split('.') - .nth(1) - .ok_or(Error::from("no capture name found"))? - .into(), - t.target.clone()) - ] + ( + &li, + vec![(cname_from_target(&t.target)?, t.target.clone())] ) ); } @@ -137,6 +128,16 @@ fn hash_map_targets<'a>(c : &'a Config, targets : Vec<Target>) Ok(_res) } +/// splits the target and return the capture name part +fn cname_from_target<'a>(t : &'a String) -> Result<String> { + Ok( + t.split('.') + .nth(1) + .ok_or(Error::from("no capture name found"))? + .into() + ) +} + /// Iterate the hashmap created with the above function fn hash_map_iter(h : HashMap<&String, (&LogItem, Vec<(String, String)>)>, d_from : i64, d_to : i64) -> Result<Vec<TargetData>> { |