From 5ab5fafd8f3cab7f82c11e7ad89f8fefd66e911c Mon Sep 17 00:00:00 2001 From: HampusM Date: Sun, 26 Feb 2023 14:45:20 +0100 Subject: feat: add multiple description support --- src/xml/element.rs | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'src/xml') diff --git a/src/xml/element.rs b/src/xml/element.rs index b778dac..91e4130 100644 --- a/src/xml/element.rs +++ b/src/xml/element.rs @@ -24,26 +24,6 @@ impl Elements }) } - pub fn get_first_tagged_with_name_and_attr( - &self, - tag_name: &str, - attribute: &Attribute, - ) -> Option<&Tagged> - { - self.elements.iter().find_map(|element| match element { - Element::Tagged(tagged_element) - if tagged_element.name == tag_name - && tagged_element - .attributes - .iter() - .any(|attr| attr == attribute) => - { - Some(tagged_element) - } - _ => None, - }) - } - pub fn get_all_tagged_elements(&self) -> Vec<&Tagged> { self.elements @@ -68,6 +48,26 @@ impl Elements .collect() } + pub fn get_all_tagged_with_name_and_attr( + &self, + tag_name: &str, + attr_is_match: fn(&Attribute) -> bool, + ) -> Vec<&Tagged> + { + self.elements + .iter() + .filter_map(|element| match element { + Element::Tagged(tagged_element) + if tagged_element.name == tag_name + && tagged_element.attributes.iter().any(attr_is_match) => + { + Some(tagged_element) + } + _ => None, + }) + .collect() + } + pub fn get_first_text_element(&self) -> Option<&String> { self.elements.iter().find_map(|element| match element { -- cgit v1.2.3-18-g5258