diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-08-17 06:43:52 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-08-17 06:43:52 +0900 |
| commit | 52a0665acbbe5bf5b8c6875118fb9cdf7952453b (patch) | |
| tree | 7302b0b87f7b0d406126da734ef82c80abf64204 /crates/shirabe-class-map-generator/src/php_file_cleaner.rs | |
| parent | c81e9f89d9e4388f36a4427bbaa95eced659d2ce (diff) | |
| download | php-shirabe-52a0665acbbe5bf5b8c6875118fb9cdf7952453b.tar.gz php-shirabe-52a0665acbbe5bf5b8c6875118fb9cdf7952453b.tar.zst php-shirabe-52a0665acbbe5bf5b8c6875118fb9cdf7952453b.zip | |
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<usize> 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.
Diffstat (limited to 'crates/shirabe-class-map-generator/src/php_file_cleaner.rs')
| -rw-r--r-- | crates/shirabe-class-map-generator/src/php_file_cleaner.rs | 10 |
1 files changed, 5 insertions, 5 deletions
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<CaptureKey, String> = 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<CaptureKey, String> = 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<CaptureKey, String> = 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<CaptureKey, String>>) -> bool { + fn r#match(&self, regex: &str, r#match: Option<&mut PregMatchedGroups>) -> bool { Preg::is_match4(regex, &self.contents, r#match, self.index) } } |
