From 1dfd1ae32b9b27573b9ee4439674091b792bcce0 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 16 Aug 2026 20:20:15 +0900 Subject: refactor(preg): make preg_grep() return an iterator Callers had to build a temporary Vec<&str> at every call site to satisfy the &[&str] parameter. Taking IntoIterator and yielding the matched items lets them pass owned or borrowed strings directly. The flags variant and PREG_GREP_INVERT go away with it: no caller passes flags, and Composer's Preg::grep() has no such parameter either. --- crates/shirabe/src/console/application.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'crates/shirabe/src/console/application.rs') diff --git a/crates/shirabe/src/console/application.rs b/crates/shirabe/src/console/application.rs index 9033700b..b55b9e68 100644 --- a/crates/shirabe/src/console/application.rs +++ b/crates/shirabe/src/console/application.rs @@ -953,7 +953,8 @@ impl Application { .map(|p| preg_quote(&p, None)) .collect(); let expr = format!("{}{}", shirabe_php_shim::implode("[^:]*:", &parts), "[^:]*"); - let namespaces = preg_grep(format!("{{^{}}}", expr), &all_namespaces); + let namespaces: Vec = + preg_grep(format!("{{^{}}}", expr), all_namespaces.iter().cloned()).collect(); if namespaces.is_empty() { let mut message = format!( @@ -1049,14 +1050,19 @@ impl Application { .map(|p| preg_quote(&p, None)) .collect(); let expr = format!("{}{}", shirabe_php_shim::implode("[^:]*:", &parts), "[^:]*"); - let mut commands = preg_grep(format!("{{^{}}}", expr), &all_commands); + let mut commands: Vec = + preg_grep(format!("{{^{}}}", expr), all_commands.iter().cloned()).collect(); if commands.is_empty() { - commands = preg_grep(format!("{{^{}}}i", expr), &all_commands); + commands = preg_grep(format!("{{^{}}}i", expr), all_commands.iter().cloned()).collect(); } // if no commands matched or we just matched namespaces - if commands.is_empty() || preg_grep(format!("{{^{}$}}i", expr), &commands).is_empty() { + if commands.is_empty() + || preg_grep(format!("{{^{}$}}i", expr), commands.iter()) + .next() + .is_none() + { if let Some(pos) = shirabe_php_shim::strrpos(name, ":") { // check if a namespace exists and contains commands self.find_namespace(&name[..pos])?; -- cgit v1.3.1-4-g156e