From 83f7f2da74430b2df77f6fd3b491771ab3b2ca54 Mon Sep 17 00:00:00 2001 From: mgros Date: Sat, 26 Sep 2026 18:59:35 +0200 Subject: [PATCH] Refactor comma-check logic in `is_leaf_any_name` --- src/xpath_functions.rs | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/src/xpath_functions.rs b/src/xpath_functions.rs index a713fad8..51528dd7 100644 --- a/src/xpath_functions.rs +++ b/src/xpath_functions.rs @@ -864,24 +864,17 @@ impl IsBracketed { return false; } - if requires_comma { - if let ChildOfElement::Element(contents) = children[1] { - let children = contents.children(); - if !is_tag(contents, "mrow") || children.len() <= 1 { - return false; - } - // finally, we can check for a comma -- we might not have operands, so we to check first and second entry - if get_text_from_COE(&children[0]).as_str() == "," { - return true; - } - if children.len() > 1 && get_text_from_COE(&children[1]).as_str() == "," { - return true; - } - } - return false; - } else { + if !requires_comma { return true; } + let Some(contents) = children[1].element() else { + return false; + }; + let children = contents.children(); + // The comma can be the first or second child when operands are absent. + return is_tag(contents, "mrow") + && children.len() > 1 + && (get_text_from_COE(&children[0]) == "," || get_text_from_COE(&children[1]) == ","); } }