From 52a0665acbbe5bf5b8c6875118fb9cdf7952453b Mon Sep 17 00:00:00 2001 From: nsfisis Date: Mon, 17 Aug 2026 06:43:52 +0900 Subject: refactor(preg): wrap the preg_* $matches maps in newtypes The five IndexMap shapes that the preg_* functions and Preg fill in are now distinct types generated by preg_match_map!, so a matches map no longer interchanges with any other map of the same key and value type. Index is kept alongside Index<&Q> because call sites such as config_command and event_dispatcher reach for a group by its position in the map rather than by its capture key. --- crates/shirabe/src/command/config_command.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'crates/shirabe/src/command/config_command.rs') 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 = 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 = 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 = 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 = 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 = 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 = 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 = 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 = 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 = 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 = IndexMap::new(); + let mut matches = PregMatchedGroups::new(); if Preg::is_match3( php_regex!("/^scripts\\.(.+)/"), &setting_key, -- cgit v1.3.1-4-g156e