diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-08-18 01:57:02 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-08-18 01:57:02 +0900 |
| commit | 0caac63bacefb9a1f62848636d47fca07f592bba (patch) | |
| tree | 8d2ef66e597a8d8c228d3ba2490a59f48b26db4d /crates/shirabe/src/util | |
| parent | 34c74255d781ad0a0bf7cc5ad4ec1761bef61e04 (diff) | |
| download | php-shirabe-0caac63bacefb9a1f62848636d47fca07f592bba.tar.gz php-shirabe-0caac63bacefb9a1f62848636d47fca07f592bba.tar.zst php-shirabe-0caac63bacefb9a1f62848636d47fca07f592bba.zip | |
refactor(preg): split PregMatches reads into get() and name()
PregMatches keyed both forms of a capture group through CaptureKey, so
every read built one: a usize wrapped in an enum, or worse, a String
allocated to name a group that regex::Captures can look up from a &str.
It now mirrors regex::Captures instead -- get() takes the group number,
name() the group name -- and the enum drops out of the type entirely.
That is 285 call sites across 59 files, and the named ones carry most of
the win: `matches.get(&CaptureKey::ByName("host".to_string()))` reads as
`matches.name("host")`. ProcessExecutor loses a `user_key` binding that
existed only to build the key once.
CaptureKey stays as the key type of PregMatchesAll and
PregMatchesAllWithOffsets, where numbered and named entries share one
IndexMap and a key type is the point. Five files still name it.
Also retargets the two preg_match_all comments that described the
occurrence count through `matches[&CaptureKey::ByIndex(0)].len()`, an
Index impl these types no longer carry.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/util')
| -rw-r--r-- | crates/shirabe/src/util/composer_mirror.rs | 10 | ||||
| -rw-r--r-- | crates/shirabe/src/util/filesystem.rs | 10 | ||||
| -rw-r--r-- | crates/shirabe/src/util/forgejo_url.rs | 9 | ||||
| -rw-r--r-- | crates/shirabe/src/util/git.rs | 87 | ||||
| -rw-r--r-- | crates/shirabe/src/util/github.rs | 6 | ||||
| -rw-r--r-- | crates/shirabe/src/util/hg.rs | 50 | ||||
| -rw-r--r-- | crates/shirabe/src/util/http/response.rs | 2 | ||||
| -rw-r--r-- | crates/shirabe/src/util/http_downloader.rs | 14 | ||||
| -rw-r--r-- | crates/shirabe/src/util/platform.rs | 9 | ||||
| -rw-r--r-- | crates/shirabe/src/util/process_executor.rs | 14 | ||||
| -rw-r--r-- | crates/shirabe/src/util/remote_filesystem.rs | 7 | ||||
| -rw-r--r-- | crates/shirabe/src/util/svn.rs | 9 | ||||
| -rw-r--r-- | crates/shirabe/src/util/url.rs | 40 |
13 files changed, 79 insertions, 188 deletions
diff --git a/crates/shirabe/src/util/composer_mirror.rs b/crates/shirabe/src/util/composer_mirror.rs index 5d9e8c31..f7bc179f 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::Preg; use shirabe_php_shim::{hash, php_regex}; pub struct ComposerMirror; @@ -61,8 +61,8 @@ impl ComposerMirror { ) { format!( "gh-{}/{}", - gh_matches.get(&CaptureKey::ByIndex(1)).unwrap_or_default(), - gh_matches.get(&CaptureKey::ByIndex(2)).unwrap_or_default(), + gh_matches.get(1).unwrap_or_default(), + gh_matches.get(2).unwrap_or_default(), ) } else if let Some(bb_matches) = Preg::match3( php_regex!(r"#^https://bitbucket\.org/([^/]+)/(.+?)(?:\.git)?/?$#"), @@ -70,8 +70,8 @@ impl ComposerMirror { ) { format!( "bb-{}/{}", - bb_matches.get(&CaptureKey::ByIndex(1)).unwrap_or_default(), - bb_matches.get(&CaptureKey::ByIndex(2)).unwrap_or_default(), + bb_matches.get(1).unwrap_or_default(), + bb_matches.get(2).unwrap_or_default(), ) } else { Preg::replace(php_regex!(r"{[^a-z0-9_.-]}i"), "-", url.trim_matches('/')) diff --git a/crates/shirabe/src/util/filesystem.rs b/crates/shirabe/src/util/filesystem.rs index 6302a6d2..2ef51ba1 100644 --- a/crates/shirabe/src/util/filesystem.rs +++ b/crates/shirabe/src/util/filesystem.rs @@ -739,10 +739,7 @@ impl Filesystem { php_regex!("{^( [0-9a-z]{2,}+: (?: // (?: [a-z]: )? )? | [a-z]: )}ix"), &path, ) { - prefix = prefix_match - .get(&shirabe_pcre::CaptureKey::ByIndex(1)) - .unwrap_or_default() - .to_string(); + prefix = prefix_match.get(1).unwrap_or_default().to_string(); path = substr(&path, strlen(&prefix), None); } @@ -766,10 +763,7 @@ impl Filesystem { prefix = Preg::replace_callback( php_regex!("{(^|://)[a-z]:$}i"), |m: &shirabe_pcre::PregMatches| -> String { - let s = m - .get(&shirabe_pcre::CaptureKey::ByIndex(0)) - .unwrap_or_default() - .to_string(); + let s = m.get(0).unwrap_or_default().to_string(); strtoupper(&s) }, &prefix, diff --git a/crates/shirabe/src/util/forgejo_url.rs b/crates/shirabe/src/util/forgejo_url.rs index 7f9333e0..9ae1cbee 100644 --- a/crates/shirabe/src/util/forgejo_url.rs +++ b/crates/shirabe/src/util/forgejo_url.rs @@ -38,14 +38,9 @@ impl ForgejoUrl { pub fn try_from(repo_url: Option<&str>) -> Option<Self> { let repo_url = repo_url?; let matches = Preg::match3(Self::URL_REGEX, repo_url)?; - use shirabe_pcre::CaptureKey; + let m: Vec<String> = (0..5) - .map(|i| { - matches - .get(&CaptureKey::ByIndex(i)) - .unwrap_or_default() - .to_string() - }) + .map(|i| matches.get(i).unwrap_or_default().to_string()) .collect(); let origin_url = if !m[1].is_empty() { diff --git a/crates/shirabe/src/util/git.rs b/crates/shirabe/src/util/git.rs index e7239987..e14ff05f 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, PregMatches}; +use shirabe_pcre::{Preg, PregMatches}; 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, @@ -230,17 +230,12 @@ impl Git { php_regex!(r"{^(?:composer|origin)\s+https?://(.+):(.+)@([^/]+)}im"), &output, ) { - let m3 = m - .get(&CaptureKey::ByIndex(3)) - .unwrap_or_default() - .to_string(); + let m3 = m.get(3).unwrap_or_default().to_string(); if !self.io.has_authentication(&m3) { self.io.borrow_mut().set_authentication( m3, - rawurldecode(m.get(&CaptureKey::ByIndex(1)).unwrap_or_default()), - Some(rawurldecode( - m.get(&CaptureKey::ByIndex(2)).unwrap_or_default(), - )), + rawurldecode(m.get(1).unwrap_or_default()), + Some(rawurldecode(m.get(2).unwrap_or_default())), ); } } @@ -265,14 +260,8 @@ impl Git { _ => vec![], }; for protocol in &protocols_list { - let m1 = m - .get(&CaptureKey::ByIndex(1)) - .unwrap_or_default() - .to_string(); - let m2 = m - .get(&CaptureKey::ByIndex(2)) - .unwrap_or_default() - .to_string(); + let m1 = m.get(1).unwrap_or_default().to_string(); + let m2 = m.get(2).unwrap_or_default().to_string(); let proto_url = if protocol == "ssh" { format!("git@{}:{}", m1, m2) } else { @@ -300,10 +289,7 @@ impl Git { } // failed to checkout, first check git accessibility - let m1 = m - .get(&CaptureKey::ByIndex(1)) - .unwrap_or_default() - .to_string(); + let m1 = m.get(1).unwrap_or_default().to_string(); if !self.io.has_authentication(&m1) && !self.io.is_interactive() { self.throw_exception( &format!( @@ -369,14 +355,8 @@ impl Git { ) }); if let Some(m) = github_matched { - let m1 = m - .get(&CaptureKey::ByIndex(1)) - .unwrap_or_default() - .to_string(); - let m2 = m - .get(&CaptureKey::ByIndex(2)) - .unwrap_or_default() - .to_string(); + let m1 = m.get(1).unwrap_or_default().to_string(); + let m2 = m.get(2).unwrap_or_default().to_string(); if !self.io.has_authentication(&m1) { let mut git_hub_util = GitHub::new( self.io.clone(), @@ -439,14 +419,8 @@ impl Git { None, )?; - let domain = m - .get(&CaptureKey::ByIndex(2)) - .unwrap_or_default() - .to_string(); - let mut repo_with_git_part = m - .get(&CaptureKey::ByIndex(3)) - .unwrap_or_default() - .to_string(); + let domain = m.get(2).unwrap_or_default().to_string(); + let mut repo_with_git_part = m.get(3).unwrap_or_default().to_string(); if !repo_with_git_part.ends_with(".git") { repo_with_git_part.push_str(".git"); } @@ -588,18 +562,9 @@ impl Git { url, ) }) { - let mut m1 = m - .get(&CaptureKey::ByIndex(1)) - .unwrap_or_default() - .to_string(); - let m2 = m - .get(&CaptureKey::ByIndex(2)) - .unwrap_or_default() - .to_string(); - let m3 = m - .get(&CaptureKey::ByIndex(3)) - .unwrap_or_default() - .to_string(); + let mut m1 = m.get(1).unwrap_or_default().to_string(); + let m2 = m.get(2).unwrap_or_default().to_string(); + let m3 = m.get(3).unwrap_or_default().to_string(); if m1 == "git" { m1 = "https".to_string(); } @@ -673,18 +638,9 @@ impl Git { } } else if let Some(m) = self.get_authentication_failure(url) { // private non-github/gitlab/bitbucket repo that failed to authenticate - let m1 = m - .get(&CaptureKey::ByIndex(1)) - .unwrap_or_default() - .to_string(); - let mut m2 = m - .get(&CaptureKey::ByIndex(2)) - .unwrap_or_default() - .to_string(); - let m3 = m - .get(&CaptureKey::ByIndex(3)) - .unwrap_or_default() - .to_string(); + let m1 = m.get(1).unwrap_or_default().to_string(); + let mut m2 = m.get(2).unwrap_or_default().to_string(); + let m3 = m.get(3).unwrap_or_default().to_string(); let mut auth_parts: Option<String> = None; if m2.contains("@") { let parts = explode("@", &m2); @@ -1210,12 +1166,7 @@ impl Git { if let Some(matches) = Preg::is_match3(php_regex!(r"{^\s*HEAD branch:\s(.+)\s*$}m"), &line) { - return Ok(Some( - matches - .get(&CaptureKey::ByIndex(1)) - .unwrap_or_default() - .to_string(), - )); + return Ok(Some(matches.get(1).unwrap_or_default().to_string())); } } @@ -1336,7 +1287,7 @@ impl Git { && let Some(matches) = Preg::is_match3(php_regex!(r"/^git version (\d+(?:\.\d+)+)/m"), &output) { - *version = Some(matches.get(&CaptureKey::ByIndex(1)).map(str::to_string)); + *version = Some(matches.get(1).map(str::to_string)); } } version.clone().unwrap_or(None) diff --git a/crates/shirabe/src/util/github.rs b/crates/shirabe/src/util/github.rs index 28a13738..570a33bb 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::Preg; use shirabe_php_shim::Catch as _; use shirabe_php_shim::{PhpMixed, date_local, in_array_loose, php_regex, stripos, strtolower}; @@ -326,9 +326,7 @@ impl GitHub { continue; } if let Some(caps) = Preg::match3(php_regex!(r"{\burl=(?P<url>[^\s;]+)}"), header) { - return caps - .get(&CaptureKey::ByName("url".to_string())) - .map(str::to_string); + return caps.name("url").map(str::to_string); } } diff --git a/crates/shirabe/src/util/hg.rs b/crates/shirabe/src/util/hg.rs index 395ea6d5..f95f15d5 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::{CaptureKey, Preg}; +use shirabe_pcre::Preg; use shirabe_php_shim::{php_regex, rawurlencode}; use std::sync::OnceLock; @@ -64,44 +64,30 @@ impl Hg { ); if let Some(matches) = matched - && self.io.has_authentication( - matches - .get(&CaptureKey::ByName("host".to_string())) - .unwrap_or(""), - ) + && self + .io + .has_authentication(matches.name("host").unwrap_or("")) { - let authenticated_url = if matches.get(&CaptureKey::ByName("proto".to_string())) - == Some("ssh") - { - let user = if let Some(u) = matches.get(&CaptureKey::ByName("user".to_string())) { + let authenticated_url = if matches.name("proto") == Some("ssh") { + let user = if let Some(u) = matches.name("user") { format!("{}@", rawurlencode(u)) } else { String::new() }; format!( "{}://{}{}{}", - matches - .get(&CaptureKey::ByName("proto".to_string())) - .unwrap_or(""), + matches.name("proto").unwrap_or(""), user, - matches - .get(&CaptureKey::ByName("host".to_string())) - .unwrap_or(""), - matches - .get(&CaptureKey::ByName("path".to_string())) - .unwrap_or(""), + matches.name("host").unwrap_or(""), + matches.name("path").unwrap_or(""), ) } else { - let auth = self.io.get_authentication( - matches - .get(&CaptureKey::ByName("host".to_string())) - .unwrap_or(""), - ); + let auth = self + .io + .get_authentication(matches.name("host").unwrap_or("")); format!( "{}://{}:{}@{}{}", - matches - .get(&CaptureKey::ByName("proto".to_string())) - .unwrap_or(""), + matches.name("proto").unwrap_or(""), rawurlencode( auth.get("username") .and_then(|s| s.as_deref()) @@ -112,12 +98,8 @@ impl Hg { .and_then(|s| s.as_deref()) .unwrap_or("") ), - matches - .get(&CaptureKey::ByName("host".to_string())) - .unwrap_or(""), - matches - .get(&CaptureKey::ByName("path".to_string())) - .unwrap_or(""), + matches.name("host").unwrap_or(""), + matches.name("path").unwrap_or(""), ) }; @@ -174,7 +156,7 @@ impl Hg { &output, ) { - return matches.get(&CaptureKey::ByIndex(1)).map(str::to_string); + return matches.get(1).map(str::to_string); } None }) diff --git a/crates/shirabe/src/util/http/response.rs b/crates/shirabe/src/util/http/response.rs index 7c5f5248..bd117a24 100644 --- a/crates/shirabe/src/util/http/response.rs +++ b/crates/shirabe/src/util/http/response.rs @@ -66,7 +66,7 @@ impl Response { let pattern = format!("{{^{}:\\s*(.+?)\\s*$}}i", preg_quote(name, None)); for header in headers { if let Some(matches) = Preg::match3(&pattern, header) - && let Some(s) = matches.get(&shirabe_pcre::CaptureKey::ByIndex(1)) + && let Some(s) = matches.get(1) { value = Some(s.to_string()); } diff --git a/crates/shirabe/src/util/http_downloader.rs b/crates/shirabe/src/util/http_downloader.rs index c6e70117..151b2646 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::Preg; use shirabe_php_shim::Catch as _; use shirabe_php_shim::{ InvalidArgumentException, LogicException, PhpMixed, array_replace_recursive, extension_loaded, @@ -244,17 +244,9 @@ impl HttpDownloader { { self.io.borrow_mut().set_authentication( origin.clone(), - rawurldecode( - m.get(&CaptureKey::ByIndex(1)) - .unwrap_or_default() - .to_string() - .as_str(), - ), + rawurldecode(m.get(1).unwrap_or_default().to_string().as_str()), Some(rawurldecode( - m.get(&CaptureKey::ByIndex(2)) - .unwrap_or_default() - .to_string() - .as_str(), + m.get(2).unwrap_or_default().to_string().as_str(), )), ); } diff --git a/crates/shirabe/src/util/platform.rs b/crates/shirabe/src/util/platform.rs index f2b8aea3..606ff43d 100644 --- a/crates/shirabe/src/util/platform.rs +++ b/crates/shirabe/src/util/platform.rs @@ -83,7 +83,6 @@ impl Platform { /// Parses tildes and environment variables in paths. pub fn expand_path(path: &str) -> String { - use shirabe_pcre::CaptureKey; if Preg::is_match(php_regex!(r"#^~[\\/]#"), path) { return format!( "{}{}", @@ -100,12 +99,10 @@ impl Platform { php_regex!(r"#^(?:\$(?P<dvar>\w+)|%(?P<pvar>\w+)%)(?P<path>.*)#"), |matches: &PregMatches| -> String { let var = matches - .get(&CaptureKey::ByName("dvar".to_string())) - .or_else(|| matches.get(&CaptureKey::ByName("pvar".to_string()))) - .unwrap_or(""); - let path_part = matches - .get(&CaptureKey::ByName("path".to_string())) + .name("dvar") + .or_else(|| matches.name("pvar")) .unwrap_or(""); + let path_part = matches.name("path").unwrap_or(""); // Treat HOME as an alias for USERPROFILE on Windows for legacy reasons if Platform::is_windows() && var == "HOME" { let home = diff --git a/crates/shirabe/src/util/process_executor.rs b/crates/shirabe/src/util/process_executor.rs index 2954ed7a..2bfaeb94 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, PregMatches}; +use shirabe_pcre::{Preg, PregMatches}; use shirabe_php_shim::Catch as _; use shirabe_php_shim::{ LogicException, PHP_EOL, PhpMixed, RuntimeException, array_intersect, array_map, @@ -219,10 +219,7 @@ impl ProcessExecutor { if Platform::is_windows() && let Some(m) = Preg::is_match3(php_regex!(r"{^([^:/\\]++) }"), &command_str) { - let m1 = m - .get(&CaptureKey::ByIndex(1)) - .unwrap_or_default() - .to_string(); + let m1 = m.get(1).unwrap_or_default().to_string(); command_str = substr_replace( &command_str, &Self::escape(&Self::get_executable(&m1)), @@ -835,19 +832,18 @@ impl ProcessExecutor { let safe_command = Preg::replace_callback( php_regex!(r"{://(?P<user>[^:/\s]+):(?P<password>[^@\s/]+)@}i"), |m: &PregMatches| -> 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( GitHub::GITHUB_TOKEN_REGEX, - m.get(&user_key).unwrap_or_default(), + m.name("user").unwrap_or_default(), ) { return "://***:***@".to_string(); } - if Preg::is_match(r"{^[a-f0-9]{12,}$}", m.get(&user_key).unwrap_or_default()) { + if Preg::is_match(r"{^[a-f0-9]{12,}$}", m.name("user").unwrap_or_default()) { return "://***:***@".to_string(); } - format!("://{}:***@", m.get(&user_key).unwrap_or_default()) + format!("://{}:***@", m.name("user").unwrap_or_default()) }, &command_string, ); diff --git a/crates/shirabe/src/util/remote_filesystem.rs b/crates/shirabe/src/util/remote_filesystem.rs index 0bc004ce..e55e5200 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::Preg; use shirabe_php_shim::Catch as _; use shirabe_php_shim::{ PhpMixed, RuntimeException, STREAM_NOTIFY_FAILURE, STREAM_NOTIFY_FILE_SIZE_IS, @@ -149,10 +149,7 @@ impl RemoteFilesystem { let mut value: Option<i64> = None; for header in headers { if let Some(m) = Preg::is_match3(php_regex!("{^HTTP/\\S+ (\\d+)}i"), header) { - value = m - .get(&CaptureKey::ByIndex(1)) - .and_then(|s| s.parse().ok()) - .or(Some(0)); + value = m.get(1).and_then(|s| s.parse().ok()).or(Some(0)); } } diff --git a/crates/shirabe/src/util/svn.rs b/crates/shirabe/src/util/svn.rs index 72ca2321..5ff6a025 100644 --- a/crates/shirabe/src/util/svn.rs +++ b/crates/shirabe/src/util/svn.rs @@ -6,7 +6,7 @@ use crate::io::IOInterfaceImmutable; use crate::io::io_interface; use crate::util::Platform; use crate::util::ProcessExecutor; -use shirabe_pcre::{CaptureKey, Preg}; +use shirabe_pcre::Preg; use shirabe_php_shim::{ LogicException, PhpMixed, RuntimeException, implode, parse_url, php_regex, stripos, strpos, trim, @@ -407,12 +407,7 @@ impl Svn { None, ) && let Some(matches) = Preg::is_match3(php_regex!(r"{(\d+(?:\.\d+)+)}"), &output) { - *cached = Some( - matches - .get(&CaptureKey::ByIndex(1)) - .unwrap_or_default() - .to_string(), - ); + *cached = Some(matches.get(1).unwrap_or_default().to_string()); } } diff --git a/crates/shirabe/src/util/url.rs b/crates/shirabe/src/util/url.rs index 8b751b2a..eb533a06 100644 --- a/crates/shirabe/src/util/url.rs +++ b/crates/shirabe/src/util/url.rs @@ -2,7 +2,7 @@ use crate::config::Config; use crate::util::GitHub; -use shirabe_pcre::{CaptureKey, Preg}; +use shirabe_pcre::Preg; use shirabe_php_shim::{PhpMixed, in_array_strict, parse_url, php_regex}; pub struct Url; @@ -22,9 +22,9 @@ impl Url { ) { url = format!( "https://api.github.com/repos/{}/{}/{}ball/{}", - m.get(&CaptureKey::ByIndex(1)).unwrap_or_default(), - m.get(&CaptureKey::ByIndex(2)).unwrap_or_default(), - m.get(&CaptureKey::ByIndex(3)).unwrap_or_default(), + m.get(1).unwrap_or_default(), + m.get(2).unwrap_or_default(), + m.get(3).unwrap_or_default(), r#ref ); } else if let Some(m) = Preg::match3( @@ -35,9 +35,9 @@ impl Url { ) { url = format!( "https://api.github.com/repos/{}/{}/{}ball/{}", - m.get(&CaptureKey::ByIndex(1)).unwrap_or_default(), - m.get(&CaptureKey::ByIndex(2)).unwrap_or_default(), - m.get(&CaptureKey::ByIndex(3)).unwrap_or_default(), + m.get(1).unwrap_or_default(), + m.get(2).unwrap_or_default(), + m.get(3).unwrap_or_default(), r#ref ); } else if let Some(m) = Preg::match3( @@ -48,9 +48,9 @@ impl Url { ) { url = format!( "https://api.github.com/repos/{}/{}/{}ball/{}", - m.get(&CaptureKey::ByIndex(1)).unwrap_or_default(), - m.get(&CaptureKey::ByIndex(2)).unwrap_or_default(), - m.get(&CaptureKey::ByIndex(3)).unwrap_or_default(), + m.get(1).unwrap_or_default(), + m.get(2).unwrap_or_default(), + m.get(3).unwrap_or_default(), r#ref ); } @@ -63,10 +63,10 @@ impl Url { ) { url = format!( "https://bitbucket.org/{}/{}/get/{}.{}", - m.get(&CaptureKey::ByIndex(1)).unwrap_or_default(), - m.get(&CaptureKey::ByIndex(2)).unwrap_or_default(), + m.get(1).unwrap_or_default(), + m.get(2).unwrap_or_default(), r#ref, - m.get(&CaptureKey::ByIndex(4)).unwrap_or_default() + m.get(4).unwrap_or_default() ); } } else if host == "gitlab.com" || host == "www.gitlab.com" { @@ -78,8 +78,8 @@ impl Url { ) { url = format!( "https://gitlab.com/api/v4/projects/{}/repository/archive.{}?sha={}", - m.get(&CaptureKey::ByIndex(1)).unwrap_or_default(), - m.get(&CaptureKey::ByIndex(2)).unwrap_or_default(), + m.get(1).unwrap_or_default(), + m.get(2).unwrap_or_default(), r#ref ); } @@ -163,14 +163,8 @@ impl Url { Preg::replace_callback( php_regex!(r"{^(?P<prefix>[a-z0-9]+://)?(?P<user>[^:/\s@]+):(?P<password>[^@\s/]+)@}i"), |m| { - let user = m - .get(&CaptureKey::ByName("user".to_string())) - .unwrap_or_default() - .to_string(); - let prefix = m - .get(&CaptureKey::ByName("prefix".to_string())) - .unwrap_or_default() - .to_string(); + let user = m.name("user").unwrap_or_default().to_string(); + let prefix = m.name("prefix").unwrap_or_default().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(GitHub::GITHUB_TOKEN_REGEX, &user) { format!("{}***:***@", prefix) |
