From 24a4f39bd981768cc299121b506f6bba584cb31d Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 16 Aug 2026 17:58:11 +0900 Subject: refactor(preg): merge preg_replace_callback2 into preg_replace_callback preg_replace_callback2 had one caller, Preg::replace_callback6, which was itself reached only from Preg::replace_callback with the default limit, count and flags. Fold the two shim functions into one and drop those parameters along with replace_callback6. The surviving callback takes callback2's IndexMap of matches: it can be keyed by group name, and it omits trailing non-participating groups the way PHP does, which is what the callbacks in Process and ProgressBar test for. --- crates/shirabe-symfony-console/src/helper/progress_bar.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'crates/shirabe-symfony-console/src/helper/progress_bar.rs') diff --git a/crates/shirabe-symfony-console/src/helper/progress_bar.rs b/crates/shirabe-symfony-console/src/helper/progress_bar.rs index b0124419..dea1c3ad 100644 --- a/crates/shirabe-symfony-console/src/helper/progress_bar.rs +++ b/crates/shirabe-symfony-console/src/helper/progress_bar.rs @@ -9,6 +9,7 @@ use crate::output::OutputInterface; use crate::output::output_interface; use crate::terminal::Terminal; use indexmap::IndexMap; +use shirabe_php_shim::CaptureKey; pub const FORMAT_VERBOSE: &str = "verbose"; pub const FORMAT_VERY_VERBOSE: &str = "very_verbose"; @@ -797,8 +798,8 @@ impl ProgressBar { let format = self.format.clone().unwrap_or_default(); // $callback in PHP, expressed as a closure over $this and the matches. - let callback = |matches: &[Option]| -> anyhow::Result { - let name = matches[1].clone().unwrap_or_default(); + let callback = |matches: &IndexMap>| -> anyhow::Result { + let name = matches[&CaptureKey::ByIndex(1)].clone().unwrap_or_default(); let text: shirabe_php_shim::PhpMixed = if Self::get_placeholder_formatter_definition(&name).is_some() { @@ -812,10 +813,10 @@ impl ProgressBar { } else if let Some(message) = self.messages.get(&name) { shirabe_php_shim::PhpMixed::String(message.clone()) } else { - return Ok(matches[0].clone().unwrap_or_default()); + return Ok(matches[&CaptureKey::ByIndex(0)].clone().unwrap_or_default()); }; - if let Some(modifier) = matches.get(2).and_then(|m| m.clone()) { + if let Some(modifier) = matches.get(&CaptureKey::ByIndex(2)).and_then(|m| m.clone()) { return Ok(shirabe_php_shim::sprintf(&format!("%{modifier}"), &[text])); } -- cgit v1.3.1-4-g156e