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 | |
| 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')
61 files changed, 351 insertions, 270 deletions
diff --git a/crates/shirabe-class-map-generator/src/class_map_generator.rs b/crates/shirabe-class-map-generator/src/class_map_generator.rs index 2207416b..478781c8 100644 --- a/crates/shirabe-class-map-generator/src/class_map_generator.rs +++ b/crates/shirabe-class-map-generator/src/class_map_generator.rs @@ -3,8 +3,7 @@ use crate::class_map::ClassMap; use crate::file_list::FileList; use crate::php_file_parser::PhpFileParser; -use indexmap::indexmap; -use shirabe_pcre::{CaptureKey, Preg}; +use shirabe_pcre::{CaptureKey, Preg, PregMatchedGroups}; use shirabe_php_shim::{ InvalidArgumentException, LogicException, PATHINFO_EXTENSION, RuntimeException, explode, getcwd, implode, is_dir, is_file, pathinfo, php_regex, preg_quote, realpath, str_replace, @@ -348,7 +347,7 @@ impl ClassMapGenerator { } // extract a prefix being a protocol://, protocol:, protocol://drive: or simply drive: - let mut r#match: indexmap::IndexMap<_, _> = indexmap![]; + let mut r#match = PregMatchedGroups::new(); if Preg::is_match3( php_regex!(r"{^( [0-9a-z]{2,}+: (?: // (?: [a-z]: )? )? | [a-z]: )}ix"), &path, 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) } } diff --git a/crates/shirabe-class-map-generator/src/php_file_parser.rs b/crates/shirabe-class-map-generator/src/php_file_parser.rs index b35988fb..a1207140 100644 --- a/crates/shirabe-class-map-generator/src/php_file_parser.rs +++ b/crates/shirabe-class-map-generator/src/php_file_parser.rs @@ -1,8 +1,7 @@ //! ref: composer/vendor/composer/class-map-generator/src/PhpFileParser.php use crate::php_file_cleaner::PhpFileCleaner; -use indexmap::IndexMap; -use shirabe_pcre::{CaptureKey, Preg}; +use shirabe_pcre::{CaptureKey, Preg, PregMatchesAll}; use shirabe_php_shim::{ PHP_EOL, RuntimeException, file_exists, file_get_contents, function_exists, is_file, is_readable, ltrim, php_strip_whitespace, str_replace_array, strrpos, substr, trim, @@ -85,7 +84,7 @@ impl PhpFileParser { }}ix", et = extra_types ); - let mut matches: IndexMap<_, _> = IndexMap::new(); + let mut matches = PregMatchesAll::new(); Preg::match_all2(&pattern2, &contents, &mut matches); let mut classes = vec![]; diff --git a/crates/shirabe-pcre/src/preg.rs b/crates/shirabe-pcre/src/preg.rs index 0448f81a..3a997ad3 100644 --- a/crates/shirabe-pcre/src/preg.rs +++ b/crates/shirabe-pcre/src/preg.rs @@ -11,13 +11,24 @@ //! //! See docs/dev/regex-porting.md for more detailed regex porting rules. -use indexmap::IndexMap; -pub use shirabe_php_shim::CaptureKey; +pub use shirabe_php_shim::{CaptureKey, PregMatches, PregMatchesAll, PregMatchesAllWithOffsets}; use shirabe_php_shim::{ PregPattern, preg_grep, preg_match_all_offset_capture_unmatched_as_null, preg_match_all2, - preg_match2, preg_match2_unmatched_as_null, preg_replace_callback, preg_replace2, + preg_match_map, preg_match2, preg_match2_unmatched_as_null, preg_replace_callback, + preg_replace2, }; +preg_match_map! { + /// A single match's `$matches` as `Preg` hands it to callers: an unmatched capture group is + /// absent rather than held as a null value. + pub struct PregMatchedGroups(CaptureKey => String); +} + +preg_match_map! { + /// The named capture groups of a single match, keyed by group name alone. + pub struct PregNamedGroups(String => String); +} + #[derive(Debug)] pub struct Preg; @@ -25,7 +36,7 @@ impl Preg { pub fn match3( pattern: impl PregPattern, subject: &str, - matches: Option<&mut IndexMap<CaptureKey, String>>, + matches: Option<&mut PregMatchedGroups>, ) -> bool { Self::match4(pattern, subject, matches, 0) } @@ -33,10 +44,10 @@ impl Preg { pub fn match4( pattern: impl PregPattern, subject: &str, - matches: Option<&mut IndexMap<CaptureKey, String>>, + matches: Option<&mut PregMatchedGroups>, offset: usize, ) -> bool { - let mut internal: IndexMap<CaptureKey, Option<String>> = IndexMap::new(); + let mut internal = PregMatches::new(); let result = preg_match2_unmatched_as_null(pattern, subject, &mut internal, offset); if let Some(out) = matches { @@ -47,14 +58,14 @@ impl Preg { } pub fn match_all(pattern: impl PregPattern, subject: &str) -> usize { - let mut dummy = IndexMap::new(); + let mut dummy = PregMatchesAll::new(); preg_match_all2(pattern, subject, &mut dummy) } pub fn match_all2( pattern: impl PregPattern, subject: &str, - matches: &mut IndexMap<CaptureKey, Vec<Option<String>>>, + matches: &mut PregMatchesAll, ) -> usize { preg_match_all2(pattern, subject, matches) } @@ -62,9 +73,9 @@ impl Preg { fn match_all_with_offsets5( pattern: impl PregPattern, subject: &str, - matches: Option<&mut IndexMap<CaptureKey, Vec<(Option<String>, i64)>>>, + matches: Option<&mut PregMatchesAllWithOffsets>, ) -> usize { - let mut internal: IndexMap<CaptureKey, Vec<(Option<String>, i64)>> = IndexMap::new(); + let mut internal = PregMatchesAllWithOffsets::new(); let result = preg_match_all_offset_capture_unmatched_as_null(pattern, subject, &mut internal); @@ -98,14 +109,12 @@ impl Preg { preg_replace2(pattern, replacement, subject, limit, Some(count)) } - pub fn replace_callback<F: FnMut(&IndexMap<CaptureKey, String>) -> String>( + pub fn replace_callback<F: FnMut(&PregMatchedGroups) -> String>( pattern: impl PregPattern, mut replacement: F, subject: &str, ) -> String { - let adapter = |internal: &IndexMap<CaptureKey, Option<String>>| { - Ok(replacement(&drop_null_matches_ref(internal))) - }; + let adapter = |internal: &PregMatches| Ok(replacement(&drop_null_matches_ref(internal))); preg_replace_callback(pattern, adapter, subject).expect("$replacement cannot fail") } @@ -124,7 +133,7 @@ impl Preg { pub fn is_match3( pattern: impl PregPattern, subject: &str, - matches: Option<&mut IndexMap<CaptureKey, String>>, + matches: Option<&mut PregMatchedGroups>, ) -> bool { Self::match4(pattern, subject, matches, 0) } @@ -132,7 +141,7 @@ impl Preg { pub fn is_match4( pattern: impl PregPattern, subject: &str, - matches: Option<&mut IndexMap<CaptureKey, String>>, + matches: Option<&mut PregMatchedGroups>, offset: usize, ) -> bool { Self::match4(pattern, subject, matches, offset) @@ -141,9 +150,9 @@ impl Preg { pub fn is_match_named( pattern: impl PregPattern, subject: &str, - matches: &mut IndexMap<String, String>, + matches: &mut PregNamedGroups, ) -> bool { - let mut internal: IndexMap<CaptureKey, Option<String>> = IndexMap::new(); + let mut internal = PregMatches::new(); let result = preg_match2_unmatched_as_null(pattern, subject, &mut internal, 0); matches.clear(); @@ -162,7 +171,7 @@ impl Preg { ) -> Option<Vec<String>> { // Classic preg_match semantics (no PREG_UNMATCHED_AS_NULL): trailing // unmatched groups are truncated, interior unmatched groups become "". - let mut internal: IndexMap<CaptureKey, Option<String>> = IndexMap::new(); + let mut internal = PregMatches::new(); let result = preg_match2(pattern, subject, &mut internal, 0); if !result { @@ -193,7 +202,7 @@ impl Preg { pub fn is_match_all( pattern: impl PregPattern, subject: &str, - matches: &mut IndexMap<CaptureKey, Vec<Option<String>>>, + matches: &mut PregMatchesAll, ) -> bool { Self::match_all2(pattern, subject, matches) > 0 } @@ -201,7 +210,7 @@ impl Preg { pub fn is_match_all_with_offsets3( pattern: impl PregPattern, subject: &str, - matches: Option<&mut IndexMap<CaptureKey, Vec<(Option<String>, i64)>>>, + matches: Option<&mut PregMatchesAllWithOffsets>, ) -> bool { Self::match_all_with_offsets5(pattern, subject, matches) > 0 } @@ -209,18 +218,14 @@ impl Preg { // Drops `null` (unmatched) groups, mirroring how the public `string`-valued // `matches` map represents PHP's `string|null` entries by their absence. -fn drop_null_matches( - matches: IndexMap<CaptureKey, Option<String>>, -) -> IndexMap<CaptureKey, String> { +fn drop_null_matches(matches: PregMatches) -> PregMatchedGroups { matches .into_iter() .filter_map(|(key, value)| value.map(|value| (key, value))) .collect() } -fn drop_null_matches_ref( - matches: &IndexMap<CaptureKey, Option<String>>, -) -> IndexMap<CaptureKey, String> { +fn drop_null_matches_ref(matches: &PregMatches) -> PregMatchedGroups { matches .iter() .filter_map(|(key, value)| value.clone().map(|value| (key.clone(), value))) diff --git a/crates/shirabe-php-shim/src/preg.rs b/crates/shirabe-php-shim/src/preg.rs index 0d6a3231..6b53bb59 100644 --- a/crates/shirabe-php-shim/src/preg.rs +++ b/crates/shirabe-php-shim/src/preg.rs @@ -7,6 +7,99 @@ pub enum CaptureKey { ByName(String), } +/// Defines a newtype over `IndexMap` for one of the `$matches` shapes the `preg_*` functions fill +/// in. Also used by `shirabe_pcre` for the shapes `Composer\Pcre\Preg` adds on top. +#[macro_export] +macro_rules! preg_match_map { + ($(#[$attr:meta])* $vis:vis struct $name:ident($key:ty => $value:ty);) => { + $(#[$attr])* + #[derive(Debug, Default, Clone, PartialEq, Eq)] + $vis struct $name(::indexmap::IndexMap<$key, $value>); + + impl $name { + pub fn new() -> Self { + Self(::indexmap::IndexMap::new()) + } + + pub fn clear(&mut self) { + self.0.clear(); + } + + pub fn get<Q>(&self, key: &Q) -> Option<&$value> + where + Q: ?Sized + ::std::hash::Hash + ::indexmap::Equivalent<$key>, + { + self.0.get(key) + } + + pub fn insert(&mut self, key: $key, value: $value) -> Option<$value> { + self.0.insert(key, value) + } + + pub fn keys(&self) -> ::indexmap::map::Keys<'_, $key, $value> { + self.0.keys() + } + + pub fn iter(&self) -> ::indexmap::map::Iter<'_, $key, $value> { + self.0.iter() + } + } + + impl<Q> ::std::ops::Index<&Q> for $name + where + Q: ?Sized + ::std::hash::Hash + ::indexmap::Equivalent<$key>, + { + type Output = $value; + + fn index(&self, key: &Q) -> &$value { + &self.0[key] + } + } + + /// Looks a group up by its position in the map rather than by key, as `IndexMap` does. + impl ::std::ops::Index<usize> for $name { + type Output = $value; + + fn index(&self, position: usize) -> &$value { + &self.0[position] + } + } + + impl IntoIterator for $name { + type Item = ($key, $value); + type IntoIter = ::indexmap::map::IntoIter<$key, $value>; + + fn into_iter(self) -> Self::IntoIter { + self.0.into_iter() + } + } + + impl FromIterator<($key, $value)> for $name { + fn from_iter<I: IntoIterator<Item = ($key, $value)>>(iter: I) -> Self { + Self(iter.into_iter().collect()) + } + } + }; +} + +preg_match_map! { + /// A single match's `$matches`, keyed by both the named and the numbered form of each capture + /// group. A `None` value is a group the caller's flags reported as unmatched. + pub struct PregMatches(CaptureKey => Option<String>); +} + +preg_match_map! { + /// `PREG_PATTERN_ORDER` `$matches`: one entry per capture group, holding that group's value + /// across every match occurrence. + pub struct PregMatchesAll(CaptureKey => Vec<Option<String>>); +} + +preg_match_map! { + /// `PREG_OFFSET_CAPTURE` counterpart of `PregMatchesAll`, pairing each value with the byte + /// offset it was captured at (`-1` for a group that did not participate). + pub struct PregMatchesAllWithOffsets(CaptureKey => Vec<(Option<String>, i64)>); +} + pub fn preg_quote(str: &str, delimiter: Option<char>) -> String { // Regex pattern compatibility: // PHP's preg_quote escapes `<` and `>` (PCRE treats `\<`/`\>` as literals), but the `regex` @@ -53,7 +146,7 @@ pub fn preg_match( pub fn preg_match2( pattern: impl PregPattern, subject: &str, - matches: &mut indexmap::IndexMap<CaptureKey, Option<String>>, + matches: &mut PregMatches, offset: usize, ) -> bool { preg_match2_impl(pattern, subject, matches, offset, false) @@ -63,7 +156,7 @@ pub fn preg_match2( pub fn preg_match2_unmatched_as_null( pattern: impl PregPattern, subject: &str, - matches: &mut indexmap::IndexMap<CaptureKey, Option<String>>, + matches: &mut PregMatches, offset: usize, ) -> bool { preg_match2_impl(pattern, subject, matches, offset, true) @@ -72,7 +165,7 @@ pub fn preg_match2_unmatched_as_null( fn preg_match2_impl( pattern: impl PregPattern, subject: &str, - matches: &mut indexmap::IndexMap<CaptureKey, Option<String>>, + matches: &mut PregMatches, offset: usize, unmatched_as_null: bool, ) -> bool { @@ -123,7 +216,7 @@ pub fn preg_match_all(pattern: impl PregPattern, subject: &str) -> Vec<Vec<Strin pub fn preg_match_all2( pattern: impl PregPattern, subject: &str, - matches: &mut indexmap::IndexMap<CaptureKey, Vec<Option<String>>>, + matches: &mut PregMatchesAll, ) -> usize { let __resolved = pattern.resolve(); let (re, _anchored) = __resolved.parts(); @@ -174,7 +267,7 @@ pub fn preg_match_all_set_order( pub fn preg_match_all_offset_capture( pattern: impl PregPattern, subject: &str, - matches: &mut indexmap::IndexMap<CaptureKey, Vec<(Option<String>, i64)>>, + matches: &mut PregMatchesAllWithOffsets, ) -> usize { preg_match_all_offset_capture_impl(pattern, subject, matches, false) } @@ -184,7 +277,7 @@ pub fn preg_match_all_offset_capture( pub fn preg_match_all_offset_capture_unmatched_as_null( pattern: impl PregPattern, subject: &str, - matches: &mut indexmap::IndexMap<CaptureKey, Vec<(Option<String>, i64)>>, + matches: &mut PregMatchesAllWithOffsets, ) -> usize { preg_match_all_offset_capture_impl(pattern, subject, matches, true) } @@ -192,7 +285,7 @@ pub fn preg_match_all_offset_capture_unmatched_as_null( fn preg_match_all_offset_capture_impl( pattern: impl PregPattern, subject: &str, - matches: &mut indexmap::IndexMap<CaptureKey, Vec<(Option<String>, i64)>>, + matches: &mut PregMatchesAllWithOffsets, unmatched_as_null: bool, ) -> usize { let __resolved = pattern.resolve(); @@ -315,7 +408,7 @@ pub fn preg_replace_callback<F>( subject: &str, ) -> anyhow::Result<String> where - F: FnMut(&indexmap::IndexMap<CaptureKey, Option<String>>) -> anyhow::Result<String>, + F: FnMut(&PregMatches) -> anyhow::Result<String>, { let __resolved = pattern.resolve(); let (re, _anchored) = __resolved.parts(); @@ -615,11 +708,8 @@ fn php_match_row(caps: ®ex::Captures) -> Vec<String> { // Builds a single match's `$matches` map with both named and numbered keys // (the named key precedes its number). Trailing unmatched groups are dropped // and interior ones become "". -fn single_match_map( - caps: ®ex::Captures, - names: &[Option<&str>], -) -> indexmap::IndexMap<CaptureKey, Option<String>> { - let mut out = indexmap::IndexMap::new(); +fn single_match_map(caps: ®ex::Captures, names: &[Option<&str>]) -> PregMatches { + let mut out = PregMatches::new(); let group_count = caps.len(); let last_participating = (0..group_count).rev().find(|&i| caps.get(i).is_some()); @@ -645,8 +735,8 @@ fn single_match_map( fn single_match_map_unmatched_as_null( caps: ®ex::Captures, names: &[Option<&str>], -) -> indexmap::IndexMap<CaptureKey, Option<String>> { - let mut out = indexmap::IndexMap::new(); +) -> PregMatches { + let mut out = PregMatches::new(); for i in 0..caps.len() { let value = caps.get(i).map(|m| m.as_str().to_string()); diff --git a/crates/shirabe-symfony-console/src/formatter/output_formatter.rs b/crates/shirabe-symfony-console/src/formatter/output_formatter.rs index 1a3de217..de030e96 100644 --- a/crates/shirabe-symfony-console/src/formatter/output_formatter.rs +++ b/crates/shirabe-symfony-console/src/formatter/output_formatter.rs @@ -7,8 +7,8 @@ use crate::formatter::output_formatter_style_interface::OutputFormatterStyleInte use crate::formatter::output_formatter_style_stack::OutputFormatterStyleStack; use crate::formatter::wrappable_output_formatter_interface::WrappableOutputFormatterInterface; use shirabe_php_shim::{ - CaptureKey, php_regex, preg_match, preg_match_all, preg_match_all_offset_capture, - preg_match_all_set_order, preg_replace, + CaptureKey, PregMatchesAllWithOffsets, php_regex, preg_match, preg_match_all, + preg_match_all_offset_capture, preg_match_all_set_order, preg_replace, }; use shirabe_symfony_string::b; @@ -290,8 +290,7 @@ impl WrappableOutputFormatterInterface for OutputFormatter { let open_tag_regex = "[a-z](?:[^\\\\<>]* | \\\\.)*"; let close_tag_regex = "[a-z][^<>]*"; let mut current_line_length: i64 = 0; - let mut matches: indexmap::IndexMap<CaptureKey, Vec<(Option<String>, i64)>> = - indexmap::IndexMap::new(); + let mut matches = PregMatchesAllWithOffsets::new(); preg_match_all_offset_capture( format!("#<(({open_tag_regex}) | /({close_tag_regex})?)>#ix"), message, diff --git a/crates/shirabe-symfony-console/src/helper/progress_bar.rs b/crates/shirabe-symfony-console/src/helper/progress_bar.rs index 1158c507..4764d617 100644 --- a/crates/shirabe-symfony-console/src/helper/progress_bar.rs +++ b/crates/shirabe-symfony-console/src/helper/progress_bar.rs @@ -9,7 +9,7 @@ use crate::output::OutputInterface; use crate::output::output_interface; use crate::terminal::Terminal; use indexmap::IndexMap; -use shirabe_php_shim::{CaptureKey, preg_replace_callback}; +use shirabe_php_shim::{CaptureKey, PregMatches, preg_replace_callback}; pub const FORMAT_VERBOSE: &str = "verbose"; pub const FORMAT_VERY_VERBOSE: &str = "very_verbose"; @@ -798,7 +798,7 @@ impl ProgressBar { let format = self.format.clone().unwrap_or_default(); // $callback in PHP, expressed as a closure over $this and the matches. - let callback = |matches: &IndexMap<CaptureKey, Option<String>>| -> anyhow::Result<String> { + let callback = |matches: &PregMatches| -> anyhow::Result<String> { let name = matches[&CaptureKey::ByIndex(1)].clone().unwrap_or_default(); let text: shirabe_php_shim::PhpMixed = diff --git a/crates/shirabe-symfony-console/src/input/string_input.rs b/crates/shirabe-symfony-console/src/input/string_input.rs index d6794957..245b948d 100644 --- a/crates/shirabe-symfony-console/src/input/string_input.rs +++ b/crates/shirabe-symfony-console/src/input/string_input.rs @@ -6,7 +6,7 @@ use crate::input::InputDefinition; use crate::input::InputInterface; use crate::input::StreamableInputInterface; use indexmap::IndexMap; -use shirabe_php_shim::{CaptureKey, PhpMixed, php_regex, preg_match2}; +use shirabe_php_shim::{CaptureKey, PhpMixed, PregMatches, php_regex, preg_match2}; /// StringInput represents an input provided as a string. /// @@ -57,7 +57,7 @@ impl StringInput { continue; } - let mut m: IndexMap<CaptureKey, Option<String>> = IndexMap::new(); + let mut m = PregMatches::new(); if preg_match2(php_regex!(r"/\s+/A"), input, &mut m, cursor as usize) { if token.is_some() { tokens.push(token.take().unwrap()); diff --git a/crates/shirabe-symfony-finder/src/finder.rs b/crates/shirabe-symfony-finder/src/finder.rs index 95ab5d50..27a7d2d6 100644 --- a/crates/shirabe-symfony-finder/src/finder.rs +++ b/crates/shirabe-symfony-finder/src/finder.rs @@ -8,8 +8,8 @@ use crate::glob::Glob; use chrono::{NaiveDate, NaiveDateTime}; -use indexmap::{IndexMap, IndexSet}; -use shirabe_pcre::{CaptureKey, Preg}; +use indexmap::IndexSet; +use shirabe_pcre::{CaptureKey, Preg, PregMatchedGroups}; use shirabe_php_shim::{file_exists, glob, is_dir, php_regex, preg_quote, rtrim}; use std::path::{Path, PathBuf}; use std::time::UNIX_EPOCH; @@ -642,7 +642,7 @@ fn is_regex(str: &str) -> bool { // PHP 8.2+ available modifiers. let available_modifiers = "imsxuADUn"; - let mut matches: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut matches = PregMatchedGroups::new(); let pattern = format!("/^(.{{3,}}?)[{available_modifiers}]*$/"); if Preg::is_match3(&pattern, str, Some(&mut matches)) { let group = matches @@ -688,7 +688,7 @@ fn comparator_test(operator: &str, test: i64, target: i64) -> bool { /// `DateComparator::__construct`, returning `(operator, target unix timestamp)`. fn parse_date_comparator(test: &str) -> (String, i64) { let pattern = "#^\\s*(==|!=|[<>]=?|after|since|before|until)?\\s*(.+?)\\s*$#i"; - let mut matches: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut matches = PregMatchedGroups::new(); if !Preg::is_match3(pattern, test, Some(&mut matches)) { panic!("Don't understand \"{test}\" as a date test."); } diff --git a/crates/shirabe-symfony-process/src/process.rs b/crates/shirabe-symfony-process/src/process.rs index 045224c5..6fea07c8 100644 --- a/crates/shirabe-symfony-process/src/process.rs +++ b/crates/shirabe-symfony-process/src/process.rs @@ -12,8 +12,8 @@ use crate::pipes::windows_pipes::WindowsPipes; use crate::process_utils::ProcessUtils; use indexmap::IndexMap; use shirabe_php_shim::{ - CaptureKey, Descriptor, PhpMixed, PhpResource, php_regex, preg_match, preg_replace, - preg_replace_callback, + CaptureKey, Descriptor, PhpMixed, PhpResource, PregMatches, php_regex, preg_match, + preg_replace, preg_replace_callback, }; use std::sync::OnceLock; @@ -938,7 +938,7 @@ impl Process { )++ ) | [^"]*+ )"/x"# ), - |m: &IndexMap<CaptureKey, Option<String>>| -> anyhow::Result<String> { + |m: &PregMatches| -> anyhow::Result<String> { let m0 = m[&CaptureKey::ByIndex(0)].clone().unwrap_or_default(); let m1 = m.get(&CaptureKey::ByIndex(1)).cloned().flatten(); if m1.is_none() { @@ -1072,7 +1072,7 @@ impl Process { ) -> anyhow::Result<String> { preg_replace_callback( php_regex!(r#"/"\$\{:([_a-zA-Z]+[_a-zA-Z0-9]*)\}"/"#), - |matches: &IndexMap<CaptureKey, Option<String>>| -> anyhow::Result<String> { + |matches: &PregMatches| -> anyhow::Result<String> { let key = matches .get(&CaptureKey::ByIndex(1)) .cloned() diff --git a/crates/shirabe/src/autoload/autoload_generator.rs b/crates/shirabe/src/autoload/autoload_generator.rs index 91df1749..9a4a4c26 100644 --- a/crates/shirabe/src/autoload/autoload_generator.rs +++ b/crates/shirabe/src/autoload/autoload_generator.rs @@ -23,7 +23,7 @@ use crate::util::Platform; use indexmap::IndexMap; use shirabe_class_map_generator::class_map::ClassMap; use shirabe_class_map_generator::class_map_generator::ClassMapGenerator; -use shirabe_pcre::{CaptureKey, Preg}; +use shirabe_pcre::{CaptureKey, Preg, PregMatchedGroups}; use shirabe_php_shim::{ InvalidArgumentException, PhpMixed, array_keys, array_map, array_merge_map, array_merge_recursive, array_shift, array_slice_strs, array_unique, bin2hex, explode, @@ -559,7 +559,7 @@ return array( { let content = file_get_contents(format!("{}/autoload.php", vendor_path)).unwrap_or_default(); - let mut matches: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut matches = PregMatchedGroups::new(); if Preg::match3( php_regex!("{ComposerAutoloaderInit([^:\\s]+)::}"), &content, @@ -1155,7 +1155,7 @@ return array( let package = &item.0; let links = array_merge_map(package.get_replaces(), package.get_provides()); for (_k, link) in &links { - let mut matches: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut matches = PregMatchedGroups::new(); if Preg::match3( php_regex!("{^ext-(.+)$}iD"), link.get_target(), @@ -1201,7 +1201,7 @@ return array( required_php_64bit = true; } - let mut matches: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut matches = PregMatchedGroups::new(); if check_platform.as_bool() == Some(true) && Preg::match3( php_regex!("{^ext-(.+)$}iD"), @@ -1950,7 +1950,7 @@ class ComposerStaticInit{} std::cell::RefCell::new(None); let p = Preg::replace_callback( php_regex!("{^((?:(?:\\\\\\.){1,2}+/)+)}"), - |matches: &IndexMap<CaptureKey, String>| -> String { + |matches: &PregMatchedGroups| -> String { // undo preg_quote for the matched string *updir_cell.borrow_mut() = Some(str_replace( "\\.", diff --git a/crates/shirabe/src/cache.rs b/crates/shirabe/src/cache.rs index b41350f5..e1964959 100644 --- a/crates/shirabe/src/cache.rs +++ b/crates/shirabe/src/cache.rs @@ -6,7 +6,7 @@ use crate::util::Filesystem; use crate::util::Platform; use crate::util::Silencer; use chrono::Utc; -use shirabe_pcre::{CaptureKey, Preg}; +use shirabe_pcre::{CaptureKey, Preg, PregMatchedGroups}; use shirabe_php_shim::{ ErrorException, bin2hex, clearstatcache, date_format_to_strftime, dirname, disk_free_space, file_exists, file_get_contents, file_put_contents, filemtime, function_exists, hash_file, @@ -186,7 +186,7 @@ impl Cache { true, crate::io::DEBUG, ); - let mut m = indexmap::IndexMap::new(); + let mut m = PregMatchedGroups::new(); if Preg::match3( php_regex!( r"{^file_put_contents\(\): Only ([0-9]+) of ([0-9]+) bytes written}" diff --git a/crates/shirabe/src/command/archive_command.rs b/crates/shirabe/src/command/archive_command.rs index 452103d9..1d7165ac 100644 --- a/crates/shirabe/src/command/archive_command.rs +++ b/crates/shirabe/src/command/archive_command.rs @@ -26,7 +26,7 @@ use crate::util::Platform; use crate::util::ProcessExecutor; use crate::util::r#loop::Loop; use indexmap::IndexMap; -use shirabe_pcre::{CaptureKey, Preg}; +use shirabe_pcre::{CaptureKey, Preg, PregMatchedGroups}; use shirabe_php_shim::{LogicException, get_debug_type, impl_php_class, php_regex}; use shirabe_symfony_console::command::Command; use shirabe_symfony_console::input::InputInterface; @@ -229,7 +229,7 @@ impl ArchiveCommand { } if let Some(version_str) = &version { - let mut matches: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut matches = PregMatchedGroups::new(); if Preg::match3( php_regex!(r"{@(stable|RC|beta|alpha|dev)$}i"), version_str, diff --git a/crates/shirabe/src/command/config_command.rs b/crates/shirabe/src/command/config_command.rs index 504a0f11..550ddf3c 100644 --- a/crates/shirabe/src/command/config_command.rs +++ b/crates/shirabe/src/command/config_command.rs @@ -18,7 +18,7 @@ use crate::util::Filesystem; use crate::util::Platform; use crate::util::Silencer; use indexmap::IndexMap; -use shirabe_pcre::{CaptureKey, Preg}; +use shirabe_pcre::{CaptureKey, Preg, PregMatchedGroups}; use shirabe_php_shim::{ InvalidArgumentException, PhpMixed, RuntimeException, array_is_list, array_merge, escapeshellcmd, exec, explode, file_exists, impl_php_class, implode, in_array_loose, @@ -701,7 +701,7 @@ impl Command for ConfigCommand { let mut source = config.borrow_mut().get_source_of_value(&setting_key); let mut value: PhpMixed; - let mut matches: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut matches = PregMatchedGroups::new(); if Preg::is_match3( php_regex!("/^repos?(?:itories)?(?:\\.(.+))?/"), &setting_key, @@ -929,7 +929,7 @@ impl Command for ConfigCommand { return Ok(0); } // handle preferred-install per-package config - let mut matches: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut matches = PregMatchedGroups::new(); if Preg::is_match3( php_regex!("/^preferred-install\\.(.+)/"), &setting_key, @@ -967,7 +967,7 @@ impl Command for ConfigCommand { } // handle allow-plugins config setting elements true or false to add/remove - let mut matches: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut matches = PregMatchedGroups::new(); if Preg::is_match3( php_regex!("{^allow-plugins\\.([a-zA-Z0-9/*-]+)}"), &setting_key, @@ -1037,7 +1037,7 @@ impl Command for ConfigCommand { } // handle repositories - let mut matches: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut matches = PregMatchedGroups::new(); if Preg::is_match3( php_regex!("/^repos?(?:itories)?\\.(.+)/"), &setting_key, @@ -1110,7 +1110,7 @@ impl Command for ConfigCommand { } // handle extra - let mut matches: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut matches = PregMatchedGroups::new(); if Preg::is_match3( php_regex!("/^extra\\.(.+)/"), &setting_key, @@ -1187,7 +1187,7 @@ impl Command for ConfigCommand { } // handle suggest - let mut matches: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut matches = PregMatchedGroups::new(); if Preg::is_match3( php_regex!("/^suggest\\.(.+)/"), &setting_key, @@ -1226,7 +1226,7 @@ impl Command for ConfigCommand { } // handle platform - let mut matches: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut matches = PregMatchedGroups::new(); if Preg::is_match3( php_regex!("/^platform\\.(.+)/"), &setting_key, @@ -1348,7 +1348,7 @@ impl Command for ConfigCommand { } // handle auth - let mut matches: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut matches = PregMatchedGroups::new(); if Preg::is_match3( php_regex!( "/^(bitbucket-oauth|github-oauth|gitlab-oauth|gitlab-token|http-basic|custom-headers|bearer|forgejo-token)\\.(.+)/" @@ -1474,7 +1474,7 @@ impl Command for ConfigCommand { } // Check if the header is in correct "Name: Value" format - let mut header_parts: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut header_parts = PregMatchedGroups::new(); if !Preg::is_match3( php_regex!("/^[^:]+:\\s*.+$/"), header, @@ -1527,7 +1527,7 @@ impl Command for ConfigCommand { } // handle script - let mut matches: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut matches = PregMatchedGroups::new(); if Preg::is_match3( php_regex!("/^scripts\\.(.+)/"), &setting_key, diff --git a/crates/shirabe/src/command/create_project_command.rs b/crates/shirabe/src/command/create_project_command.rs index 124f809b..33bfb021 100644 --- a/crates/shirabe/src/command/create_project_command.rs +++ b/crates/shirabe/src/command/create_project_command.rs @@ -37,7 +37,7 @@ use crate::util::Filesystem; use crate::util::Platform; use crate::util::ProcessExecutor; use indexmap::IndexMap; -use shirabe_pcre::{CaptureKey, Preg}; +use shirabe_pcre::{CaptureKey, Preg, PregMatchedGroups}; use shirabe_php_shim::Catch as _; use shirabe_php_shim::{ InvalidArgumentException, PhpMixed, RuntimeException, UnexpectedValueException, array_pop, @@ -527,7 +527,7 @@ impl CreateProjectCommand { stability = Some("stable".to_string()); } else { let ok = { - let mut matched: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut matched = PregMatchedGroups::new(); let ok = Preg::is_match3( format!( "{{^[^,\\s]*?@({})$}}i", diff --git a/crates/shirabe/src/command/diagnose_command.rs b/crates/shirabe/src/command/diagnose_command.rs index 4b148c09..aa581c82 100644 --- a/crates/shirabe/src/command/diagnose_command.rs +++ b/crates/shirabe/src/command/diagnose_command.rs @@ -33,7 +33,7 @@ use crate::util::ProcessExecutor; use crate::util::http::ProxyManager; use crate::util::http::RequestProxy; use indexmap::IndexMap; -use shirabe_pcre::{CaptureKey, Preg}; +use shirabe_pcre::{CaptureKey, Preg, PregMatchedGroups}; use shirabe_php_shim::Catch as _; use shirabe_php_shim::{ AnyThrowable, CmpOp, InvalidArgumentException, PHP_EOL, PhpClass as _, PhpMixed, @@ -862,7 +862,7 @@ impl DiagnoseCommand { warnings.insert("zlib".to_string(), PhpMixed::Bool(true)); } - let mut phpinfo_match: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut phpinfo_match = PregMatchedGroups::new(); if Preg::is_match3( php_regex!("{Configure Command(?: *</td><td class=\"v\">| *=> *)(.*?)(?:</td>|$)}m"), &diagnostics.phpinfo_general, diff --git a/crates/shirabe/src/command/init_command.rs b/crates/shirabe/src/command/init_command.rs index af3d16e2..243df290 100644 --- a/crates/shirabe/src/command/init_command.rs +++ b/crates/shirabe/src/command/init_command.rs @@ -19,7 +19,7 @@ use crate::util::Filesystem; use crate::util::ProcessExecutor; use crate::util::Silencer; use indexmap::IndexMap; -use shirabe_pcre::{CaptureKey, Preg}; +use shirabe_pcre::{CaptureKey, Preg, PregMatchedGroups, PregMatchesAll}; use shirabe_php_shim::Catch as _; use shirabe_php_shim::{ FILE_IGNORE_NEW_LINES, InvalidArgumentException, PHP_EOL, PHP_SERVER, PhpMixed, @@ -90,7 +90,7 @@ impl InitCommand { &self, author: &str, ) -> anyhow::Result<IndexMap<String, Option<String>>> { - let mut m: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut m = PregMatchedGroups::new(); if Preg::is_match3( php_regex!(r#"/^(?P<name>[- .,\p{L}\p{N}\p{Mn}\'’\"()]+)(?:\s+<(?P<email>.+?)>)?$/u"#), author, @@ -175,7 +175,7 @@ impl InitCommand { ) == 0 { *self.git_config.borrow_mut() = Some(IndexMap::new()); - let mut m: IndexMap<CaptureKey, Vec<Option<String>>> = IndexMap::new(); + let mut m = PregMatchesAll::new(); if Preg::is_match_all(php_regex!(r"{^([^=]+)=(.*)$}m"), &output, &mut m) { let keys: Vec<Option<String>> = m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default(); diff --git a/crates/shirabe/src/command/package_discovery_trait.rs b/crates/shirabe/src/command/package_discovery_trait.rs index 88c90a5a..877cc7da 100644 --- a/crates/shirabe/src/command/package_discovery_trait.rs +++ b/crates/shirabe/src/command/package_discovery_trait.rs @@ -19,7 +19,7 @@ use crate::repository::RepositorySet; use crate::repository::{RepositoryInterface, SearchResult}; use crate::util::Filesystem; use indexmap::IndexMap; -use shirabe_pcre::{CaptureKey, Preg}; +use shirabe_pcre::{CaptureKey, Preg, PregMatchedGroups}; use shirabe_php_shim::Catch as _; use shirabe_php_shim::{ Exception, InvalidArgumentException, LogicException, PHP_EOL, PhpMixed, array_keys, @@ -330,7 +330,7 @@ pub trait PackageDiscoveryTrait: BaseCommand { } } - let mut m: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut m = PregMatchedGroups::new(); if Preg::is_match3( php_regex!(r"{^\s*(?P<name>[\S/]+)(?:\s+(?P<version>\S+))?\s*$}"), &selection, diff --git a/crates/shirabe/src/command/show_command.rs b/crates/shirabe/src/command/show_command.rs index d02295d5..e8be4da5 100644 --- a/crates/shirabe/src/command/show_command.rs +++ b/crates/shirabe/src/command/show_command.rs @@ -36,7 +36,7 @@ use crate::repository::RepositoryUtils; use crate::repository::RootPackageRepository; use crate::util::PackageInfo; use indexmap::IndexMap; -use shirabe_pcre::{CaptureKey, Preg}; +use shirabe_pcre::{CaptureKey, Preg, PregMatchedGroups}; use shirabe_php_shim::{ CmpOp, DATE_ATOM, InvalidArgumentException, LogicException, PhpMixed, UnexpectedValueException, array_search, date_format_to_strftime, date_local, extension_loaded, impl_php_class, @@ -1372,7 +1372,7 @@ impl ShowCommand { } if target_version.is_none() { - let mut groups: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut groups = PregMatchedGroups::new(); if major_only && Preg::is_match3( php_regex!(r"{^(?P<zero_major>(?:0\.)+)?(?P<first_meaningful>\d+)\.}"), diff --git a/crates/shirabe/src/config.rs b/crates/shirabe/src/config.rs index 04599aa4..3a320d6f 100644 --- a/crates/shirabe/src/config.rs +++ b/crates/shirabe/src/config.rs @@ -8,7 +8,7 @@ pub use json_config_source::*; use crate::io::io_interface; use indexmap::IndexMap; -use shirabe_pcre::{CaptureKey, Preg}; +use shirabe_pcre::{CaptureKey, Preg, PregMatchedGroups}; use shirabe_php_shim::{ E_USER_DEPRECATED, PhpMixed, RuntimeException, array_key_exists, array_merge, array_search_mixed, array_unique, empty, filter_var_url, implode, in_array_loose, @@ -647,7 +647,7 @@ impl Config { // numbers with kb/mb/gb support, without env var support "cache-files-maxsize" => { let raw = self.config.get(key).map(php_to_string).unwrap_or_default(); - let mut matches: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut matches = PregMatchedGroups::new(); if !Preg::is_match3( php_regex!(r"/^\s*([0-9.]+)\s*(?:([kmg])(?:i?b)?)?\s*$/i"), &raw, @@ -961,7 +961,7 @@ impl Config { let mut error = None; let result = Preg::replace_callback( php_regex!(r"#\{\$(.+)\}#"), - |m: &IndexMap<CaptureKey, String>| -> String { + |m: &PregMatchedGroups| -> String { let key_match = m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default(); match self.get_with_flags(&key_match, flags) { Ok(v) => php_to_string(&v), diff --git a/crates/shirabe/src/console/application.rs b/crates/shirabe/src/console/application.rs index e818823e..43a2597b 100644 --- a/crates/shirabe/src/console/application.rs +++ b/crates/shirabe/src/console/application.rs @@ -1790,8 +1790,7 @@ impl Application { let mut line = String::new(); let mut offset = 0i64; - let mut m: indexmap::IndexMap<shirabe_php_shim::CaptureKey, Option<String>> = - indexmap::IndexMap::new(); + let mut m = shirabe_php_shim::PregMatches::new(); while preg_match2( php_regex!(r"/.{1,10000}/u"), &utf8_string, diff --git a/crates/shirabe/src/console/html_output_formatter.rs b/crates/shirabe/src/console/html_output_formatter.rs index 2f523c37..3b4018e3 100644 --- a/crates/shirabe/src/console/html_output_formatter.rs +++ b/crates/shirabe/src/console/html_output_formatter.rs @@ -1,7 +1,7 @@ //! ref: composer/src/Composer/Console/HtmlOutputFormatter.php use indexmap::IndexMap; -use shirabe_pcre::{CaptureKey, Preg}; +use shirabe_pcre::{CaptureKey, Preg, PregMatchedGroups}; use shirabe_symfony_console::formatter::OutputFormatter; use shirabe_symfony_console::formatter::OutputFormatterInterface; use shirabe_symfony_console::formatter::OutputFormatterStyleInterface; @@ -72,7 +72,7 @@ impl HtmlOutputFormatter { ))) } - fn format_html(&self, matches: &IndexMap<CaptureKey, String>) -> String { + fn format_html(&self, matches: &PregMatchedGroups) -> String { let codes_str = matches .get(&CaptureKey::ByIndex(1)) .map(|s| s.as_str()) diff --git a/crates/shirabe/src/dependency_resolver/lock_transaction.rs b/crates/shirabe/src/dependency_resolver/lock_transaction.rs index 51917dd6..80a755b5 100644 --- a/crates/shirabe/src/dependency_resolver/lock_transaction.rs +++ b/crates/shirabe/src/dependency_resolver/lock_transaction.rs @@ -176,7 +176,7 @@ impl LockTransaction { let dist_reference = present_package.get_dist_reference().unwrap(); let new_dist_url = Preg::replace_callback( php_regex!(r"{(/|sha=)[a-f0-9]{40}(/|$)}i"), - |m: &indexmap::IndexMap<shirabe_pcre::CaptureKey, String>| -> String { + |m: &shirabe_pcre::PregMatchedGroups| -> String { let get = |i: usize| -> String { m.get(&shirabe_pcre::CaptureKey::ByIndex(i)) .cloned() diff --git a/crates/shirabe/src/dependency_resolver/problem.rs b/crates/shirabe/src/dependency_resolver/problem.rs index cdb833bf..c75a0d31 100644 --- a/crates/shirabe/src/dependency_resolver/problem.rs +++ b/crates/shirabe/src/dependency_resolver/problem.rs @@ -10,7 +10,7 @@ use crate::repository::LockArrayRepository; use crate::repository::PlatformRepository; use crate::repository::RepositorySet; use indexmap::IndexMap; -use shirabe_pcre::{CaptureKey, Preg}; +use shirabe_pcre::{CaptureKey, Preg, PregMatchedGroups}; use shirabe_php_shim::{ CmpOp, LogicException, PhpMixed, extension_loaded, implode, loosely_compare, php_regex, spl_object_hash, sprintf, str_replace, stripos, strpos, strtolower, substr, substr_count, @@ -220,7 +220,7 @@ impl Problem { installed_map, learned_pool, )?; - let mut m: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut m = PregMatchedGroups::new(); let matched = if matches!( rule_ref.get_reason(), rule::RULE_PACKAGE_REQUIRES | rule::RULE_PACKAGE_CONFLICT diff --git a/crates/shirabe/src/downloader/git_downloader.rs b/crates/shirabe/src/downloader/git_downloader.rs index 90a962a2..f60b231d 100644 --- a/crates/shirabe/src/downloader/git_downloader.rs +++ b/crates/shirabe/src/downloader/git_downloader.rs @@ -17,7 +17,7 @@ use crate::util::Platform; use crate::util::ProcessExecutor; use crate::util::Url; use indexmap::IndexMap; -use shirabe_pcre::{CaptureKey, Preg}; +use shirabe_pcre::{CaptureKey, Preg, PregMatchedGroups, PregMatchesAll}; use shirabe_php_shim::{ CmpOp, PhpMixed, RuntimeException, array_map, basename, dirname, impl_php_class, implode, in_array_strict, is_dir, php_regex, preg_quote, preg_split, realpath, rtrim, strlen, strpos, @@ -95,7 +95,7 @@ impl GitDownloader { } let mut refs = trim(&output, None); - let mut head_match: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut head_match = PregMatchedGroups::new(); if !Preg::is_match3( php_regex!(r"{^([a-f0-9]+) HEAD$}mi"), &refs, @@ -109,7 +109,7 @@ impl GitDownloader { .cloned() .unwrap_or_default(); - let mut branches_match: IndexMap<CaptureKey, Vec<Option<String>>> = IndexMap::new(); + let mut branches_match = PregMatchesAll::new(); if !Preg::is_match_all( format!("{{^{} refs/heads/(.+)$}}mi", preg_quote(&head_ref, None)), &refs, @@ -137,7 +137,7 @@ impl GitDownloader { // try to find matching branch names in remote repos for candidate in &candidate_branches { - let mut m: IndexMap<CaptureKey, Vec<Option<String>>> = IndexMap::new(); + let mut m = PregMatchesAll::new(); if Preg::is_match_all( format!( "{{^[a-f0-9]+ refs/remotes/((?:[^/]+)/{})$}}mi", @@ -510,7 +510,7 @@ impl GitDownloader { fn set_push_url(&self, path: &str, url: &str) { // set push url for github projects - let mut match_: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut match_ = PregMatchedGroups::new(); if Preg::is_match3( format!( "{{^(?:https?|git)://{}/([^/]+)/([^/]+?)(?:\\.git)?$}}", @@ -1115,8 +1115,8 @@ impl VcsDownloader for GitDownloader { Some(&path), ) == 0 { - let mut origin_match: IndexMap<CaptureKey, String> = IndexMap::new(); - let mut composer_match: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut origin_match = PregMatchedGroups::new(); + let mut composer_match = PregMatchedGroups::new(); if Preg::is_match3( php_regex!(r"{^origin\s+(?P<url>\S+)}m"), &output, diff --git a/crates/shirabe/src/downloader/svn_downloader.rs b/crates/shirabe/src/downloader/svn_downloader.rs index d5087d10..29662be8 100644 --- a/crates/shirabe/src/downloader/svn_downloader.rs +++ b/crates/shirabe/src/downloader/svn_downloader.rs @@ -15,7 +15,7 @@ use crate::util::Filesystem; use crate::util::ProcessExecutor; use crate::util::Svn as SvnUtil; use indexmap::IndexMap; -use shirabe_pcre::{CaptureKey, Preg}; +use shirabe_pcre::{CaptureKey, Preg, PregMatchedGroups}; use shirabe_php_shim::{ CmpOp, PhpMixed, RuntimeException, impl_php_class, is_dir, php_regex, preg_split, version_compare, @@ -383,7 +383,7 @@ impl VcsDownloader for SvnDownloader { } let url_pattern = "#<url>(.*)</url>#"; - let mut matches: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut matches = PregMatchedGroups::new(); let base_url = if Preg::match3(url_pattern, &output, Some(&mut matches)) { matches .get(&CaptureKey::ByIndex(1)) diff --git a/crates/shirabe/src/downloader/zip_downloader.rs b/crates/shirabe/src/downloader/zip_downloader.rs index e7f3facf..91078dc9 100644 --- a/crates/shirabe/src/downloader/zip_downloader.rs +++ b/crates/shirabe/src/downloader/zip_downloader.rs @@ -8,7 +8,7 @@ use crate::package::PackageInterfaceHandle; use crate::util::IniHelper; use crate::util::Platform; use indexmap::IndexMap; -use shirabe_pcre::{CaptureKey, Preg}; +use shirabe_pcre::{CaptureKey, Preg, PregMatchedGroups}; use shirabe_php_shim::Catch as _; use shirabe_php_shim::{ CmpOp, ErrorException, PhpMixed, RuntimeException, UnexpectedValueException, ZipArchive, @@ -114,7 +114,7 @@ impl ZipDownloader { .unwrap_or(1) == 0 { - let mut m: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut m = PregMatchedGroups::new(); if Preg::is_match3( php_regex!(r"{^\s*7-Zip(?:\s\[64\])?\s([0-9.]+)}"), &output, diff --git a/crates/shirabe/src/event_dispatcher/event_dispatcher.rs b/crates/shirabe/src/event_dispatcher/event_dispatcher.rs index 8aa75491..c1a7d8f9 100644 --- a/crates/shirabe/src/event_dispatcher/event_dispatcher.rs +++ b/crates/shirabe/src/event_dispatcher/event_dispatcher.rs @@ -21,7 +21,7 @@ use crate::script::Event as ScriptEvent; use crate::util::Platform; use crate::util::ProcessExecutor; use indexmap::IndexMap; -use shirabe_pcre::{CaptureKey, Preg}; +use shirabe_pcre::{CaptureKey, Preg, PregMatchedGroups}; use shirabe_php_rpc::{ PhpThrow, PluginValue, RustMethodDispatcher, RustObjHandle, call_function, call_function_with_dispatcher, call_php_method, call_static_method, @@ -962,7 +962,7 @@ try {{ } // match somename (not in quote, and not a qualified path) and if it is not a valid path from CWD then try to find it // in $PATH. This allows support for `@php foo` where foo is a binary name found in PATH but not an actual relative path - let mut m: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut m = PregMatchedGroups::new(); if Preg::is_match3( php_regex!("{^[^\\'\"\\s/\\\\]+}"), &path_and_args, diff --git a/crates/shirabe/src/installer/binary_installer.rs b/crates/shirabe/src/installer/binary_installer.rs index 32e4c071..d5ece82f 100644 --- a/crates/shirabe/src/installer/binary_installer.rs +++ b/crates/shirabe/src/installer/binary_installer.rs @@ -8,8 +8,7 @@ use crate::util::Filesystem; use crate::util::Platform; use crate::util::ProcessExecutor; use crate::util::Silencer; -use indexmap::IndexMap; -use shirabe_pcre::{CaptureKey, Preg}; +use shirabe_pcre::{CaptureKey, Preg, PregMatchedGroups}; use shirabe_php_shim::{ PhpMixed, basename, basename_with_suffix, chmod, dirname, fclose, fgets, file_exists, file_get_contents5, file_put_contents, fopen, is_dir, is_file, is_link, php_regex, realpath, @@ -202,7 +201,7 @@ impl BinaryInstaller { } Err(_) => String::new(), }; - let mut m: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut m = PregMatchedGroups::new(); if Preg::is_match3( php_regex!(r"{^#!/(?:usr/bin/env )?(?:[^/]+/)*(.+)$}m"), &line, diff --git a/crates/shirabe/src/io/buffer_io.rs b/crates/shirabe/src/io/buffer_io.rs index 75c850f5..a3311129 100644 --- a/crates/shirabe/src/io/buffer_io.rs +++ b/crates/shirabe/src/io/buffer_io.rs @@ -76,7 +76,7 @@ impl BufferIO { loop { let next = Preg::replace_callback( php_regex!(r"{(^|\n|\x08)(.+?)(\x08+)}"), - |matches: &indexmap::IndexMap<shirabe_pcre::CaptureKey, String>| -> String { + |matches: &shirabe_pcre::PregMatchedGroups| -> String { let empty = String::new(); let g1 = matches .get(&shirabe_pcre::CaptureKey::ByIndex(1)) diff --git a/crates/shirabe/src/json/json_file.rs b/crates/shirabe/src/json/json_file.rs index e31cd70d..040f472a 100644 --- a/crates/shirabe/src/json/json_file.rs +++ b/crates/shirabe/src/json/json_file.rs @@ -8,8 +8,7 @@ use crate::json::JsonValidationException; use crate::util::Filesystem; use crate::util::HttpDownloader; use crate::util::Silencer; -use indexmap::IndexMap; -use shirabe_pcre::{CaptureKey, Preg}; +use shirabe_pcre::{CaptureKey, Preg, PregMatchedGroups}; use shirabe_php_shim::Catch as _; use shirabe_php_shim::{ InvalidArgumentException, JSON_PRETTY_PRINT, JSON_UNESCAPED_SLASHES, JSON_UNESCAPED_UNICODE, @@ -451,7 +450,7 @@ impl JsonFile { let indent_owned = options.indent; return Ok(Preg::replace_callback( php_regex!(r"#^ {4,}#m"), - move |m: &indexmap::IndexMap<shirabe_pcre::CaptureKey, String>| -> String { + move |m: &shirabe_pcre::PregMatchedGroups| -> String { let whole = m .get(&shirabe_pcre::CaptureKey::ByIndex(0)) .map(|s| s.as_str()) @@ -555,7 +554,7 @@ impl JsonFile { } pub fn detect_indenting(json: Option<&str>) -> String { - let mut m: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut m = PregMatchedGroups::new(); if Preg::is_match3( php_regex!(r##"#^([ \t]+)"#m"##), json.unwrap_or(""), diff --git a/crates/shirabe/src/json/json_manipulator.rs b/crates/shirabe/src/json/json_manipulator.rs index 08880e80..425eb192 100644 --- a/crates/shirabe/src/json/json_manipulator.rs +++ b/crates/shirabe/src/json/json_manipulator.rs @@ -4,7 +4,7 @@ use crate::json::JsonFile; use crate::json::json_grammar::{self, ValueKind}; use crate::repository::PlatformRepository; use indexmap::IndexMap; -use shirabe_pcre::{CaptureKey, Preg}; +use shirabe_pcre::{CaptureKey, Preg, PregMatchedGroups, PregNamedGroups}; use shirabe_php_shim::{ InvalidArgumentException, LogicException, PhpMixed, addcslashes, array_key_exists, array_keys, array_reverse, empty, explode, implode, in_array_loose, is_array, is_int, is_numeric, @@ -112,7 +112,7 @@ impl JsonManipulator { &links[value_end..] ); } else { - let mut groups: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut groups = PregMatchedGroups::new(); if Preg::is_match3( php_regex!("#^\\s*\\{\\s*\\S+.*?(\\s*\\}\\s*)$#s"), &links, @@ -740,7 +740,7 @@ impl JsonManipulator { &children[cm.value_end..] ); } else { - let mut leading_match: IndexMap<String, String> = IndexMap::new(); + let mut leading_match = PregNamedGroups::new(); if Preg::is_match_named( php_regex!( "#^\\{(?P<leadingspace>\\s*?)(?P<content>\\S+.*?)?(?P<trailingspace>\\s*)\\}$#s" @@ -942,7 +942,7 @@ impl JsonManipulator { let children_clean = children_clean.ok_or_else(|| InvalidArgumentException::new("JsonManipulator: $childrenClean is not defined. Please report at https://github.com/nsfisis/php-shirabe/issues/new.".to_string()))?; // no child data left, $name was the only key in - let mut empty_match: IndexMap<String, String> = IndexMap::new(); + let mut empty_match = PregNamedGroups::new(); if Preg::is_match_named( php_regex!("#^\\{\\s*?(?P<content>\\S+.*?)?(?P<trailingspace>\\s*)\\}$#s"), &children_clean, @@ -1039,7 +1039,7 @@ impl JsonManipulator { return Ok(false); } - let mut leading_match: IndexMap<String, String> = IndexMap::new(); + let mut leading_match = PregNamedGroups::new(); if Preg::is_match_named( php_regex!( "#^\\[(?P<leadingspace>\\s*?)(?P<content>\\S+.*?)?(?P<trailingspace>\\s*)\\]$#s" @@ -1330,7 +1330,7 @@ impl JsonManipulator { } // append at the end of the file and keep whitespace - let mut tail_match: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut tail_match = PregMatchedGroups::new(); if Preg::is_match3( php_regex!("#[^{\\s](\\s*)\\}$#"), &self.contents, diff --git a/crates/shirabe/src/package/loader/root_package_loader.rs b/crates/shirabe/src/package/loader/root_package_loader.rs index 58a06ebd..bbcf294f 100644 --- a/crates/shirabe/src/package/loader/root_package_loader.rs +++ b/crates/shirabe/src/package/loader/root_package_loader.rs @@ -15,7 +15,7 @@ use crate::repository::RepositoryManager; use crate::util::Platform; use crate::util::ProcessExecutor; use indexmap::IndexMap; -use shirabe_pcre::{CaptureKey, Preg}; +use shirabe_pcre::{CaptureKey, Preg, PregMatchedGroups}; use shirabe_php_shim::{ PhpMixed, RuntimeException, UnexpectedValueException, php_regex, preg_split, strtolower, }; @@ -252,7 +252,7 @@ impl RootPackageLoader { mut aliases: Vec<IndexMap<String, String>>, ) -> Vec<IndexMap<String, String>> { for (req_name, req_version) in requires { - let mut m: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut m = PregMatchedGroups::new(); if Preg::is_match3( php_regex!(r"{(?:^|\| *|, *)([^,\s#|]+)(?:#[^ ]+)? +as +([^,\s|]+)(?:$| *\|| *,)}"), req_version, @@ -318,7 +318,7 @@ impl RootPackageLoader { let mut matched = false; for constraint in &constraints { - let mut m: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut m = PregMatchedGroups::new(); if Preg::is_match3(&pattern, constraint, Some(&mut m)) { let name = strtolower(req_name); let m1 = m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default(); @@ -365,7 +365,7 @@ impl RootPackageLoader { ) -> IndexMap<String, String> { for (req_name, req_version) in requires { let req_version = Preg::replace(php_regex!(r"{^([^,\s@]+) as .+$}"), "$1", req_version); - let mut m: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut m = PregMatchedGroups::new(); if Preg::is_match3( php_regex!(r"{^[^,\s@]+?#([a-f0-9]+)$}"), &req_version, diff --git a/crates/shirabe/src/package/locker.rs b/crates/shirabe/src/package/locker.rs index ccfb2ddf..5c99b967 100644 --- a/crates/shirabe/src/package/locker.rs +++ b/crates/shirabe/src/package/locker.rs @@ -24,7 +24,7 @@ use crate::repository::RootPackageRepository; use crate::util::Git as GitUtil; use crate::util::ProcessExecutor; use indexmap::IndexMap; -use shirabe_pcre::{CaptureKey, Preg}; +use shirabe_pcre::{CaptureKey, Preg, PregMatchedGroups}; use shirabe_php_shim::Catch as _; use shirabe_php_shim::{ DATE_RFC3339, LogicException, PhpMixed, RuntimeException, array_intersect, array_keys, @@ -844,7 +844,7 @@ impl Locker { &mut output, path.as_deref(), )? { - let mut m: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut m = PregMatchedGroups::new(); if Preg::is_match3( php_regex!(r"{^\s*(\d+)\s*}"), output.as_string().unwrap_or(""), diff --git a/crates/shirabe/src/package/package.rs b/crates/shirabe/src/package/package.rs index 4e35ee55..2054d396 100644 --- a/crates/shirabe/src/package/package.rs +++ b/crates/shirabe/src/package/package.rs @@ -433,7 +433,7 @@ impl Package { // dist URL never carries more than one SHA reference. self.set_dist_url(Some(Preg::replace_callback( php_regex!("{(/|sha=)[a-f0-9]{40}(/|$)}i"), - |m: &indexmap::IndexMap<shirabe_pcre::CaptureKey, String>| -> String { + |m: &shirabe_pcre::PregMatchedGroups| -> String { let get = |i: usize| -> String { m.get(&shirabe_pcre::CaptureKey::ByIndex(i)) .cloned() diff --git a/crates/shirabe/src/package/version/version_bumper.rs b/crates/shirabe/src/package/version/version_bumper.rs index 83df211a..dbeff6a0 100644 --- a/crates/shirabe/src/package/version/version_bumper.rs +++ b/crates/shirabe/src/package/version/version_bumper.rs @@ -5,8 +5,7 @@ use crate::package::dumper::ArrayDumper; use crate::package::loader::ArrayLoader; use crate::package::version::VersionParser; use crate::util::Platform; -use indexmap::IndexMap; -use shirabe_pcre::{CaptureKey, Preg}; +use shirabe_pcre::{CaptureKey, Preg, PregMatchesAllWithOffsets}; use shirabe_php_shim::php_regex; use shirabe_semver::Intervals; use shirabe_semver::constraint::AnyConstraint; @@ -78,7 +77,7 @@ impl VersionBumper { major = major ); - let mut matches: IndexMap<CaptureKey, Vec<(Option<String>, i64)>> = IndexMap::new(); + let mut matches = PregMatchesAllWithOffsets::new(); if Preg::is_match_all_with_offsets3(&pattern, &pretty_constraint, Some(&mut matches)) { let mut modified = pretty_constraint.clone(); let constraint_matches = matches diff --git a/crates/shirabe/src/package/version/version_guesser.rs b/crates/shirabe/src/package/version/version_guesser.rs index 2fde58fb..4f46919e 100644 --- a/crates/shirabe/src/package/version/version_guesser.rs +++ b/crates/shirabe/src/package/version/version_guesser.rs @@ -12,7 +12,7 @@ use crate::util::ProcessExecutor; use crate::util::Svn as SvnUtil; use crate::util::sync_executor; use indexmap::IndexMap; -use shirabe_pcre::{CaptureKey, Preg}; +use shirabe_pcre::{CaptureKey, Preg, PregMatchedGroups}; use shirabe_php_shim::{ PhpMixed, RuntimeException, array_keys, array_map, array_merge, empty, function_exists, implode, is_string, json_encode, php_regex, preg_quote, str_replace, strlen, strnatcasecmp, @@ -229,7 +229,7 @@ impl VersionGuesser { // find current branch and collect all branch names for branch in self.process.borrow().split_lines(&output) { if !branch.is_empty() { - let mut m: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut m = PregMatchedGroups::new(); if Preg::is_match3( php_regex!( r"{^(?:\* ) *(\(no branch\)|\(detached from \S+\)|\(HEAD detached at \S+\)|\S+) *([a-f0-9]+) .*$}" @@ -258,10 +258,10 @@ impl VersionGuesser { } if !branch.is_empty() && { - let mut tmp: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut tmp = PregMatchedGroups::new(); !Preg::is_match3(php_regex!(r"{^ *.+/HEAD }"), &branch, Some(&mut tmp)) } { - let mut m: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut m = PregMatchedGroups::new(); if Preg::is_match3( php_regex!( r"{^(?:\* )? *((?:remotes/(?:origin|upstream)/)?[^\s/]+) *([a-f0-9]+) .*$}" @@ -756,7 +756,7 @@ impl VersionGuesser { .into()); } }; - let mut m: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut m = PregMatchedGroups::new(); if Preg::is_match3( php_regex!(r"{^(\d+(?:\.\d+)*)-dev$}i"), &version, diff --git a/crates/shirabe/src/platform/version.rs b/crates/shirabe/src/platform/version.rs index b3eacd4c..2bcb4c38 100644 --- a/crates/shirabe/src/platform/version.rs +++ b/crates/shirabe/src/platform/version.rs @@ -1,7 +1,6 @@ //! ref: composer/src/Composer/Platform/Version.php -use indexmap::IndexMap; -use shirabe_pcre::{CaptureKey, Preg}; +use shirabe_pcre::{CaptureKey, Preg, PregMatchedGroups}; use shirabe_php_shim::{CmpOp, php_regex, version_compare}; pub struct Version; @@ -10,7 +9,7 @@ impl Version { pub fn parse_openssl(openssl_version: &str, is_fips: &mut bool) -> Option<String> { *is_fips = false; - let mut matches: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut matches = PregMatchedGroups::new(); if !Preg::match3( php_regex!( r"/^(?P<version>[0-9.]+)(?P<patch>[a-z]{0,2})(?P<suffix>(?:-?(?:dev|pre|alpha|beta|rc|fips)[\d]*)*)(?:-\w+)?(?: \(.+?\))?$/" @@ -56,7 +55,7 @@ impl Version { } pub fn parse_libjpeg(libjpeg_version: &str) -> Option<String> { - let mut matches: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut matches = PregMatchedGroups::new(); if !Preg::match3( php_regex!(r"/^(?P<major>\d+)(?P<minor>[a-z]*)$/"), libjpeg_version, @@ -81,7 +80,7 @@ impl Version { } pub fn parse_zoneinfo_version(zoneinfo_version: &str) -> Option<String> { - let mut matches: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut matches = PregMatchedGroups::new(); if !Preg::match3( php_regex!(r"/^(?P<year>\d{4})(?P<revision>[a-z]*)$/"), zoneinfo_version, diff --git a/crates/shirabe/src/repository/composer_repository.rs b/crates/shirabe/src/repository/composer_repository.rs index 5f9314b4..33703709 100644 --- a/crates/shirabe/src/repository/composer_repository.rs +++ b/crates/shirabe/src/repository/composer_repository.rs @@ -37,7 +37,7 @@ use futures::StreamExt; use futures::stream::FuturesOrdered; use indexmap::IndexMap; use shirabe_metadata_minifier::MetadataMinifier; -use shirabe_pcre::{CaptureKey, Preg}; +use shirabe_pcre::{CaptureKey, Preg, PregMatchedGroups}; use shirabe_php_shim::Catch as _; use shirabe_php_shim::{ AnyThrowable, CmpOp, InvalidArgumentException, LogicException, PHP_EOL, PhpMixed, @@ -245,7 +245,7 @@ impl ComposerRepository { .to_string(); // force url for packagist.org to repo.packagist.org - let mut match_packagist: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut match_packagist = PregMatchedGroups::new(); if Preg::is_match3( php_regex!(r"{^(?P<proto>https?)://packagist\.org/?$}i"), &url, @@ -781,7 +781,7 @@ impl ComposerRepository { if self.has_providers()? || self.lazy_providers_url.is_some() { // optimize search for "^foo/bar" where at least "^foo/" is present by loading this directly from the listUrl if present - let mut match_groups: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut match_groups = PregMatchedGroups::new(); if Preg::is_match3( php_regex!(r"{^\^(?P<query>(?P<vendor>[a-z0-9_.-]+)/[a-z0-9_.-]*)\*?$}i"), &query, @@ -2430,7 +2430,7 @@ impl ComposerRepository { } if url.starts_with('/') { - let mut matches: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut matches = PregMatchedGroups::new(); if Preg::is_match3( php_regex!(r"{^[^:]++://[^/]*+}"), &self.url, diff --git a/crates/shirabe/src/repository/platform_repository.rs b/crates/shirabe/src/repository/platform_repository.rs index 7c7030f0..6c25d967 100644 --- a/crates/shirabe/src/repository/platform_repository.rs +++ b/crates/shirabe/src/repository/platform_repository.rs @@ -16,7 +16,7 @@ use crate::plugin::plugin_interface::{self}; use crate::repository::ArrayRepository; use crate::repository::RepositoryInterface; use indexmap::IndexMap; -use shirabe_pcre::{CaptureKey, Preg}; +use shirabe_pcre::{CaptureKey, Preg, PregMatchedGroups}; use shirabe_php_rpc::PlatformInfo; use shirabe_php_shim::{ InvalidArgumentException, PhpMixed, UnexpectedValueException, array_map_str_fn, @@ -316,7 +316,7 @@ impl PlatformRepository { let info = platform_info.get_extension_info(name); // librabbitmq version => 0.9.0 - let mut librabbitmq_matches: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut librabbitmq_matches = PregMatchedGroups::new(); if Preg::is_match3( php_regex!("/^librabbitmq version => (?<version>.+)$/im"), info, @@ -335,7 +335,7 @@ impl PlatformRepository { } // AMQP protocol version => 0-9-1 - let mut protocol_matches: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut protocol_matches = PregMatchedGroups::new(); if Preg::is_match3( php_regex!("/^AMQP protocol version => (?<version>.+)$/im"), info, @@ -360,7 +360,7 @@ impl PlatformRepository { let info = platform_info.get_extension_info(name); // BZip2 Version => 1.0.6, 6-Sept-2010 - let mut matches: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut matches = PregMatchedGroups::new(); if Preg::is_match3( php_regex!("/^BZip2 Version => (?<version>.*),/im"), info, @@ -393,7 +393,7 @@ impl PlatformRepository { let info = platform_info.get_extension_info(name); // SSL Version => OpenSSL/1.0.1t - let mut ssl_matches: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut ssl_matches = PregMatchedGroups::new(); if Preg::is_match3( php_regex!("{^SSL Version => (?<library>[^/]+)/(?<version>.+)$}im"), info, @@ -428,8 +428,7 @@ impl PlatformRepository { } else { let (shortlib, ssl_lib); if library.starts_with("(securetransport)") { - let mut securetransport_matches: IndexMap<CaptureKey, String> = - IndexMap::new(); + let mut securetransport_matches = PregMatchedGroups::new(); if Preg::is_match3( php_regex!("{^\\(securetransport\\) ([a-z0-9]+)}"), &library, @@ -461,7 +460,7 @@ impl PlatformRepository { } // libSSH Version => libssh2/1.4.3 - let mut ssh_matches: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut ssh_matches = PregMatchedGroups::new(); if Preg::is_match3( php_regex!( "{^libSSH Version => (?<library>[^/]+)/(?<version>.+?)(?:/.*)?$}im" @@ -488,7 +487,7 @@ impl PlatformRepository { } // ZLib Version => 1.2.8 - let mut zlib_matches: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut zlib_matches = PregMatchedGroups::new(); if Preg::is_match3( php_regex!("{^ZLib Version => (?<version>.+)$}im"), info, @@ -511,7 +510,7 @@ impl PlatformRepository { let info = platform_info.get_extension_info(name); // timelib version => 2018.03 - let mut timelib_matches: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut timelib_matches = PregMatchedGroups::new(); if Preg::is_match3( php_regex!("/^timelib version => (?<version>.+)$/im"), info, @@ -530,7 +529,7 @@ impl PlatformRepository { } // Timezone Database => internal - let mut zoneinfo_source_matches: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut zoneinfo_source_matches = PregMatchedGroups::new(); if Preg::is_match3( php_regex!("/^Timezone Database => (?<source>internal|external)$/im"), info, @@ -540,7 +539,7 @@ impl PlatformRepository { .get(&CaptureKey::ByName("source".to_string())) .map(|s| s == "external") .unwrap_or(false); - let mut zoneinfo_matches: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut zoneinfo_matches = PregMatchedGroups::new(); if Preg::is_match3( php_regex!( "/^\"Olson\" Timezone Database Version => (?<version>.+?)(?:\\.system)?$/im" @@ -582,7 +581,7 @@ impl PlatformRepository { let info = platform_info.get_extension_info(name); // libmagic => 537 - let mut magic_matches: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut magic_matches = PregMatchedGroups::new(); if Preg::is_match3( php_regex!("/^libmagic => (?<version>.+)$/im"), info, @@ -618,7 +617,7 @@ impl PlatformRepository { let info = platform_info.get_extension_info(name); - let mut libjpeg_matches: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut libjpeg_matches = PregMatchedGroups::new(); if Preg::is_match3( php_regex!("/^libJPEG Version => (?<version>.+?)(?: compatible)?$/im"), info, @@ -639,7 +638,7 @@ impl PlatformRepository { )?; } - let mut libpng_matches: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut libpng_matches = PregMatchedGroups::new(); if Preg::is_match3( php_regex!("/^libPNG Version => (?<version>.+)$/im"), info, @@ -657,7 +656,7 @@ impl PlatformRepository { )?; } - let mut freetype_matches: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut freetype_matches = PregMatchedGroups::new(); if Preg::is_match3( php_regex!("/^FreeType Version => (?<version>.+)$/im"), info, @@ -675,7 +674,7 @@ impl PlatformRepository { )?; } - let mut libxpm_matches: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut libxpm_matches = PregMatchedGroups::new(); if Preg::is_match3( php_regex!("/^libXpm Version => (?<versionId>\\d+)$/im"), info, @@ -749,7 +748,7 @@ impl PlatformRepository { &[], )?; } else { - let mut matches: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut matches = PregMatchedGroups::new(); if Preg::is_match3( php_regex!("/^ICU version => (?<version>.+)$/im"), info, @@ -769,7 +768,7 @@ impl PlatformRepository { } // ICU TZData version => 2019c - let mut zoneinfo_matches: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut zoneinfo_matches = PregMatchedGroups::new(); if Preg::is_match3( php_regex!("/^ICU TZData version => (?<version>.*)$/im"), info, @@ -834,7 +833,7 @@ impl PlatformRepository { Self::imagick_get_version_string(image_magick_version); // 6.x: ImageMagick 6.2.9 08/24/06 Q16 http://www.imagemagick.org // 7.x: ImageMagick 7.0.8-34 Q16 x86_64 2019-03-23 https://imagemagick.org - let mut matches: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut matches = PregMatchedGroups::new(); if Preg::is_match3( php_regex!("/^ImageMagick (?<version>[\\d.]+)(?:-(?<patch>\\d+))?/"), &image_magick_version_str, @@ -862,8 +861,8 @@ impl PlatformRepository { "ldap" => { let info = platform_info.get_extension_info(name); - let mut matches: IndexMap<CaptureKey, String> = IndexMap::new(); - let mut vendor_matches: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut matches = PregMatchedGroups::new(); + let mut vendor_matches = PregMatchedGroups::new(); if Preg::is_match3( php_regex!("/^Vendor Version => (?<versionId>\\d+)$/im"), info, @@ -922,7 +921,7 @@ impl PlatformRepository { let info = platform_info.get_extension_info(name); // libmbfl version => 1.3.2 - let mut libmbfl_matches: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut libmbfl_matches = PregMatchedGroups::new(); if Preg::is_match3( php_regex!("/^libmbfl version => (?<version>.+)$/im"), info, @@ -958,7 +957,7 @@ impl PlatformRepository { // Multibyte regex (oniguruma) version => 5.9.5 // oniguruma version => 6.9.0 } else { - let mut oniguruma_matches: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut oniguruma_matches = PregMatchedGroups::new(); if Preg::is_match3( php_regex!( "/^(?:oniguruma|Multibyte regex \\(oniguruma\\)) version => (?<version>.+)$/im" @@ -984,7 +983,7 @@ impl PlatformRepository { let info = platform_info.get_extension_info(name); // libmemcached version => 1.0.18 - let mut matches: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut matches = PregMatchedGroups::new(); if Preg::is_match3( php_regex!("/^libmemcached version => (?<version>.+)$/im"), info, @@ -1010,7 +1009,7 @@ impl PlatformRepository { _ => "".to_string(), }; // OpenSSL 1.1.1g 21 Apr 2020 - let mut matches: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut matches = PregMatchedGroups::new(); if Preg::is_match3( php_regex!("{^(?:OpenSSL|LibreSSL)?\\s*(?<version>\\S+)}i"), &openssl_text_str, @@ -1051,7 +1050,7 @@ impl PlatformRepository { let info = platform_info.get_extension_info(name); // PCRE Unicode Version => 12.1.0 - let mut pcre_unicode_matches: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut pcre_unicode_matches = PregMatchedGroups::new(); if Preg::is_match3( php_regex!("/^PCRE Unicode Version => (?<version>.+)$/im"), info, @@ -1073,7 +1072,7 @@ impl PlatformRepository { "mysqlnd" | "pdo_mysql" => { let info = platform_info.get_extension_info(name); - let mut matches: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut matches = PregMatchedGroups::new(); if Preg::is_match3( php_regex!( "/^(?:Client API version|Version) => mysqlnd (?<version>.+?) /mi" @@ -1097,7 +1096,7 @@ impl PlatformRepository { "mongodb" => { let info = platform_info.get_extension_info(name); - let mut libmongoc_matches: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut libmongoc_matches = PregMatchedGroups::new(); if Preg::is_match3( php_regex!("/^libmongoc bundled version => (?<version>.+)$/im"), info, @@ -1115,7 +1114,7 @@ impl PlatformRepository { )?; } - let mut libbson_matches: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut libbson_matches = PregMatchedGroups::new(); if Preg::is_match3( php_regex!("/^libbson bundled version => (?<version>.+)$/im"), info, @@ -1153,7 +1152,7 @@ impl PlatformRepository { // intentional fall-through to next case... let info = platform_info.get_extension_info(name); - let mut matches: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut matches = PregMatchedGroups::new(); if Preg::is_match3( php_regex!("/^PostgreSQL\\(libpq\\) Version => (?<version>.*)$/im"), info, @@ -1176,7 +1175,7 @@ impl PlatformRepository { "pdo_pgsql" => { let info = platform_info.get_extension_info(name); - let mut matches: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut matches = PregMatchedGroups::new(); if Preg::is_match3( php_regex!("/^PostgreSQL\\(libpq\\) Version => (?<version>.*)$/im"), info, @@ -1200,7 +1199,7 @@ impl PlatformRepository { // Used Library => Compiled => Linked // libpq => 14.3 (Ubuntu 14.3-1.pgdg22.04+1) => 15.0.2 - let mut matches: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut matches = PregMatchedGroups::new(); if Preg::is_match3( php_regex!("/^libpq => (?<compiled>.+) => (?<linked>.+)$/im"), info, @@ -1278,7 +1277,7 @@ impl PlatformRepository { "sqlite3" | "pdo_sqlite" => { let info = platform_info.get_extension_info(name); - let mut matches: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut matches = PregMatchedGroups::new(); if Preg::is_match3( php_regex!("/^SQLite Library => (?<version>.+)$/im"), info, @@ -1300,7 +1299,7 @@ impl PlatformRepository { "ssh2" => { let info = platform_info.get_extension_info(name); - let mut matches: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut matches = PregMatchedGroups::new(); if Preg::is_match3( php_regex!("/^libssh2 version => (?<version>.+)$/im"), info, @@ -1336,7 +1335,7 @@ impl PlatformRepository { )?; let info = platform_info.get_extension_info("xsl"); - let mut matches: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut matches = PregMatchedGroups::new(); if Preg::is_match3( php_regex!( "/^libxslt compiled against libxml Version => (?<version>.+)$/im" @@ -1360,7 +1359,7 @@ impl PlatformRepository { "yaml" => { let info = platform_info.get_extension_info("yaml"); - let mut matches: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut matches = PregMatchedGroups::new(); if Preg::is_match3( php_regex!("/^LibYAML Version => (?<version>.+)$/im"), info, @@ -1417,7 +1416,7 @@ impl PlatformRepository { // Linked Version => 1.2.8 } else { let info = platform_info.get_extension_info(name); - let mut matches: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut matches = PregMatchedGroups::new(); if Preg::is_match3( php_regex!("/^Linked Version => (?<version>.+)$/im"), info, @@ -1620,7 +1619,7 @@ impl PlatformRepository { Ok(v) => v, Err(_) => { extra_description = Some(format!(" (actual version: {})", pretty_version)); - let mut m: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut m = PregMatchedGroups::new(); if Preg::is_match3( php_regex!("{^(\\d+\\.\\d+\\.\\d+(?:\\.\\d+)?)}"), &pretty_version, diff --git a/crates/shirabe/src/repository/vcs/forgejo_driver.rs b/crates/shirabe/src/repository/vcs/forgejo_driver.rs index 7687db0d..9a656a65 100644 --- a/crates/shirabe/src/repository/vcs/forgejo_driver.rs +++ b/crates/shirabe/src/repository/vcs/forgejo_driver.rs @@ -15,7 +15,7 @@ use crate::util::ForgejoRepositoryData; use crate::util::ForgejoUrl; use crate::util::http::Response; use indexmap::IndexMap; -use shirabe_pcre::{CaptureKey, Preg}; +use shirabe_pcre::{CaptureKey, Preg, PregMatchedGroups}; use shirabe_php_shim::Catch as _; use shirabe_php_shim::{ PhpMixed, RuntimeException, base64_decode, explode, extension_loaded, php_regex, urlencode, @@ -584,7 +584,7 @@ impl ForgejoDriver { let links = explode(",", &header); for link in links { - let mut m: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut m = PregMatchedGroups::new(); if Preg::match3(php_regex!(r#"{<(.+?)>; *rel="next"}"#), &link, Some(&mut m)) && let Some(url) = m.get(&CaptureKey::ByIndex(1)) { diff --git a/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs b/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs index 9558e3b2..964c4b10 100644 --- a/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs +++ b/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs @@ -15,7 +15,7 @@ use crate::util::Bitbucket; use crate::util::http::Response; use chrono::{DateTime, FixedOffset}; use indexmap::IndexMap; -use shirabe_pcre::{CaptureKey, Preg}; +use shirabe_pcre::{CaptureKey, Preg, PregMatchedGroups}; use shirabe_php_shim::Catch as _; use shirabe_php_shim::{ InvalidArgumentException, LogicException, PhpMixed, RuntimeException, array_key_exists, @@ -84,7 +84,7 @@ impl GitBitbucketDriver { /// @inheritDoc pub fn initialize(&mut self) -> anyhow::Result<()> { - let mut m: indexmap::IndexMap<CaptureKey, String> = indexmap::IndexMap::new(); + let mut m = PregMatchedGroups::new(); if !Preg::is_match3( php_regex!(r"#^https?://bitbucket\.org/([^/]+)/([^/]+?)(?:\.git|/?)?$#i"), &self.inner.url, diff --git a/crates/shirabe/src/repository/vcs/git_driver.rs b/crates/shirabe/src/repository/vcs/git_driver.rs index f39e142a..c46a6664 100644 --- a/crates/shirabe/src/repository/vcs/git_driver.rs +++ b/crates/shirabe/src/repository/vcs/git_driver.rs @@ -14,7 +14,7 @@ use crate::util::Url; use chrono::TimeZone; use chrono::{DateTime, FixedOffset, Utc}; use indexmap::IndexMap; -use shirabe_pcre::{CaptureKey, Preg}; +use shirabe_pcre::{CaptureKey, Preg, PregMatchedGroups}; use shirabe_php_shim::Catch as _; use shirabe_php_shim::{ InvalidArgumentException, RuntimeException, dirname, is_dir, is_writable, realpath, @@ -199,7 +199,7 @@ impl GitDriver { if !branches.contains(&"* master".to_string()) { for branch in &branches { if !branch.is_empty() { - let mut caps: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut caps = PregMatchedGroups::new(); if Preg::match3(php_regex!(r"{^\* +(\S+)}"), branch, Some(&mut caps)) && let Some(name) = caps.get(&CaptureKey::ByIndex(1)) { @@ -311,7 +311,7 @@ impl GitDriver { ); for tag in self.inner.process.borrow().split_lines(&output) { if !tag.is_empty() { - let mut caps: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut caps = PregMatchedGroups::new(); if Preg::match3( php_regex!(r"{^([a-f0-9]{40}) refs/tags/(\S+?)(\^\{\})?$}"), &tag, @@ -350,7 +350,7 @@ impl GitDriver { ); for branch in self.inner.process.borrow().split_lines(&output) { if !branch.is_empty() && !Preg::is_match(php_regex!(r"{^ *[^/]+/HEAD }"), &branch) { - let mut caps: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut caps = PregMatchedGroups::new(); if Preg::match3( php_regex!(r"{^(?:\* )? *(\S+) *([a-f0-9]+)(?: .*)?$}"), &branch, diff --git a/crates/shirabe/src/repository/vcs/github_driver.rs b/crates/shirabe/src/repository/vcs/github_driver.rs index 4c0df86a..10a61feb 100644 --- a/crates/shirabe/src/repository/vcs/github_driver.rs +++ b/crates/shirabe/src/repository/vcs/github_driver.rs @@ -14,7 +14,7 @@ use crate::util::GitHub; use crate::util::http::Response; use chrono::{DateTime, FixedOffset}; use indexmap::IndexMap; -use shirabe_pcre::{CaptureKey, Preg}; +use shirabe_pcre::{CaptureKey, Preg, PregMatchedGroups}; use shirabe_php_shim::Catch as _; use shirabe_php_shim::{ InvalidArgumentException, PhpMixed, RuntimeException, array_diff, array_map, @@ -70,7 +70,7 @@ impl GitHubDriver { } pub fn initialize(&mut self) -> anyhow::Result<()> { - let mut match_: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut match_ = PregMatchedGroups::new(); if !Preg::is_match3( php_regex!( r"#^(?:(?:https?|git)://([^/]+)/|git@([^:]+):/?)([^/]+)/([^/]+?)(?:\.git|/)?$#" @@ -495,7 +495,7 @@ impl GitHubDriver { let mut key: Option<String> = None; for line in preg_split(php_regex!(r"{\r?\n}"), &funding) { let line = trim(&line, None); - let mut m: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut m = PregMatchedGroups::new(); if Preg::is_match3(php_regex!(r"{^(\w+)\s*:\s*(.+)$}"), &line, Some(&mut m)) { let g1 = m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default(); let g2 = m.get(&CaptureKey::ByIndex(2)).cloned().unwrap_or_default(); @@ -503,7 +503,7 @@ impl GitHubDriver { key = Some(g1); continue; } - let mut m2: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut m2 = PregMatchedGroups::new(); if Preg::is_match3(php_regex!(r"{^\[(.*?)\](?:\s*#.*)?$}"), &g2, Some(&mut m2)) { let inner = m2.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default(); for item in array_map( @@ -538,7 +538,7 @@ impl GitHubDriver { } else if Preg::is_match3(php_regex!(r"{^(\w+)\s*:\s*#\s*$}"), &line, Some(&mut m)) { key = Some(m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default()); } else if key.is_some() && { - let mut tmp: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut tmp = PregMatchedGroups::new(); Preg::is_match3(php_regex!(r"{^-\s*(.+)(?:\s+#.*)?$}"), &line, Some(&mut m)) || Preg::is_match3(php_regex!(r"{^(.+),(?:\s*#.*)?$}"), &line, Some(&mut tmp)) && { @@ -936,7 +936,7 @@ impl GitHubDriver { url: &str, _deep: bool, ) -> anyhow::Result<bool> { - let mut matches: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut matches = PregMatchedGroups::new(); if !Preg::is_match3( php_regex!( r"#^((?:https?|git)://([^/]+)/|git@([^:]+):/?)([^/]+)/([^/]+?)(?:\.git|/)?$#" @@ -1284,7 +1284,7 @@ impl GitHubDriver { let links = explode(",", &header); for link in &links { - let mut m: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut m = PregMatchedGroups::new(); if Preg::is_match3(php_regex!(r#"{<(.+?)>; *rel="next"}"#), link, Some(&mut m)) { return Some(m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default()); } diff --git a/crates/shirabe/src/repository/vcs/gitlab_driver.rs b/crates/shirabe/src/repository/vcs/gitlab_driver.rs index df1ad686..c141cc9a 100644 --- a/crates/shirabe/src/repository/vcs/gitlab_driver.rs +++ b/crates/shirabe/src/repository/vcs/gitlab_driver.rs @@ -15,7 +15,7 @@ use crate::util::HttpDownloader; use crate::util::http::Response; use chrono::{DateTime, FixedOffset}; use indexmap::IndexMap; -use shirabe_pcre::{CaptureKey, Preg}; +use shirabe_pcre::{CaptureKey, Preg, PregMatchedGroups}; use shirabe_php_shim::Catch as _; use shirabe_php_shim::{ InvalidArgumentException, LogicException, PhpMixed, RuntimeException, array_search_mixed, @@ -81,7 +81,7 @@ impl GitLabDriver { /// /// SSH urls use https by default. Set "secure-http": false on the repository config to use http instead. pub fn initialize(&mut self) -> anyhow::Result<()> { - let mut match_: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut match_ = PregMatchedGroups::new(); if !Preg::is_match3(Self::URL_REGEX, &self.inner.url, Some(&mut match_)) { return Err(InvalidArgumentException::new(format!( "The GitLab repository URL {} is invalid. It must be the HTTP URL of a GitLab project.", @@ -945,7 +945,7 @@ impl GitLabDriver { url: &str, _deep: bool, ) -> anyhow::Result<bool> { - let mut match_: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut match_ = PregMatchedGroups::new(); if !Preg::is_match3(Self::URL_REGEX, url, Some(&mut match_)) { return Ok(false); } @@ -1011,7 +1011,7 @@ impl GitLabDriver { let links = explode(",", &header); for link in &links { - let mut match_: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut match_ = PregMatchedGroups::new(); if Preg::is_match3( php_regex!(r#"{<(.+?)>; *rel="next"}"#), link, diff --git a/crates/shirabe/src/repository/vcs/hg_driver.rs b/crates/shirabe/src/repository/vcs/hg_driver.rs index f4e02685..d617099e 100644 --- a/crates/shirabe/src/repository/vcs/hg_driver.rs +++ b/crates/shirabe/src/repository/vcs/hg_driver.rs @@ -11,7 +11,7 @@ use crate::util::Hg as HgUtils; use crate::util::Url; use chrono::{DateTime, FixedOffset, Utc}; use indexmap::IndexMap; -use shirabe_pcre::{CaptureKey, Preg}; +use shirabe_pcre::{CaptureKey, Preg, PregMatchedGroups}; use shirabe_php_shim::Catch as _; use shirabe_php_shim::{PhpMixed, RuntimeException, dirname, is_dir, is_writable, php_regex}; @@ -233,7 +233,7 @@ impl HgDriver { ); for tag in self.inner.process.borrow().split_lines(&output) { if !tag.is_empty() { - let mut m: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut m = PregMatchedGroups::new(); if Preg::match3(php_regex!(r"(^([^\s]+)\s+\d+:(.*)$)"), &tag, Some(&mut m)) { tags.insert( m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default(), @@ -263,7 +263,7 @@ impl HgDriver { ); for branch in self.inner.process.borrow().split_lines(&output) { if !branch.is_empty() { - let mut m: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut m = PregMatchedGroups::new(); if Preg::match3( php_regex!(r"(^([^\s]+)\s+\d+:([a-f0-9]+))"), &branch, @@ -288,7 +288,7 @@ impl HgDriver { ); for branch in self.inner.process.borrow().split_lines(&output) { if !branch.is_empty() { - let mut m: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut m = PregMatchedGroups::new(); if Preg::match3( php_regex!(r"(^(?:[\s*]*)([^\s]+)\s+\d+:(.*)$)"), &branch, diff --git a/crates/shirabe/src/repository/vcs/svn_driver.rs b/crates/shirabe/src/repository/vcs/svn_driver.rs index dd74400d..297e8f33 100644 --- a/crates/shirabe/src/repository/vcs/svn_driver.rs +++ b/crates/shirabe/src/repository/vcs/svn_driver.rs @@ -13,7 +13,7 @@ use crate::util::Svn as SvnUtil; use crate::util::Url; use chrono::{DateTime, FixedOffset, Utc}; use indexmap::IndexMap; -use shirabe_pcre::{CaptureKey, Preg}; +use shirabe_pcre::{CaptureKey, Preg, PregMatchedGroups}; use shirabe_php_shim::Catch as _; use shirabe_php_shim::{ PhpMixed, RuntimeException, php_regex, stripos, strrpos, strtr, substr, trim, @@ -318,7 +318,7 @@ impl SvnDriver { )?; for line in self.inner.process.borrow().split_lines(&output) { if !line.is_empty() { - let mut m: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut m = PregMatchedGroups::new(); if Preg::is_match3( php_regex!(r"{^Last Changed Date: ([^(]+)}"), &line, @@ -350,7 +350,7 @@ impl SvnDriver { for line in self.inner.process.borrow().split_lines(&output) { let line = trim(&line, None); if !line.is_empty() { - let mut m: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut m = PregMatchedGroups::new(); if Preg::is_match3( php_regex!(r"{^\s*(\S+).*?(\S+)\s*$}"), &line, @@ -401,7 +401,7 @@ impl SvnDriver { for line in self.inner.process.borrow().split_lines(&output) { let line = trim(&line, None); if !line.is_empty() { - let mut m: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut m = PregMatchedGroups::new(); if Preg::is_match3( php_regex!(r"{^\s*(\S+).*?(\S+)\s*$}"), &line, @@ -443,7 +443,7 @@ impl SvnDriver { { let line = trim(&line, None); if !line.is_empty() { - let mut m: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut m = PregMatchedGroups::new(); if Preg::is_match3( php_regex!(r"{^\s*(\S+).*?(\S+)\s*$}"), &line, diff --git a/crates/shirabe/src/util/composer_mirror.rs b/crates/shirabe/src/util/composer_mirror.rs index 1e57662a..1455613d 100644 --- a/crates/shirabe/src/util/composer_mirror.rs +++ b/crates/shirabe/src/util/composer_mirror.rs @@ -1,6 +1,6 @@ //! ref: composer/src/Composer/Util/ComposerMirror.php -use shirabe_pcre::{CaptureKey, Preg}; +use shirabe_pcre::{CaptureKey, Preg, PregMatchedGroups}; use shirabe_php_shim::{hash, php_regex}; pub struct ComposerMirror; @@ -53,8 +53,8 @@ impl ComposerMirror { url: &str, r#type: Option<&str>, ) -> String { - let mut gh_matches: indexmap::IndexMap<CaptureKey, String> = indexmap::IndexMap::new(); - let mut bb_matches: indexmap::IndexMap<CaptureKey, String> = indexmap::IndexMap::new(); + let mut gh_matches = PregMatchedGroups::new(); + let mut bb_matches = PregMatchedGroups::new(); let normalized_url = if Preg::match3( php_regex!( r"#^(?:(?:https?|git)://github\.com/|git@github\.com:)([^/]+)/(.+?)(?:\.git)?$#" diff --git a/crates/shirabe/src/util/filesystem.rs b/crates/shirabe/src/util/filesystem.rs index 1a9ab703..21512a81 100644 --- a/crates/shirabe/src/util/filesystem.rs +++ b/crates/shirabe/src/util/filesystem.rs @@ -735,8 +735,7 @@ impl Filesystem { } // extract a prefix being a protocol://, protocol:, protocol://drive: or simply drive: - let mut prefix_match: indexmap::IndexMap<shirabe_pcre::CaptureKey, String> = - indexmap::IndexMap::new(); + let mut prefix_match = shirabe_pcre::PregMatchedGroups::new(); if Preg::is_match3( php_regex!("{^( [0-9a-z]{2,}+: (?: // (?: [a-z]: )? )? | [a-z]: )}ix"), &path, @@ -768,7 +767,7 @@ impl Filesystem { // ensure c: is normalized to C: prefix = Preg::replace_callback( php_regex!("{(^|://)[a-z]:$}i"), - |m: &indexmap::IndexMap<shirabe_pcre::CaptureKey, String>| -> String { + |m: &shirabe_pcre::PregMatchedGroups| -> String { let s = m .get(&shirabe_pcre::CaptureKey::ByIndex(0)) .cloned() diff --git a/crates/shirabe/src/util/forgejo_url.rs b/crates/shirabe/src/util/forgejo_url.rs index d2628409..7a5d2b10 100644 --- a/crates/shirabe/src/util/forgejo_url.rs +++ b/crates/shirabe/src/util/forgejo_url.rs @@ -37,8 +37,7 @@ impl ForgejoUrl { pub fn try_from(repo_url: Option<&str>) -> Option<Self> { let repo_url = repo_url?; - let mut matches: indexmap::IndexMap<shirabe_pcre::CaptureKey, String> = - indexmap::IndexMap::new(); + let mut matches = shirabe_pcre::PregMatchedGroups::new(); if !Preg::match3(Self::URL_REGEX, repo_url, Some(&mut matches)) { return None; } diff --git a/crates/shirabe/src/util/git.rs b/crates/shirabe/src/util/git.rs index f8fea562..0f463aea 100644 --- a/crates/shirabe/src/util/git.rs +++ b/crates/shirabe/src/util/git.rs @@ -14,7 +14,7 @@ use crate::util::ProcessExecutor; use crate::util::Url; use crate::util::{AuthHelper, StoreAuth}; use indexmap::IndexMap; -use shirabe_pcre::{CaptureKey, Preg}; +use shirabe_pcre::{CaptureKey, Preg, PregMatchedGroups}; use shirabe_php_shim::{ AnyThrowable, CmpOp, InvalidArgumentException, PHP_EOL, PhpMixed, RuntimeException, array_map, clearstatcache, explode, implode, in_array_loose, in_array_strict, is_dir, php_regex, @@ -226,7 +226,7 @@ impl Git { &mut output, cwd, )?; - let mut m: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut m = PregMatchedGroups::new(); if Preg::is_match3( php_regex!(r"{^(?:composer|origin)\s+https?://(.+):(.+)@([^/]+)}im"), &output, @@ -248,7 +248,7 @@ impl Git { let protocols = self.config.borrow_mut().get("github-protocols"); // public github, autoswitch protocols // @phpstan-ignore composerPcre.maybeUnsafeStrictGroups - let mut m: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut m = PregMatchedGroups::new(); if Preg::is_match3( format!( "{{^(?:https?|git)://{}/(.*)}}", @@ -344,7 +344,7 @@ impl Git { let mut error_msg = self.process.borrow().get_error_output().to_string(); // private github repository without ssh key access, try https with auth // @phpstan-ignore composerPcre.maybeUnsafeStrictGroups - let mut m: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut m = PregMatchedGroups::new(); let github_matched = Preg::is_match3( format!( "{{^git@{}:(.+?)\\.git$}}i", @@ -1089,8 +1089,8 @@ impl Git { Ok(false) } - fn get_authentication_failure(&self, url: &str) -> Option<IndexMap<CaptureKey, String>> { - let mut m: IndexMap<CaptureKey, String> = IndexMap::new(); + fn get_authentication_failure(&self, url: &str) -> Option<PregMatchedGroups> { + let mut m = PregMatchedGroups::new(); if !Preg::is_match3( php_regex!(r"{^(https?://)([^/]+)(.*)$}i"), url, @@ -1179,7 +1179,7 @@ impl Git { .borrow() .split_lines(output_mixed.as_string().unwrap_or("")); for line in lines { - let mut matches: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut matches = PregMatchedGroups::new(); if Preg::is_match3( php_regex!(r"{^\s*HEAD branch:\s(.+)\s*$}m"), &line, @@ -1308,7 +1308,7 @@ impl Git { Option::<&str>::None, ); if exit_code == 0 { - let mut matches: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut matches = PregMatchedGroups::new(); if Preg::is_match3( php_regex!(r"/^git version (\d+(?:\.\d+)+)/m"), &output, diff --git a/crates/shirabe/src/util/github.rs b/crates/shirabe/src/util/github.rs index 25a95e57..b7659572 100644 --- a/crates/shirabe/src/util/github.rs +++ b/crates/shirabe/src/util/github.rs @@ -8,7 +8,7 @@ use crate::io::io_interface; use crate::util::HttpDownloader; use crate::util::ProcessExecutor; use indexmap::IndexMap; -use shirabe_pcre::{CaptureKey, Preg}; +use shirabe_pcre::{CaptureKey, Preg, PregMatchedGroups}; use shirabe_php_shim::Catch as _; use shirabe_php_shim::{PhpMixed, date_local, in_array_loose, php_regex, stripos, strtolower}; @@ -325,7 +325,7 @@ impl GitHub { if stripos(header, "x-github-sso: required").is_none() { continue; } - let mut caps: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut caps = PregMatchedGroups::new(); if Preg::match3( php_regex!(r"{\burl=(?P<url>[^\s;]+)}"), header, diff --git a/crates/shirabe/src/util/hg.rs b/crates/shirabe/src/util/hg.rs index f0cc56cc..8570af6d 100644 --- a/crates/shirabe/src/util/hg.rs +++ b/crates/shirabe/src/util/hg.rs @@ -5,7 +5,7 @@ use crate::io::IOInterface; use crate::io::IOInterfaceImmutable; use crate::util::ProcessExecutor; use crate::util::Url; -use shirabe_pcre::Preg; +use shirabe_pcre::{Preg, PregNamedGroups}; use shirabe_php_shim::{php_regex, rawurlencode}; use std::sync::OnceLock; @@ -56,7 +56,7 @@ impl Hg { } // Try with the authentication information available - let mut matches: indexmap::IndexMap<String, String> = indexmap::IndexMap::new(); + let mut matches = PregNamedGroups::new(); let matched = Preg::is_match_named( php_regex!( r"{^(?P<proto>ssh|https?)://(?:(?P<user>[^:@]+)(?::(?P<pass>[^:@]+))?@)?(?P<host>[^/]+)(?P<path>/.*)?}mi" diff --git a/crates/shirabe/src/util/http/response.rs b/crates/shirabe/src/util/http/response.rs index 47a1593f..6ce52643 100644 --- a/crates/shirabe/src/util/http/response.rs +++ b/crates/shirabe/src/util/http/response.rs @@ -65,8 +65,7 @@ impl Response { let mut value = None; let pattern = format!("{{^{}:\\s*(.+?)\\s*$}}i", preg_quote(name, None)); for header in headers { - let mut matches: indexmap::IndexMap<shirabe_pcre::CaptureKey, String> = - indexmap::IndexMap::new(); + let mut matches = shirabe_pcre::PregMatchedGroups::new(); if Preg::match3(&pattern, header, Some(&mut matches)) && let Some(s) = matches.get(&shirabe_pcre::CaptureKey::ByIndex(1)) { diff --git a/crates/shirabe/src/util/http_downloader.rs b/crates/shirabe/src/util/http_downloader.rs index c8fb943b..c478d445 100644 --- a/crates/shirabe/src/util/http_downloader.rs +++ b/crates/shirabe/src/util/http_downloader.rs @@ -16,7 +16,7 @@ use crate::util::http::CurlDownloader; use crate::util::http::Response; use crate::util::sync_executor; use indexmap::IndexMap; -use shirabe_pcre::{CaptureKey, Preg}; +use shirabe_pcre::{CaptureKey, Preg, PregMatchedGroups}; use shirabe_php_shim::Catch as _; use shirabe_php_shim::{ InvalidArgumentException, LogicException, PhpMixed, array_replace_recursive, extension_loaded, @@ -240,7 +240,7 @@ impl HttpDownloader { let origin = Url::get_origin(&self.config.borrow(), url); // capture username/password from URL if there is one - let mut m: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut m = PregMatchedGroups::new(); if Preg::is_match3( php_regex!(r"{^https?://([^:/]+):([^@/]+)@([^/]+)}i"), url, diff --git a/crates/shirabe/src/util/platform.rs b/crates/shirabe/src/util/platform.rs index 4336de53..21ad869c 100644 --- a/crates/shirabe/src/util/platform.rs +++ b/crates/shirabe/src/util/platform.rs @@ -2,7 +2,7 @@ use crate::util::ProcessExecutor; use crate::util::Silencer; -use shirabe_pcre::Preg; +use shirabe_pcre::{Preg, PregMatchedGroups}; use shirabe_php_shim::{ PHP_ENV, PHP_SERVER, PhpMixed, PhpResource, RuntimeException, defined, file_exists, file_get_contents, fstat, function_exists, getcwd, getenv, ini_get, is_readable, mb_strlen, @@ -99,7 +99,7 @@ impl Platform { // not participate is reported as an empty string, which `\w+` can never capture. Preg::replace_callback( php_regex!(r"#^(?:\$(?P<dvar>\w+)|%(?P<pvar>\w+)%)(?P<path>.*)#"), - |matches: &indexmap::IndexMap<CaptureKey, String>| -> String { + |matches: &PregMatchedGroups| -> String { let var = matches .get(&CaptureKey::ByName("dvar".to_string())) .filter(|dvar| !dvar.is_empty()) diff --git a/crates/shirabe/src/util/process_executor.rs b/crates/shirabe/src/util/process_executor.rs index fc67604e..d87e2ff4 100644 --- a/crates/shirabe/src/util/process_executor.rs +++ b/crates/shirabe/src/util/process_executor.rs @@ -7,7 +7,7 @@ use crate::signal::SignalSubscription; use crate::util::GitHub; use crate::util::Platform; use indexmap::IndexMap; -use shirabe_pcre::{CaptureKey, Preg}; +use shirabe_pcre::{CaptureKey, Preg, PregMatchedGroups}; use shirabe_php_shim::Catch as _; use shirabe_php_shim::{ LogicException, PHP_EOL, PhpMixed, RuntimeException, array_intersect, array_map, @@ -217,7 +217,7 @@ impl ProcessExecutor { if is_string(&command) { let mut command_str = command.as_string().unwrap_or("").to_string(); if Platform::is_windows() { - let mut m: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut m = PregMatchedGroups::new(); if Preg::is_match3(php_regex!(r"{^([^:/\\]++) }"), &command_str, Some(&mut m)) { let m1 = m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default(); command_str = substr_replace( @@ -832,7 +832,7 @@ impl ProcessExecutor { }; let safe_command = Preg::replace_callback( php_regex!(r"{://(?P<user>[^:/\s]+):(?P<password>[^@\s/]+)@}i"), - |m: &IndexMap<CaptureKey, String>| -> String { + |m: &PregMatchedGroups| -> String { let user_key = CaptureKey::ByName("user".to_string()); // if the username looks like a long (12char+) hex string, or a modern github token (e.g. ghp_xxx, github_pat_xxx) we obfuscate that if Preg::is_match( diff --git a/crates/shirabe/src/util/remote_filesystem.rs b/crates/shirabe/src/util/remote_filesystem.rs index 4a8ca267..40a69f28 100644 --- a/crates/shirabe/src/util/remote_filesystem.rs +++ b/crates/shirabe/src/util/remote_filesystem.rs @@ -13,7 +13,7 @@ use crate::util::Url; use crate::util::http::ProxyManager; use crate::util::http::Response; use indexmap::IndexMap; -use shirabe_pcre::{CaptureKey, Preg}; +use shirabe_pcre::{CaptureKey, Preg, PregMatchedGroups}; use shirabe_php_shim::Catch as _; use shirabe_php_shim::{ PhpMixed, RuntimeException, STREAM_NOTIFY_FAILURE, STREAM_NOTIFY_FILE_SIZE_IS, @@ -148,7 +148,7 @@ impl RemoteFilesystem { pub fn find_status_code(headers: &[String]) -> Option<i64> { let mut value: Option<i64> = None; for header in headers { - let mut m: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut m = PregMatchedGroups::new(); if Preg::is_match3(php_regex!("{^HTTP/\\S+ (\\d+)}i"), header, Some(&mut m)) { value = m .get(&CaptureKey::ByIndex(1)) diff --git a/crates/shirabe/src/util/svn.rs b/crates/shirabe/src/util/svn.rs index 9662c24d..d07b3ffe 100644 --- a/crates/shirabe/src/util/svn.rs +++ b/crates/shirabe/src/util/svn.rs @@ -6,8 +6,7 @@ use crate::io::IOInterfaceImmutable; use crate::io::io_interface; use crate::util::Platform; use crate::util::ProcessExecutor; -use indexmap::IndexMap; -use shirabe_pcre::{CaptureKey, Preg}; +use shirabe_pcre::{CaptureKey, Preg, PregMatchedGroups}; use shirabe_php_shim::{ LogicException, PhpMixed, RuntimeException, implode, parse_url, php_regex, stripos, strpos, trim, @@ -407,7 +406,7 @@ impl Svn { &mut output, None, ) { - let mut matches: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut matches = PregMatchedGroups::new(); if Preg::is_match3( php_regex!(r"{(\d+(?:\.\d+)+)}"), &output, diff --git a/crates/shirabe/src/util/url.rs b/crates/shirabe/src/util/url.rs index ea9e4401..3afcd962 100644 --- a/crates/shirabe/src/util/url.rs +++ b/crates/shirabe/src/util/url.rs @@ -2,8 +2,7 @@ use crate::config::Config; use crate::util::GitHub; -use indexmap::IndexMap; -use shirabe_pcre::{CaptureKey, Preg}; +use shirabe_pcre::{CaptureKey, Preg, PregMatchedGroups}; use shirabe_php_shim::{PhpMixed, in_array_strict, parse_url, php_regex}; pub struct Url; @@ -15,7 +14,7 @@ impl Url { .unwrap_or_default(); if host == "api.github.com" || host == "github.com" || host == "www.github.com" { - let mut m: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut m = PregMatchedGroups::new(); if Preg::match3( php_regex!( r"{^https?://(?:www\.)?github\.com/([^/]+)/([^/]+)/(zip|tar)ball/(.+)$}i" @@ -60,7 +59,7 @@ impl Url { ); } } else if host == "bitbucket.org" || host == "www.bitbucket.org" { - let mut m: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut m = PregMatchedGroups::new(); if Preg::match3( php_regex!( r"{^https?://(?:www\.)?bitbucket\.org/([^/]+)/([^/]+)/get/(.+)\.(zip|tar\.gz|tar\.bz2)$}i" @@ -77,7 +76,7 @@ impl Url { ); } } else if host == "gitlab.com" || host == "www.gitlab.com" { - let mut m: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut m = PregMatchedGroups::new(); if Preg::match3( php_regex!( r"{^https?://(?:www\.)?gitlab\.com/api/v[34]/projects/([^/]+)/repository/archive\.(zip|tar\.gz|tar\.bz2|tar)\?sha=.+$}i" diff --git a/crates/shirabe/tests/all_functional_test.rs b/crates/shirabe/tests/all_functional_test.rs index 7d71c649..500f822e 100644 --- a/crates/shirabe/tests/all_functional_test.rs +++ b/crates/shirabe/tests/all_functional_test.rs @@ -8,7 +8,7 @@ use indexmap::IndexMap; use serial_test::serial; use shirabe::util::filesystem::Filesystem; -use shirabe_pcre::preg::Preg; +use shirabe_pcre::preg::{Preg, PregMatchedGroups}; use shirabe_php_shim::{CaptureKey, PhpMixed, intval, php_regex, preg_split_delim_capture}; use std::path::{Path, PathBuf}; @@ -141,14 +141,14 @@ fn expect_matches(expected: &str, output: &str) { line += 1; } if eb[i] == b'%' { - let mut m: IndexMap<CaptureKey, String> = IndexMap::new(); + let mut m = PregMatchedGroups::new(); if !Preg::is_match3(php_regex!("{%(.+?)%}"), &expected[i..], Some(&mut m)) { panic!("Failed to match %...% in {}", &expected[i..]); } let regex = m.get(&CaptureKey::ByIndex(1)).cloned().unwrap(); let pattern = format!("{{{}}}", regex); - let mut m = IndexMap::new(); + let mut m = PregMatchedGroups::new(); if Preg::is_match3(&pattern, &output[j..], Some(&mut m)) { let full = m.get(&CaptureKey::ByIndex(0)).cloned().unwrap(); i += regex.len() + 2; |
