diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-08-16 17:58:11 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-08-16 17:58:11 +0900 |
| commit | 24a4f39bd981768cc299121b506f6bba584cb31d (patch) | |
| tree | 39c9de717f5ca374e2c4df9b7eaeb0f86b11da0b /crates/shirabe-pcre/src | |
| parent | 224d3e8262ed6156ea3374fe91dfb5b66d6f0d3a (diff) | |
| download | php-shirabe-24a4f39bd981768cc299121b506f6bba584cb31d.tar.gz php-shirabe-24a4f39bd981768cc299121b506f6bba584cb31d.tar.zst php-shirabe-24a4f39bd981768cc299121b506f6bba584cb31d.zip | |
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.
Diffstat (limited to 'crates/shirabe-pcre/src')
| -rw-r--r-- | crates/shirabe-pcre/src/preg.rs | 18 |
1 files changed, 4 insertions, 14 deletions
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 @@ -156,25 +156,15 @@ impl Preg { pub fn replace_callback<F: FnMut(&IndexMap<CaptureKey, String>) -> String>( pattern: impl PregPattern, - replacement: F, - subject: &str, - ) -> String { - Self::replace_callback6(pattern, replacement, subject, -1, None, 0) - } - - pub fn replace_callback6<F: FnMut(&IndexMap<CaptureKey, String>) -> String>( - pattern: impl PregPattern, mut replacement: F, subject: &str, - limit: i64, - count: Option<&mut usize>, - flags: i64, ) -> String { - let adapter = |internal: &IndexMap<CaptureKey, Option<String>>| -> String { - replacement(&drop_null_matches_ref(internal)) + let adapter = |internal: &IndexMap<CaptureKey, Option<String>>| { + 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<String> { |
