From 52a0665acbbe5bf5b8c6875118fb9cdf7952453b Mon Sep 17 00:00:00 2001 From: nsfisis Date: Mon, 17 Aug 2026 06:43:52 +0900 Subject: refactor(preg): wrap the preg_* $matches maps in newtypes The five IndexMap shapes that the preg_* functions and Preg fill in are now distinct types generated by preg_match_map!, so a matches map no longer interchanges with any other map of the same key and value type. Index is kept alongside Index<&Q> because call sites such as config_command and event_dispatcher reach for a group by its position in the map rather than by its capture key. --- crates/shirabe-class-map-generator/src/php_file_cleaner.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'crates/shirabe-class-map-generator/src/php_file_cleaner.rs') diff --git a/crates/shirabe-class-map-generator/src/php_file_cleaner.rs b/crates/shirabe-class-map-generator/src/php_file_cleaner.rs index c5952389..78041061 100644 --- a/crates/shirabe-class-map-generator/src/php_file_cleaner.rs +++ b/crates/shirabe-class-map-generator/src/php_file_cleaner.rs @@ -1,7 +1,7 @@ //! ref: composer/vendor/composer/class-map-generator/src/PhpFileCleaner.php use indexmap::IndexMap; -use shirabe_pcre::{CaptureKey, Preg}; +use shirabe_pcre::{CaptureKey, Preg, PregMatchedGroups}; use std::sync::Mutex; #[derive(Debug, Clone)] @@ -97,7 +97,7 @@ impl PhpFileCleaner { } if char == '<' && self.peek('<') { - let mut r#match: IndexMap = IndexMap::new(); + let mut r#match = PregMatchedGroups::new(); // Regex pattern compatibility: // PHP matches `<<<`, an optional quote, the identifier, then requires the // closing quote to be the exact same character via `\1`. The `regex` crate has @@ -144,7 +144,7 @@ impl PhpFileCleaner { let end = self.index + entry.length; if end <= self.len && self.contents[self.index..end] == entry.name { let offset = if self.index > 0 { self.index - 1 } else { 0 }; - let mut r#match: IndexMap = IndexMap::new(); + let mut r#match = PregMatchedGroups::new(); if Preg::is_match4( &entry.pattern, &self.contents, @@ -164,7 +164,7 @@ impl PhpFileCleaner { self.index += 1; let rest_pattern = REST_PATTERN.lock().unwrap().clone(); if let Some(rest_pattern) = rest_pattern { - let mut r#match: IndexMap = IndexMap::new(); + let mut r#match = PregMatchedGroups::new(); if self.r#match(&rest_pattern, Some(&mut r#match)) { let m0 = r#match .get(&CaptureKey::ByIndex(0)) @@ -292,7 +292,7 @@ impl PhpFileCleaner { self.index + 1 < self.len && self.contents.as_bytes()[self.index + 1] as char == char } - fn r#match(&self, regex: &str, r#match: Option<&mut IndexMap>) -> bool { + fn r#match(&self, regex: &str, r#match: Option<&mut PregMatchedGroups>) -> bool { Preg::is_match4(regex, &self.contents, r#match, self.index) } } -- cgit v1.3.1-4-g156e