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-pcre/src/preg.rs | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) (limited to 'crates/shirabe-pcre/src') diff --git a/crates/shirabe-pcre/src/preg.rs b/crates/shirabe-pcre/src/preg.rs index 06586d2c..1c6fbfc1 100644 --- a/crates/shirabe-pcre/src/preg.rs +++ b/crates/shirabe-pcre/src/preg.rs @@ -155,26 +155,16 @@ impl Preg { } pub fn replace_callback) -> String>( - pattern: impl PregPattern, - replacement: F, - subject: &str, - ) -> String { - Self::replace_callback6(pattern, replacement, subject, -1, None, 0) - } - - pub fn replace_callback6) -> String>( pattern: impl PregPattern, mut replacement: F, subject: &str, - limit: i64, - count: Option<&mut usize>, - flags: i64, ) -> String { - let adapter = |internal: &IndexMap>| -> String { - replacement(&drop_null_matches_ref(internal)) + let adapter = |internal: &IndexMap>| { + Ok(replacement(&drop_null_matches_ref(internal))) }; - shirabe_php_shim::preg_replace_callback2(pattern, adapter, subject, limit, count, flags) + shirabe_php_shim::preg_replace_callback(pattern, adapter, subject) + .expect("$replacement cannot fail") } pub fn split(pattern: impl PregPattern, subject: &str) -> Vec { -- cgit v1.3.1-4-g156e