diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-08-17 06:43:52 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-08-17 06:43:52 +0900 |
| commit | 52a0665acbbe5bf5b8c6875118fb9cdf7952453b (patch) | |
| tree | 7302b0b87f7b0d406126da734ef82c80abf64204 /crates/shirabe/src/repository/vcs/github_driver.rs | |
| parent | c81e9f89d9e4388f36a4427bbaa95eced659d2ce (diff) | |
| download | php-shirabe-52a0665acbbe5bf5b8c6875118fb9cdf7952453b.tar.gz php-shirabe-52a0665acbbe5bf5b8c6875118fb9cdf7952453b.tar.zst php-shirabe-52a0665acbbe5bf5b8c6875118fb9cdf7952453b.zip | |
refactor(preg): wrap the preg_* $matches maps in newtypes
The five IndexMap shapes that the preg_* functions and Preg fill in are
now distinct types generated by preg_match_map!, so a matches map no
longer interchanges with any other map of the same key and value type.
Index<usize> is kept alongside Index<&Q> because call sites such as
config_command and event_dispatcher reach for a group by its position in
the map rather than by its capture key.
Diffstat (limited to 'crates/shirabe/src/repository/vcs/github_driver.rs')
| -rw-r--r-- | crates/shirabe/src/repository/vcs/github_driver.rs | 14 |
1 files changed, 7 insertions, 7 deletions
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()); } |
