diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-08-17 08:05:42 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-08-17 08:05:42 +0900 |
| commit | 79b504e55cd4c4d1da102c3a076dc2a2e1edcd65 (patch) | |
| tree | 2c12198742f289de49b9b77a2c2ad66ef417405c /crates/shirabe/src/util | |
| parent | 9fd6aecad27240ccedab4487f6c157914142ca47 (diff) | |
| download | php-shirabe-79b504e55cd4c4d1da102c3a076dc2a2e1edcd65.tar.gz php-shirabe-79b504e55cd4c4d1da102c3a076dc2a2e1edcd65.tar.zst php-shirabe-79b504e55cd4c4d1da102c3a076dc2a2e1edcd65.zip | |
refactor(pcre): return the Preg $matches instead of filling an out-param
`Composer\Pcre\Preg` fills `$matches` through a by-ref parameter, and the
port mirrored that with a `&mut` (or `Option<&mut>`) out-param plus a
bool or count return. Callers had to declare an empty map one line ahead
of the call, and the type never said the map is only meaningful when the
call matched. Return the matches instead:
- match3/match4/is_match3/is_match4 -> Option<PregMatchedGroups>
- is_match_named -> Option<PregNamedGroups>
- match_all2/is_match_all -> PregMatchesAll
- is_match_all_with_offsets3 -> PregMatchesAllWithOffsets
Nothing is lost: the bool is `Option::is_some()`, and the occurrence
count is the length of any one column of a PREG_PATTERN_ORDER map, now
spelled `PregMatchesAll::occurrence_count()`. is_match() still answers
the bool question directly for callers that want no groups.
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 | 18 | ||||
| -rw-r--r-- | crates/shirabe/src/util/forgejo_url.rs | 5 | ||||
| -rw-r--r-- | crates/shirabe/src/util/git.rs | 94 | ||||
| -rw-r--r-- | crates/shirabe/src/util/github.rs | 9 | ||||
| -rw-r--r-- | crates/shirabe/src/util/hg.rs | 6 | ||||
| -rw-r--r-- | crates/shirabe/src/util/http/response.rs | 3 | ||||
| -rw-r--r-- | crates/shirabe/src/util/http_downloader.rs | 10 | ||||
| -rw-r--r-- | crates/shirabe/src/util/process_executor.rs | 21 | ||||
| -rw-r--r-- | crates/shirabe/src/util/remote_filesystem.rs | 5 | ||||
| -rw-r--r-- | crates/shirabe/src/util/svn.rs | 24 | ||||
| -rw-r--r-- | crates/shirabe/src/util/url.rs | 20 |
12 files changed, 84 insertions, 141 deletions
diff --git a/crates/shirabe/src/util/composer_mirror.rs b/crates/shirabe/src/util/composer_mirror.rs index 1455613d..7344bfaf 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, PregMatchedGroups}; +use shirabe_pcre::{CaptureKey, Preg}; use shirabe_php_shim::{hash, php_regex}; pub struct ComposerMirror; @@ -53,14 +53,11 @@ impl ComposerMirror { url: &str, r#type: Option<&str>, ) -> String { - let mut gh_matches = PregMatchedGroups::new(); - let mut bb_matches = PregMatchedGroups::new(); - let normalized_url = if Preg::match3( + let normalized_url = if let Some(gh_matches) = Preg::match3( php_regex!( r"#^(?:(?:https?|git)://github\.com/|git@github\.com:)([^/]+)/(.+?)(?:\.git)?$#" ), url, - Some(&mut gh_matches), ) { format!( "gh-{}/{}", @@ -73,10 +70,9 @@ impl ComposerMirror { .cloned() .unwrap_or_default(), ) - } else if Preg::match3( + } else if let Some(bb_matches) = Preg::match3( php_regex!(r"#^https://bitbucket\.org/([^/]+)/(.+?)(?:\.git)?/?$#"), url, - Some(&mut bb_matches), ) { format!( "bb-{}/{}", diff --git a/crates/shirabe/src/util/filesystem.rs b/crates/shirabe/src/util/filesystem.rs index 21512a81..d59df55e 100644 --- a/crates/shirabe/src/util/filesystem.rs +++ b/crates/shirabe/src/util/filesystem.rs @@ -246,7 +246,7 @@ impl Filesystem { return Ok(Some(true)); } - if Preg::is_match3(php_regex!("{^(?:[a-z]:)?[/\\\\]+$}i"), directory, None) { + if Preg::is_match3(php_regex!("{^(?:[a-z]:)?[/\\\\]+$}i"), directory).is_some() { return Err(RuntimeException::new(format!("Aborting an attempted deletion of {}, this was probably not intended, if it is a real use case please report it.", directory)) .into()); } @@ -578,7 +578,7 @@ impl Filesystem { let mut common_path = to.clone(); while strpos(&format!("{}/", from), &format!("{}/", common_path)) != Some(0) && "/" != common_path - && !Preg::is_match3(php_regex!("{^[A-Z]:/?$}i"), &common_path, None) + && Preg::is_match3(php_regex!("{^[A-Z]:/?$}i"), &common_path).is_none() { common_path = strtr(&dirname(&common_path), "\\", "/"); } @@ -635,7 +635,7 @@ impl Filesystem { let mut common_path = to.clone(); while strpos(&format!("{}/", from), &format!("{}/", common_path)) != Some(0) && "/" != common_path - && !Preg::is_match3(php_regex!("{^[A-Z]:/?$}i"), &common_path, None) + && Preg::is_match3(php_regex!("{^[A-Z]:/?$}i"), &common_path).is_none() && "." != common_path { common_path = strtr(&dirname(&common_path), "\\", "/"); @@ -735,11 +735,9 @@ impl Filesystem { } // extract a prefix being a protocol://, protocol:, protocol://drive: or simply drive: - let mut prefix_match = shirabe_pcre::PregMatchedGroups::new(); - if Preg::is_match3( + if let Some(prefix_match) = Preg::is_match3( php_regex!("{^( [0-9a-z]{2,}+: (?: // (?: [a-z]: )? )? | [a-z]: )}ix"), &path, - Some(&mut prefix_match), ) { prefix = prefix_match .get(&shirabe_pcre::CaptureKey::ByIndex(1)) @@ -785,7 +783,7 @@ impl Filesystem { /// And other possible unforeseen disasters, see https://github.com/composer/composer/pull/9422 pub fn trim_trailing_slash(path: &str) -> String { let mut path = path.to_string(); - if !Preg::is_match3(php_regex!("{^[/\\\\]+$}"), &path, None) { + if Preg::is_match3(php_regex!("{^[/\\\\]+$}"), &path).is_none() { path = rtrim(&path, Some("/\\")); } @@ -802,15 +800,15 @@ impl Filesystem { "{^(file://(?!//)|/(?!/)|/?[a-z]:[\\\\/]|\\.\\.[\\\\/]|[a-z0-9_.-]+[\\\\/])}i" ), path, - None, - ); + ) + .is_some(); } Preg::is_match3( php_regex!("{^(file://|/|/?[a-z]:[\\\\/]|\\.\\.[\\\\/]|[a-z0-9_.-]+[\\\\/])}i"), path, - None, ) + .is_some() } pub fn get_platform_path(path: &str) -> String { diff --git a/crates/shirabe/src/util/forgejo_url.rs b/crates/shirabe/src/util/forgejo_url.rs index 7a5d2b10..e5304f5d 100644 --- a/crates/shirabe/src/util/forgejo_url.rs +++ b/crates/shirabe/src/util/forgejo_url.rs @@ -37,10 +37,7 @@ impl ForgejoUrl { pub fn try_from(repo_url: Option<&str>) -> Option<Self> { let repo_url = repo_url?; - let mut matches = shirabe_pcre::PregMatchedGroups::new(); - if !Preg::match3(Self::URL_REGEX, repo_url, Some(&mut matches)) { - return None; - } + let matches = Preg::match3(Self::URL_REGEX, repo_url)?; use shirabe_pcre::CaptureKey; let m: Vec<String> = (0..5) .map(|i| { diff --git a/crates/shirabe/src/util/git.rs b/crates/shirabe/src/util/git.rs index 0f463aea..2b012d4c 100644 --- a/crates/shirabe/src/util/git.rs +++ b/crates/shirabe/src/util/git.rs @@ -226,11 +226,9 @@ impl Git { &mut output, cwd, )?; - let mut m = PregMatchedGroups::new(); - if Preg::is_match3( + if let Some(m) = Preg::is_match3( php_regex!(r"{^(?:composer|origin)\s+https?://(.+):(.+)@([^/]+)}im"), &output, - Some(&mut m), ) { let m3 = m.get(&CaptureKey::ByIndex(3)).cloned().unwrap_or_default(); if !self.io.has_authentication(&m3) { @@ -248,14 +246,12 @@ impl Git { let protocols = self.config.borrow_mut().get("github-protocols"); // public github, autoswitch protocols // @phpstan-ignore composerPcre.maybeUnsafeStrictGroups - let mut m = PregMatchedGroups::new(); - if Preg::is_match3( + if let Some(m) = Preg::is_match3( format!( "{{^(?:https?|git)://{}/(.*)}}", Self::get_github_domains_regex(&self.config.borrow()) ), url, - Some(&mut m), ) { let mut messages: Vec<String> = vec![]; let protocols_list: Vec<String> = match &protocols { @@ -344,23 +340,23 @@ 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 = PregMatchedGroups::new(); let github_matched = Preg::is_match3( format!( "{{^git@{}:(.+?)\\.git$}}i", Self::get_github_domains_regex(&self.config.borrow()) ), url, - Some(&mut m), - ) || Preg::is_match3( - format!( - "{{^https?://{}/(.*?)(?:\\.git)?$}}i", - Self::get_github_domains_regex(&self.config.borrow()) - ), - url, - Some(&mut m), - ); - if github_matched { + ) + .or_else(|| { + Preg::is_match3( + format!( + "{{^https?://{}/(.*?)(?:\\.git)?$}}i", + Self::get_github_domains_regex(&self.config.borrow()) + ), + url, + ) + }); + if let Some(m) = github_matched { let m1 = m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default(); let m2 = m.get(&CaptureKey::ByIndex(2)).cloned().unwrap_or_default(); if !self.io.has_authentication(&m1) { @@ -410,15 +406,12 @@ impl Git { credentials = vec![rawurlencode(&username), rawurlencode(&password)]; error_msg = self.process.borrow().get_error_output().to_string(); } - } else if Preg::is_match3( + } else if let Some(m) = Preg::is_match3( php_regex!(r"{^(https?)://(bitbucket\.org)/(.*?)(?:\.git)?$}i"), url, - Some(&mut m), - ) || Preg::is_match3( - php_regex!(r"{^(git)@(bitbucket\.org):(.+?\.git)$}i"), - url, - Some(&mut m), - ) { + ) + .or_else(|| Preg::is_match3(php_regex!(r"{^(git)@(bitbucket\.org):(.+?\.git)$}i"), url)) + { // bitbucket either through oauth or app password, with fallback to ssh. let mut bitbucket_util = Bitbucket::new( self.io.clone(), @@ -556,21 +549,22 @@ impl Git { } error_msg = self.process.borrow().get_error_output().to_string(); - } else if Preg::is_match3( + } else if let Some(m) = Preg::is_match3( format!( "{{^(git)@{}:(.+?\\.git)$}}i", Self::get_gitlab_domains_regex(&self.config.borrow()) ), url, - Some(&mut m), - ) || Preg::is_match3( - format!( - "{{^(https?)://{}/(.*)}}i", - Self::get_gitlab_domains_regex(&self.config.borrow()) - ), - url, - Some(&mut m), - ) { + ) + .or_else(|| { + Preg::is_match3( + format!( + "{{^(https?)://{}/(.*)}}i", + Self::get_gitlab_domains_regex(&self.config.borrow()) + ), + url, + ) + }) { let mut m1 = m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default(); let m2 = m.get(&CaptureKey::ByIndex(2)).cloned().unwrap_or_default(); let m3 = m.get(&CaptureKey::ByIndex(3)).cloned().unwrap_or_default(); @@ -1090,14 +1084,7 @@ impl Git { } fn get_authentication_failure(&self, url: &str) -> Option<PregMatchedGroups> { - let mut m = PregMatchedGroups::new(); - if !Preg::is_match3( - php_regex!(r"{^(https?://)([^/]+)(.*)$}i"), - url, - Some(&mut m), - ) { - return None; - } + let m = Preg::is_match3(php_regex!(r"{^(https?://)([^/]+)(.*)$}i"), url)?; let auth_failures = [ "fatal: Authentication failed", @@ -1179,12 +1166,9 @@ impl Git { .borrow() .split_lines(output_mixed.as_string().unwrap_or("")); for line in lines { - let mut matches = PregMatchedGroups::new(); - if Preg::is_match3( - php_regex!(r"{^\s*HEAD branch:\s(.+)\s*$}m"), - &line, - Some(&mut matches), - ) { + 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)) @@ -1307,15 +1291,11 @@ impl Git { &mut output, Option::<&str>::None, ); - if exit_code == 0 { - let mut matches = PregMatchedGroups::new(); - if Preg::is_match3( - php_regex!(r"/^git version (\d+(?:\.\d+)+)/m"), - &output, - Some(&mut matches), - ) { - *version = Some(matches.get(&CaptureKey::ByIndex(1)).cloned()); - } + if exit_code == 0 + && let Some(matches) = + Preg::is_match3(php_regex!(r"/^git version (\d+(?:\.\d+)+)/m"), &output) + { + *version = Some(matches.get(&CaptureKey::ByIndex(1)).cloned()); } } version.clone().unwrap_or(None) diff --git a/crates/shirabe/src/util/github.rs b/crates/shirabe/src/util/github.rs index b7659572..9c22a2b3 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, PregMatchedGroups}; +use shirabe_pcre::{CaptureKey, Preg}; use shirabe_php_shim::Catch as _; use shirabe_php_shim::{PhpMixed, date_local, in_array_loose, php_regex, stripos, strtolower}; @@ -325,12 +325,7 @@ impl GitHub { if stripos(header, "x-github-sso: required").is_none() { continue; } - let mut caps = PregMatchedGroups::new(); - if Preg::match3( - php_regex!(r"{\burl=(?P<url>[^\s;]+)}"), - header, - Some(&mut caps), - ) { + if let Some(caps) = Preg::match3(php_regex!(r"{\burl=(?P<url>[^\s;]+)}"), header) { return caps.get(&CaptureKey::ByName("url".to_string())).cloned(); } } diff --git a/crates/shirabe/src/util/hg.rs b/crates/shirabe/src/util/hg.rs index d9e58623..29d305f0 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, PregNamedGroups}; +use shirabe_pcre::Preg; use shirabe_php_shim::{php_regex, rawurlencode}; use std::sync::OnceLock; @@ -56,16 +56,14 @@ impl Hg { } // Try with the authentication information available - 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" ), &url, - &mut matches, ); - if matched + if let Some(matches) = matched && self .io .has_authentication(matches.get("host").map(|s| s.as_str()).unwrap_or("")) diff --git a/crates/shirabe/src/util/http/response.rs b/crates/shirabe/src/util/http/response.rs index 6ce52643..ea961768 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 = shirabe_pcre::PregMatchedGroups::new(); - if Preg::match3(&pattern, header, Some(&mut matches)) + if let Some(matches) = Preg::match3(&pattern, header) && let Some(s) = matches.get(&shirabe_pcre::CaptureKey::ByIndex(1)) { value = Some(s.clone()); diff --git a/crates/shirabe/src/util/http_downloader.rs b/crates/shirabe/src/util/http_downloader.rs index c478d445..b06d7004 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, PregMatchedGroups}; +use shirabe_pcre::{CaptureKey, Preg}; use shirabe_php_shim::Catch as _; use shirabe_php_shim::{ InvalidArgumentException, LogicException, PhpMixed, array_replace_recursive, extension_loaded, @@ -240,12 +240,8 @@ impl HttpDownloader { let origin = Url::get_origin(&self.config.borrow(), url); // capture username/password from URL if there is one - let mut m = PregMatchedGroups::new(); - if Preg::is_match3( - php_regex!(r"{^https?://([^:/]+):([^@/]+)@([^/]+)}i"), - url, - Some(&mut m), - ) { + if let Some(m) = Preg::is_match3(php_regex!(r"{^https?://([^:/]+):([^@/]+)@([^/]+)}i"), url) + { self.io.borrow_mut().set_authentication( origin.clone(), rawurldecode( diff --git a/crates/shirabe/src/util/process_executor.rs b/crates/shirabe/src/util/process_executor.rs index d87e2ff4..48fa415f 100644 --- a/crates/shirabe/src/util/process_executor.rs +++ b/crates/shirabe/src/util/process_executor.rs @@ -216,17 +216,16 @@ impl ProcessExecutor { let mut process: Process; if is_string(&command) { let mut command_str = command.as_string().unwrap_or("").to_string(); - if Platform::is_windows() { - 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( - &command_str, - &Self::escape(&Self::get_executable(&m1)), - 0, - Some(strlen(&m1)), - ); - } + if Platform::is_windows() + && let Some(m) = Preg::is_match3(php_regex!(r"{^([^:/\\]++) }"), &command_str) + { + let m1 = m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default(); + command_str = substr_replace( + &command_str, + &Self::escape(&Self::get_executable(&m1)), + 0, + Some(strlen(&m1)), + ); } process = Process::from_shell_commandline( diff --git a/crates/shirabe/src/util/remote_filesystem.rs b/crates/shirabe/src/util/remote_filesystem.rs index 40a69f28..0bc004ce 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, PregMatchedGroups}; +use shirabe_pcre::{CaptureKey, Preg}; use shirabe_php_shim::Catch as _; use shirabe_php_shim::{ PhpMixed, RuntimeException, STREAM_NOTIFY_FAILURE, STREAM_NOTIFY_FILE_SIZE_IS, @@ -148,8 +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 = PregMatchedGroups::new(); - if Preg::is_match3(php_regex!("{^HTTP/\\S+ (\\d+)}i"), header, Some(&mut m)) { + 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()) diff --git a/crates/shirabe/src/util/svn.rs b/crates/shirabe/src/util/svn.rs index d07b3ffe..8018efa5 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, PregMatchedGroups}; +use shirabe_pcre::{CaptureKey, Preg}; use shirabe_php_shim::{ LogicException, PhpMixed, RuntimeException, implode, parse_url, php_regex, stripos, strpos, trim, @@ -405,20 +405,14 @@ impl Svn { &["svn".to_string(), "--version".to_string()], &mut output, None, - ) { - let mut matches = PregMatchedGroups::new(); - if Preg::is_match3( - php_regex!(r"{(\d+(?:\.\d+)+)}"), - &output, - Some(&mut matches), - ) { - *cached = Some( - matches - .get(&CaptureKey::ByIndex(1)) - .cloned() - .unwrap_or_default(), - ); - } + ) && let Some(matches) = Preg::is_match3(php_regex!(r"{(\d+(?:\.\d+)+)}"), &output) + { + *cached = Some( + matches + .get(&CaptureKey::ByIndex(1)) + .cloned() + .unwrap_or_default(), + ); } } diff --git a/crates/shirabe/src/util/url.rs b/crates/shirabe/src/util/url.rs index 3afcd962..0a3722eb 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, PregMatchedGroups}; +use shirabe_pcre::{CaptureKey, Preg}; use shirabe_php_shim::{PhpMixed, in_array_strict, parse_url, php_regex}; pub struct Url; @@ -14,13 +14,11 @@ impl Url { .unwrap_or_default(); if host == "api.github.com" || host == "github.com" || host == "www.github.com" { - let mut m = PregMatchedGroups::new(); - if Preg::match3( + if let Some(m) = Preg::match3( php_regex!( r"{^https?://(?:www\.)?github\.com/([^/]+)/([^/]+)/(zip|tar)ball/(.+)$}i" ), &url, - Some(&mut m), ) { url = format!( "https://api.github.com/repos/{}/{}/{}ball/{}", @@ -29,12 +27,11 @@ impl Url { m.get(&CaptureKey::ByIndex(3)).cloned().unwrap_or_default(), r#ref ); - } else if Preg::match3( + } else if let Some(m) = Preg::match3( php_regex!( r"{^https?://(?:www\.)?github\.com/([^/]+)/([^/]+)/archive/.+\.(zip|tar)(?:\.gz)?$}i" ), &url, - Some(&mut m), ) { url = format!( "https://api.github.com/repos/{}/{}/{}ball/{}", @@ -43,12 +40,11 @@ impl Url { m.get(&CaptureKey::ByIndex(3)).cloned().unwrap_or_default(), r#ref ); - } else if Preg::match3( + } else if let Some(m) = Preg::match3( php_regex!( r"{^https?://api\.github\.com/repos/([^/]+)/([^/]+)/(zip|tar)ball(?:/.+)?$}i" ), &url, - Some(&mut m), ) { url = format!( "https://api.github.com/repos/{}/{}/{}ball/{}", @@ -59,13 +55,11 @@ impl Url { ); } } else if host == "bitbucket.org" || host == "www.bitbucket.org" { - let mut m = PregMatchedGroups::new(); - if Preg::match3( + if let Some(m) = Preg::match3( php_regex!( r"{^https?://(?:www\.)?bitbucket\.org/([^/]+)/([^/]+)/get/(.+)\.(zip|tar\.gz|tar\.bz2)$}i" ), &url, - Some(&mut m), ) { url = format!( "https://bitbucket.org/{}/{}/get/{}.{}", @@ -76,13 +70,11 @@ impl Url { ); } } else if host == "gitlab.com" || host == "www.gitlab.com" { - let mut m = PregMatchedGroups::new(); - if Preg::match3( + if let Some(m) = Preg::match3( php_regex!( r"{^https?://(?:www\.)?gitlab\.com/api/v[34]/projects/([^/]+)/repository/archive\.(zip|tar\.gz|tar\.bz2|tar)\?sha=.+$}i" ), &url, - Some(&mut m), ) { url = format!( "https://gitlab.com/api/v4/projects/{}/repository/archive.{}?sha={}", |
