From abffae07ed350ebb1de98edd2ae246ccddfa6085 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Mon, 17 Aug 2026 03:23:52 +0900 Subject: 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) --- crates/shirabe-pcre/src/preg.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'crates/shirabe-pcre') 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, i64)>>>, ) -> usize { let mut internal: IndexMap, 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; -- cgit v1.3.1-4-g156e