diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-08-17 03:23:52 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-08-17 03:23:52 +0900 |
| commit | abffae07ed350ebb1de98edd2ae246ccddfa6085 (patch) | |
| tree | 6c917cc08e39ad95078505951bdea4b9ae538630 /crates/shirabe-pcre | |
| parent | 8b57e90f5c563bbc1a6060d9f5e94b5d3cd91324 (diff) | |
| download | php-shirabe-abffae07ed350ebb1de98edd2ae246ccddfa6085.tar.gz php-shirabe-abffae07ed350ebb1de98edd2ae246ccddfa6085.tar.zst php-shirabe-abffae07ed350ebb1de98edd2ae246ccddfa6085.zip | |
refactor(preg): merge preg_match_all_offset_capture2() into its sibling
The two functions ran the same search and differed only in how they
reported a non-participating group: one as ("", 0) in a bespoke struct,
the other as (null, -1) in a capture-key map. Neither shape covered both
callers, because PHP reaches preg_match_all() with different flags from
each: Preg::matchAllWithOffsets() always ORs in PREG_UNMATCHED_AS_NULL,
while OutputFormatter::formatAndWrap() passes PREG_OFFSET_CAPTURE alone.
Keep the capture-key map, which also exposes named groups, and take the
flags that decide between null and "" for an unmatched group. The offset
is -1 either way, so the ("", 0) approximation is gone.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe-pcre')
| -rw-r--r-- | crates/shirabe-pcre/src/preg.rs | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/crates/shirabe-pcre/src/preg.rs b/crates/shirabe-pcre/src/preg.rs index 822609a9..8fb0c2e8 100644 --- a/crates/shirabe-pcre/src/preg.rs +++ b/crates/shirabe-pcre/src/preg.rs @@ -15,7 +15,7 @@ use indexmap::IndexMap; pub use shirabe_php_shim::CaptureKey; use shirabe_php_shim::{ PREG_OFFSET_CAPTURE, PREG_SET_ORDER, PREG_SPLIT_OFFSET_CAPTURE, PREG_UNMATCHED_AS_NULL, - PregPattern, preg_grep, preg_match_all_offset_capture2, preg_match_all2, preg_match2, + PregPattern, preg_grep, preg_match_all_offset_capture, preg_match_all2, preg_match2, preg_replace_callback, preg_replace2, preg_split2, }; @@ -89,7 +89,8 @@ impl Preg { matches: Option<&mut IndexMap<CaptureKey, Vec<(Option<String>, i64)>>>, ) -> usize { let mut internal: IndexMap<CaptureKey, Vec<(Option<String>, i64)>> = IndexMap::new(); - let result = preg_match_all_offset_capture2(pattern, subject, &mut internal); + let result = + preg_match_all_offset_capture(pattern, subject, &mut internal, PREG_UNMATCHED_AS_NULL); if let Some(out) = matches { *out = internal; |
