diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-08-17 03:43:21 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-08-17 03:43:21 +0900 |
| commit | 879affc50810e1ebb20687265a9a4e9801e21af2 (patch) | |
| tree | 00207618f49b31f391e7a1cb83dd7fc713dcfa16 /crates | |
| parent | abffae07ed350ebb1de98edd2ae246ccddfa6085 (diff) | |
| download | php-shirabe-879affc50810e1ebb20687265a9a4e9801e21af2.tar.gz php-shirabe-879affc50810e1ebb20687265a9a4e9801e21af2.tar.zst php-shirabe-879affc50810e1ebb20687265a9a4e9801e21af2.zip | |
refactor(preg): drop pass-through private helpers
match_all5() was identical to match_all3(), and replace_impl() only
forwarded its arguments to preg_replace2(). Call the destinations
directly.
Diffstat (limited to 'crates')
| -rw-r--r-- | crates/shirabe-pcre/src/preg.rs | 31 |
1 files changed, 5 insertions, 26 deletions
diff --git a/crates/shirabe-pcre/src/preg.rs b/crates/shirabe-pcre/src/preg.rs index 8fb0c2e8..10ed1d5b 100644 --- a/crates/shirabe-pcre/src/preg.rs +++ b/crates/shirabe-pcre/src/preg.rs @@ -57,7 +57,7 @@ impl Preg { } pub fn match_all(pattern: impl PregPattern, subject: &str) -> usize { - Self::match_all5(pattern, subject, None) + Self::match_all3(pattern, subject, None) } pub fn match_all3( @@ -65,14 +65,6 @@ impl Preg { subject: &str, matches: Option<&mut IndexMap<CaptureKey, Vec<Option<String>>>>, ) -> usize { - Self::match_all5(pattern, subject, matches) - } - - fn match_all5( - pattern: impl PregPattern, - subject: &str, - matches: Option<&mut IndexMap<CaptureKey, Vec<Option<String>>>>, - ) -> usize { let mut internal: IndexMap<CaptureKey, Vec<Option<String>>> = IndexMap::new(); let result = preg_match_all2(pattern, subject, &mut internal); @@ -100,7 +92,7 @@ impl Preg { } pub fn replace(pattern: impl PregPattern, replacement: &str, subject: &str) -> String { - Self::replace_impl(pattern, replacement, subject, -1, None) + preg_replace2(pattern, replacement, subject, -1, None) } pub fn replace4( @@ -109,7 +101,7 @@ impl Preg { subject: &str, limit: i64, ) -> String { - Self::replace_impl(pattern, replacement, subject, limit, None) + preg_replace2(pattern, replacement, subject, limit, None) } pub fn replace5( @@ -119,20 +111,7 @@ impl Preg { limit: i64, count: &mut usize, ) -> String { - Self::replace_impl(pattern, replacement, subject, limit, Some(count)) - } - - fn replace_impl( - pattern: impl PregPattern, - replacement: &str, - subject: &str, - limit: i64, - count: Option<&mut usize>, - ) -> String { - // `$subject` is statically a string here, so the is_scalar/is_array - // guards (ARRAY_MSG / INVALID_TYPE_MSG) of the PHP original are - // unreachable and not reproduced. - preg_replace2(pattern, replacement, subject, limit, count) + preg_replace2(pattern, replacement, subject, limit, Some(count)) } pub fn replace_callback<F: FnMut(&IndexMap<CaptureKey, String>) -> String>( @@ -246,7 +225,7 @@ impl Preg { subject: &str, matches: Option<&mut IndexMap<CaptureKey, Vec<Option<String>>>>, ) -> bool { - Self::match_all5(pattern, subject, matches) > 0 + Self::match_all3(pattern, subject, matches) > 0 } pub fn is_match_all_with_offsets3( |
