aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe
diff options
context:
space:
mode:
Diffstat (limited to 'crates/shirabe')
-rw-r--r--crates/shirabe/src/autoload/autoload_generator.rs18
-rw-r--r--crates/shirabe/src/cache.rs6
-rw-r--r--crates/shirabe/src/command/archive_command.rs12
-rw-r--r--crates/shirabe/src/command/config_command.rs45
-rw-r--r--crates/shirabe/src/command/create_project_command.rs9
-rw-r--r--crates/shirabe/src/command/diagnose_command.rs7
-rw-r--r--crates/shirabe/src/command/fund_command.rs4
-rw-r--r--crates/shirabe/src/command/init_command.rs10
-rw-r--r--crates/shirabe/src/command/package_discovery_trait.rs14
-rw-r--r--crates/shirabe/src/command/show_command.rs9
-rw-r--r--crates/shirabe/src/command/update_command.rs8
-rw-r--r--crates/shirabe/src/config.rs11
-rw-r--r--crates/shirabe/src/console/application.rs4
-rw-r--r--crates/shirabe/src/console/html_output_formatter.rs6
-rw-r--r--crates/shirabe/src/dependency_resolver/lock_transaction.rs6
-rw-r--r--crates/shirabe/src/dependency_resolver/problem.rs12
-rw-r--r--crates/shirabe/src/downloader/git_downloader.rs30
-rw-r--r--crates/shirabe/src/downloader/svn_downloader.rs7
-rw-r--r--crates/shirabe/src/downloader/zip_downloader.rs7
-rw-r--r--crates/shirabe/src/event_dispatcher/event_dispatcher.rs29
-rw-r--r--crates/shirabe/src/installer/binary_installer.rs8
-rw-r--r--crates/shirabe/src/io/buffer_io.rs12
-rw-r--r--crates/shirabe/src/json/json_file.rs9
-rw-r--r--crates/shirabe/src/json/json_manipulator.rs33
-rw-r--r--crates/shirabe/src/package/loader/root_package_loader.rs24
-rw-r--r--crates/shirabe/src/package/locker.rs4
-rw-r--r--crates/shirabe/src/package/package.rs6
-rw-r--r--crates/shirabe/src/package/version/version_guesser.rs29
-rw-r--r--crates/shirabe/src/platform/version.rs37
-rw-r--r--crates/shirabe/src/repository/composer_repository.rs20
-rw-r--r--crates/shirabe/src/repository/platform_repository.rs108
-rw-r--r--crates/shirabe/src/repository/vcs/forgejo_driver.rs4
-rw-r--r--crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs12
-rw-r--r--crates/shirabe/src/repository/vcs/git_driver.rs14
-rw-r--r--crates/shirabe/src/repository/vcs/github_driver.rs67
-rw-r--r--crates/shirabe/src/repository/vcs/gitlab_driver.rs63
-rw-r--r--crates/shirabe/src/repository/vcs/hg_driver.rs34
-rw-r--r--crates/shirabe/src/repository/vcs/svn_driver.rs55
-rw-r--r--crates/shirabe/src/util/composer_mirror.rs10
-rw-r--r--crates/shirabe/src/util/filesystem.rs10
-rw-r--r--crates/shirabe/src/util/forgejo_url.rs9
-rw-r--r--crates/shirabe/src/util/git.rs87
-rw-r--r--crates/shirabe/src/util/github.rs6
-rw-r--r--crates/shirabe/src/util/hg.rs50
-rw-r--r--crates/shirabe/src/util/http/response.rs2
-rw-r--r--crates/shirabe/src/util/http_downloader.rs14
-rw-r--r--crates/shirabe/src/util/platform.rs9
-rw-r--r--crates/shirabe/src/util/process_executor.rs14
-rw-r--r--crates/shirabe/src/util/remote_filesystem.rs7
-rw-r--r--crates/shirabe/src/util/svn.rs9
-rw-r--r--crates/shirabe/src/util/url.rs40
-rw-r--r--crates/shirabe/tests/all_functional_test.rs6
52 files changed, 307 insertions, 759 deletions
diff --git a/crates/shirabe/src/autoload/autoload_generator.rs b/crates/shirabe/src/autoload/autoload_generator.rs
index 7851182f..48f94263 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, PregMatches};
+use shirabe_pcre::{Preg, PregMatches};
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,
@@ -562,7 +562,7 @@ return array(
if let Some(matches) =
Preg::match3(php_regex!("{ComposerAutoloaderInit([^:\\s]+)::}"), &content)
{
- suffix = matches.get(&CaptureKey::ByIndex(1)).map(str::to_string);
+ suffix = matches.get(1).map(str::to_string);
}
}
@@ -1153,7 +1153,7 @@ return array(
let links = array_merge_map(package.get_replaces(), package.get_provides());
for (_k, link) in &links {
if let Some(matches) = Preg::match3(php_regex!("{^ext-(.+)$}iD"), link.get_target())
- && let Some(ext) = matches.get(&CaptureKey::ByIndex(1)).map(str::to_string)
+ && let Some(ext) = matches.get(1).map(str::to_string)
{
extension_providers
.entry(ext)
@@ -1198,10 +1198,7 @@ return array(
&& let Some(matches) =
Preg::match3(php_regex!("{^ext-(.+)$}iD"), link.get_target())
{
- let ext_key = matches
- .get(&CaptureKey::ByIndex(1))
- .unwrap_or_default()
- .to_string();
+ let ext_key = matches.get(1).unwrap_or_default().to_string();
// skip extension checks if they have a valid provider/replacer
if let Some(provided_list) = extension_providers.get(&ext_key) {
for provided in provided_list {
@@ -1941,11 +1938,8 @@ class ComposerStaticInit{}
php_regex!("{^((?:(?:\\\\\\.){1,2}+/)+)}"),
|matches: &PregMatches| -> String {
// undo preg_quote for the matched string
- *updir_cell.borrow_mut() = Some(str_replace(
- "\\.",
- ".",
- matches.get(&CaptureKey::ByIndex(1)).unwrap_or(""),
- ));
+ *updir_cell.borrow_mut() =
+ Some(str_replace("\\.", ".", matches.get(1).unwrap_or("")));
String::new()
},
diff --git a/crates/shirabe/src/cache.rs b/crates/shirabe/src/cache.rs
index 43aed95d..47f3219c 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::Preg;
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,
@@ -205,8 +205,8 @@ impl Cache {
let message = format!(
"<warning>Writing {} into cache failed after {} of {} bytes written, only {} bytes of free space available</warning>",
temp_file_name,
- 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(),
free_space,
);
diff --git a/crates/shirabe/src/command/archive_command.rs b/crates/shirabe/src/command/archive_command.rs
index c2166b45..31d25b3b 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::Preg;
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;
@@ -232,14 +232,8 @@ impl ArchiveCommand {
&& let Some(matches) =
Preg::match3(php_regex!(r"{@(stable|RC|beta|alpha|dev)$}i"), version_str)
{
- let m1 = matches
- .get(&CaptureKey::ByIndex(1))
- .unwrap_or_default()
- .to_string();
- let m0 = matches
- .get(&CaptureKey::ByIndex(0))
- .unwrap_or_default()
- .to_string();
+ let m1 = matches.get(1).unwrap_or_default().to_string();
+ let m0 = matches.get(0).unwrap_or_default().to_string();
min_stability = VersionParser::normalize_stability(&m1)?;
let full_match_len = m0.len();
version = Some(version_str[..version_str.len() - full_match_len].to_string());
diff --git a/crates/shirabe/src/command/config_command.rs b/crates/shirabe/src/command/config_command.rs
index 5022d09f..8f0cbc51 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::Preg;
use shirabe_php_shim::{
InvalidArgumentException, PhpMixed, RuntimeException, array_is_list, array_merge,
escapeshellcmd, exec, explode, file_exists, impl_php_class, implode, in_array_loose,
@@ -705,16 +705,13 @@ impl Command for ConfigCommand {
php_regex!("/^repos?(?:itories)?(?:\\.(.+))?/"),
&setting_key,
) {
- if matches.get(&CaptureKey::ByIndex(1)).is_none() {
+ if matches.get(1).is_none() {
value = data
.get("repositories")
.cloned()
.unwrap_or_else(|| PhpMixed::Array(IndexMap::new()));
} else {
- let repo_key = matches
- .get(&CaptureKey::ByIndex(1))
- .unwrap_or_default()
- .to_string();
+ let repo_key = matches.get(1).unwrap_or_default().to_string();
let repos = data.get("repositories").cloned();
value = match repos
.as_ref()
@@ -1038,7 +1035,7 @@ impl Command for ConfigCommand {
.borrow_mut()
.as_mut()
.unwrap()
- .remove_repository(matches.get(&CaptureKey::ByIndex(1)).unwrap());
+ .remove_repository(matches.get(1).unwrap());
return Ok(0);
}
@@ -1052,7 +1049,7 @@ impl Command for ConfigCommand {
.as_mut()
.unwrap()
.add_repository(
- matches.get(&CaptureKey::ByIndex(1)).unwrap(),
+ matches.get(1).unwrap(),
PhpMixed::Array(repo),
input.borrow().get_option("append")?.as_bool() == Some(true),
);
@@ -1072,7 +1069,7 @@ impl Command for ConfigCommand {
.as_mut()
.unwrap()
.add_repository(
- matches.get(&CaptureKey::ByIndex(1)).unwrap(),
+ matches.get(1).unwrap(),
PhpMixed::Bool(false),
input.borrow().get_option("append")?.as_bool() == Some(true),
);
@@ -1086,7 +1083,7 @@ impl Command for ConfigCommand {
.as_mut()
.unwrap()
.add_repository(
- matches.get(&CaptureKey::ByIndex(1)).unwrap(),
+ matches.get(1).unwrap(),
value,
input.borrow().get_option("append")?.as_bool() == Some(true),
);
@@ -1336,8 +1333,8 @@ impl Command for ConfigCommand {
.unwrap()
.remove_config_setting(&format!(
"{}.{}",
- matches.get(&CaptureKey::ByIndex(1)).unwrap(),
- matches.get(&CaptureKey::ByIndex(2)).unwrap()
+ matches.get(1).unwrap(),
+ matches.get(2).unwrap()
));
self.config_source
.borrow_mut()
@@ -1345,19 +1342,15 @@ impl Command for ConfigCommand {
.unwrap()
.remove_config_setting(&format!(
"{}.{}",
- matches.get(&CaptureKey::ByIndex(1)).unwrap(),
- matches.get(&CaptureKey::ByIndex(2)).unwrap()
+ matches.get(1).unwrap(),
+ matches.get(2).unwrap()
));
return Ok(0);
}
- let key = format!(
- "{}.{}",
- matches.get(&CaptureKey::ByIndex(1)).unwrap(),
- matches.get(&CaptureKey::ByIndex(2)).unwrap()
- );
- if matches.get(&CaptureKey::ByIndex(1)).unwrap() == "bitbucket-oauth" {
+ let key = format!("{}.{}", matches.get(1).unwrap(), matches.get(2).unwrap());
+ if matches.get(1).unwrap() == "bitbucket-oauth" {
if 2 != values.len() {
return Err(RuntimeException::new(format!(
"Expected two arguments (consumer-key, consumer-secret), got {}",
@@ -1384,9 +1377,7 @@ impl Command for ConfigCommand {
.as_mut()
.unwrap()
.add_config_setting(&key, PhpMixed::Array(obj));
- } else if matches.get(&CaptureKey::ByIndex(1)).unwrap() == "gitlab-token"
- && 2 == values.len()
- {
+ } else if matches.get(1).unwrap() == "gitlab-token" && 2 == values.len() {
self.config_source
.borrow_mut()
.as_mut()
@@ -1401,7 +1392,7 @@ impl Command for ConfigCommand {
.unwrap()
.add_config_setting(&key, PhpMixed::Array(obj));
} else if matches!(
- matches.get(&CaptureKey::ByIndex(1)).unwrap(),
+ matches.get(1).unwrap(),
"github-oauth" | "gitlab-oauth" | "gitlab-token" | "bearer"
) {
if 1 != values.len() {
@@ -1420,7 +1411,7 @@ impl Command for ConfigCommand {
.as_mut()
.unwrap()
.add_config_setting(&key, PhpMixed::String(values[0].clone()));
- } else if matches.get(&CaptureKey::ByIndex(1)).unwrap() == "http-basic" {
+ } else if matches.get(1).unwrap() == "http-basic" {
if 2 != values.len() {
return Err(RuntimeException::new(format!(
"Expected two arguments (username, password), got {}",
@@ -1441,7 +1432,7 @@ impl Command for ConfigCommand {
.as_mut()
.unwrap()
.add_config_setting(&key, PhpMixed::Array(obj));
- } else if matches.get(&CaptureKey::ByIndex(1)).unwrap() == "custom-headers" {
+ } else if matches.get(1).unwrap() == "custom-headers" {
if values.is_empty() {
return Err(RuntimeException::new(
"Expected at least one argument (header), got none".to_string(),
@@ -1482,7 +1473,7 @@ impl Command for ConfigCommand {
.as_mut()
.unwrap()
.add_config_setting(&key, PhpMixed::List(formatted_headers));
- } else if matches.get(&CaptureKey::ByIndex(1)).unwrap() == "forgejo-token" {
+ } else if matches.get(1).unwrap() == "forgejo-token" {
if 2 != values.len() {
return Err(RuntimeException::new(format!(
"Expected two arguments (username, access token), got {}",
diff --git a/crates/shirabe/src/command/create_project_command.rs b/crates/shirabe/src/command/create_project_command.rs
index 8d7b4072..f1b899d3 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::Preg;
use shirabe_php_shim::Catch as _;
use shirabe_php_shim::{
InvalidArgumentException, PhpMixed, RuntimeException, UnexpectedValueException, array_pop,
@@ -540,12 +540,7 @@ impl CreateProjectCommand {
package_version.as_deref().unwrap_or(""),
);
if let Some(matched) = matched {
- stability = Some(
- matched
- .get(&CaptureKey::ByIndex(1))
- .unwrap_or_default()
- .to_string(),
- );
+ stability = Some(matched.get(1).unwrap_or_default().to_string());
} else {
stability = Some(VersionParser::parse_stability(
package_version.as_deref().unwrap_or(""),
diff --git a/crates/shirabe/src/command/diagnose_command.rs b/crates/shirabe/src/command/diagnose_command.rs
index 448de89f..820b026c 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::Preg;
use shirabe_php_shim::Catch as _;
use shirabe_php_shim::{
AnyThrowable, CmpOp, InvalidArgumentException, PHP_EOL, PhpClass as _, PhpMixed,
@@ -866,10 +866,7 @@ impl DiagnoseCommand {
php_regex!("{Configure Command(?: *</td><td class=\"v\">| *=> *)(.*?)(?:</td>|$)}m"),
&diagnostics.phpinfo_general,
) {
- let configure = phpinfo_match
- .get(&CaptureKey::ByIndex(1))
- .unwrap_or_default()
- .to_string();
+ let configure = phpinfo_match.get(1).unwrap_or_default().to_string();
let configure = configure.as_str();
if configure.contains("--enable-sigchild") {
diff --git a/crates/shirabe/src/command/fund_command.rs b/crates/shirabe/src/command/fund_command.rs
index 22c94539..f900bce0 100644
--- a/crates/shirabe/src/command/fund_command.rs
+++ b/crates/shirabe/src/command/fund_command.rs
@@ -10,7 +10,7 @@ use crate::package::base_package::{self};
use crate::repository::CompositeRepository;
use crate::repository::RepositoryInterface;
use indexmap::IndexMap;
-use shirabe_pcre::{CaptureKey, Preg};
+use shirabe_pcre::Preg;
use shirabe_php_shim::{PhpMixed, impl_php_class, php_regex};
use shirabe_semver::constraint::AnyConstraint;
use shirabe_semver::constraint::MatchAllConstraint;
@@ -65,7 +65,7 @@ impl FundCommand {
if r#type == "github"
&& let Some(matches) =
Preg::is_match3(php_regex!(r"{^https://github.com/([^/]+)$}"), &url)
- && let Some(sponsor) = matches.get(&CaptureKey::ByIndex(1)).map(str::to_string)
+ && let Some(sponsor) = matches.get(1).map(str::to_string)
{
url = format!("https://github.com/sponsors/{}", sponsor);
}
diff --git a/crates/shirabe/src/command/init_command.rs b/crates/shirabe/src/command/init_command.rs
index 81e1e381..030a8657 100644
--- a/crates/shirabe/src/command/init_command.rs
+++ b/crates/shirabe/src/command/init_command.rs
@@ -94,9 +94,7 @@ impl InitCommand {
php_regex!(r#"/^(?P<name>[- .,\p{L}\p{N}\p{Mn}\'’\"()]+)(?:\s+<(?P<email>.+?)>)?$/u"#),
author,
) {
- let email = m
- .get(&CaptureKey::ByName("email".to_string()))
- .map(str::to_string);
+ let email = m.name("email").map(str::to_string);
if let Some(ref email) = email
&& !self.is_valid_email(email)
{
@@ -108,11 +106,7 @@ impl InitCommand {
let mut result: IndexMap<String, Option<String>> = IndexMap::new();
result.insert(
"name".to_string(),
- Some(trim(
- m.get(&CaptureKey::ByName("name".to_string()))
- .unwrap_or_default(),
- None,
- )),
+ Some(trim(m.name("name").unwrap_or_default(), None)),
);
result.insert("email".to_string(), email);
diff --git a/crates/shirabe/src/command/package_discovery_trait.rs b/crates/shirabe/src/command/package_discovery_trait.rs
index 5b53bcbd..d31b5894 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::Preg;
use shirabe_php_shim::Catch as _;
use shirabe_php_shim::{
Exception, InvalidArgumentException, LogicException, PHP_EOL, PhpMixed, array_keys,
@@ -334,27 +334,21 @@ pub trait PackageDiscoveryTrait: BaseCommand {
php_regex!(r"{^\s*(?P<name>[\S/]+)(?:\s+(?P<version>\S+))?\s*$}"),
&selection,
) {
- if let Some(v) = m
- .get(&CaptureKey::ByName("version".to_string()))
- .map(str::to_string)
- {
+ if let Some(v) = m.name("version").map(str::to_string) {
// parsing `acme/example ~2.3`
// validate version constraint
version_parser_clone.parse_constraints(&v)?;
return Ok(PhpMixed::String(format!(
"{} {}",
- m.get(&CaptureKey::ByName("name".to_string()))
- .unwrap_or_default(),
+ m.name("name").unwrap_or_default(),
v,
)));
}
// parsing `acme/example`
return Ok(PhpMixed::String(
- m.get(&CaptureKey::ByName("name".to_string()))
- .unwrap_or_default()
- .to_string(),
+ m.name("name").unwrap_or_default().to_string(),
));
}
diff --git a/crates/shirabe/src/command/show_command.rs b/crates/shirabe/src/command/show_command.rs
index b479c9a8..4be7873c 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::Preg;
use shirabe_php_shim::{
CmpOp, DATE_ATOM, InvalidArgumentException, LogicException, PhpMixed, UnexpectedValueException,
array_search, date_format_to_strftime, date_local, extension_loaded, impl_php_class,
@@ -1378,12 +1378,9 @@ impl ShowCommand {
&package.get_version(),
)
{
- let zero_major = groups
- .get(&CaptureKey::ByName("zero_major".to_string()))
- .unwrap_or_default()
- .to_string();
+ let zero_major = groups.name("zero_major").unwrap_or_default().to_string();
let first_meaningful = groups
- .get(&CaptureKey::ByName("first_meaningful".to_string()))
+ .name("first_meaningful")
.unwrap_or_default()
.to_string()
.parse::<i64>()
diff --git a/crates/shirabe/src/command/update_command.rs b/crates/shirabe/src/command/update_command.rs
index 5c119489..e9f0e3ce 100644
--- a/crates/shirabe/src/command/update_command.rs
+++ b/crates/shirabe/src/command/update_command.rs
@@ -27,7 +27,7 @@ use crate::repository::PlatformRepository;
use crate::repository::RepositorySet;
use crate::util::HttpDownloader;
use indexmap::IndexMap;
-use shirabe_pcre::{CaptureKey, Preg};
+use shirabe_pcre::Preg;
use shirabe_php_shim::{
InvalidArgumentException, PhpMixed, RuntimeException, array_filter, array_intersect,
array_keys, array_merge_map, array_search_in_vec, impl_php_class, php_regex, strtolower,
@@ -464,10 +464,8 @@ impl Command for UpdateCommand {
let Some(matches) = matches else {
continue;
};
- let constraint = parser.parse_constraints(&format!(
- "~{}",
- matches.get(&CaptureKey::ByIndex(1)).unwrap_or_default()
- ))?;
+ let constraint = parser
+ .parse_constraints(&format!("~{}", matches.get(1).unwrap_or_default()))?;
if let Some(existing) = temporary_constraints.get(&package.get_name()) {
temporary_constraints.insert(
package.get_name(),
diff --git a/crates/shirabe/src/config.rs b/crates/shirabe/src/config.rs
index dd86149c..92b13fb8 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, PregMatches};
+use shirabe_pcre::{Preg, PregMatches};
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,
@@ -658,12 +658,12 @@ impl Config {
.into());
};
let mut size = matches
- .get(&CaptureKey::ByIndex(1))
+ .get(1)
.unwrap_or_default()
.to_string()
.parse::<f64>()
.unwrap_or(0.0);
- let unit = matches.get(&CaptureKey::ByIndex(2)).map(str::to_string);
+ let unit = matches.get(2).map(str::to_string);
if let Some(unit) = unit {
match strtolower(&unit).as_str() {
"g" => {
@@ -960,10 +960,7 @@ impl Config {
let result = Preg::replace_callback(
php_regex!(r"#\{\$(.+)\}#"),
|m: &PregMatches| -> String {
- let key_match = m
- .get(&CaptureKey::ByIndex(1))
- .unwrap_or_default()
- .to_string();
+ let key_match = m.get(1).unwrap_or_default().to_string();
match self.get_with_flags(&key_match, flags) {
Ok(v) => php_to_string(&v),
Err(e) => {
diff --git a/crates/shirabe/src/console/application.rs b/crates/shirabe/src/console/application.rs
index ca645635..25379a27 100644
--- a/crates/shirabe/src/console/application.rs
+++ b/crates/shirabe/src/console/application.rs
@@ -1792,9 +1792,7 @@ impl Application {
let mut offset = 0i64;
while let Some(m) = preg_match2(php_regex!(r"/.{1,10000}/u"), &utf8_string, offset as usize)
{
- let m0 = m
- .get(&shirabe_php_shim::CaptureKey::ByIndex(0))
- .unwrap_or("");
+ let m0 = m.get(0).unwrap_or("");
offset += shirabe_php_shim::strlen(m0);
let chunk = m0;
diff --git a/crates/shirabe/src/console/html_output_formatter.rs b/crates/shirabe/src/console/html_output_formatter.rs
index 4a5583fb..694f8de6 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, PregMatches};
+use shirabe_pcre::{Preg, PregMatches};
use shirabe_symfony_console::formatter::OutputFormatter;
use shirabe_symfony_console::formatter::OutputFormatterInterface;
use shirabe_symfony_console::formatter::OutputFormatterStyleInterface;
@@ -73,8 +73,8 @@ impl HtmlOutputFormatter {
}
fn format_html(&self, matches: &PregMatches) -> String {
- let codes_str = matches.get(&CaptureKey::ByIndex(1)).unwrap_or("");
- let content = matches.get(&CaptureKey::ByIndex(2)).unwrap_or("");
+ let codes_str = matches.get(1).unwrap_or("");
+ let content = matches.get(2).unwrap_or("");
let mut out = String::from("<span style=\"");
for code_str in codes_str.split(';') {
diff --git a/crates/shirabe/src/dependency_resolver/lock_transaction.rs b/crates/shirabe/src/dependency_resolver/lock_transaction.rs
index 810c19af..a238f2d6 100644
--- a/crates/shirabe/src/dependency_resolver/lock_transaction.rs
+++ b/crates/shirabe/src/dependency_resolver/lock_transaction.rs
@@ -177,11 +177,7 @@ impl LockTransaction {
let new_dist_url = Preg::replace_callback(
php_regex!(r"{(/|sha=)[a-f0-9]{40}(/|$)}i"),
|m: &shirabe_pcre::PregMatches| -> String {
- let get = |i: usize| -> String {
- m.get(&shirabe_pcre::CaptureKey::ByIndex(i))
- .unwrap_or_default()
- .to_string()
- };
+ let get = |i: usize| -> String { m.get(i).unwrap_or_default().to_string() };
format!("{}{}{}", get(1), dist_reference, get(2))
},
&package.get_dist_url().unwrap(),
diff --git a/crates/shirabe/src/dependency_resolver/problem.rs b/crates/shirabe/src/dependency_resolver/problem.rs
index 63561e98..c42caa35 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::Preg;
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,
@@ -234,14 +234,8 @@ impl Problem {
None
};
if let Some(m) = matched {
- let pkg_key = m
- .get(&CaptureKey::ByIndex(1))
- .unwrap_or_default()
- .to_string();
- let m2 = m
- .get(&CaptureKey::ByIndex(2))
- .unwrap_or_default()
- .to_string();
+ let pkg_key = m.get(1).unwrap_or_default().to_string();
+ let m2 = m.get(2).unwrap_or_default().to_string();
message = str_replace("%", "%%", &message);
let template = Preg::replace(php_regex!(r"{^\S+ \S+ }"), "%s%s ", &message);
messages.push(template.clone());
diff --git a/crates/shirabe/src/downloader/git_downloader.rs b/crates/shirabe/src/downloader/git_downloader.rs
index 83f72300..b816aa18 100644
--- a/crates/shirabe/src/downloader/git_downloader.rs
+++ b/crates/shirabe/src/downloader/git_downloader.rs
@@ -99,10 +99,7 @@ impl GitDownloader {
// could not match the HEAD for some reason
return Ok(None);
};
- let head_ref = head_match
- .get(&CaptureKey::ByIndex(1))
- .unwrap_or_default()
- .to_string();
+ let head_ref = head_match.get(1).unwrap_or_default().to_string();
let branches_match = Preg::is_match_all(
format!("{{^{} refs/heads/(.+)$}}mi", preg_quote(&head_ref, None)),
@@ -511,18 +508,9 @@ impl GitDownloader {
url,
) {
let protocols = self.inner.config.borrow_mut().get("github-protocols");
- let m1 = match_
- .get(&CaptureKey::ByIndex(1))
- .unwrap_or_default()
- .to_string();
- let m2 = match_
- .get(&CaptureKey::ByIndex(2))
- .unwrap_or_default()
- .to_string();
- let m3 = match_
- .get(&CaptureKey::ByIndex(3))
- .unwrap_or_default()
- .to_string();
+ let m1 = match_.get(1).unwrap_or_default().to_string();
+ let m2 = match_.get(2).unwrap_or_default().to_string();
+ let m3 = match_.get(3).unwrap_or_default().to_string();
let mut push_url = format!("git@{}:{}/{}.git", m1, m2, m3);
if !in_array_strict("ssh".to_string(), protocols.values()) {
push_url = format!("https://{}/{}/{}.git", m1, m2, m3);
@@ -1110,14 +1098,8 @@ impl VcsDownloader for GitDownloader {
&& let Some(composer_match) =
Preg::is_match3(php_regex!(r"{^composer\s+(?P<url>\S+)}m"), &output)
{
- let origin_url = origin_match
- .get(&CaptureKey::ByName("url".to_string()))
- .unwrap_or_default()
- .to_string();
- let composer_url = composer_match
- .get(&CaptureKey::ByName("url".to_string()))
- .unwrap_or_default()
- .to_string();
+ let origin_url = origin_match.name("url").unwrap_or_default().to_string();
+ let composer_url = composer_match.name("url").unwrap_or_default().to_string();
if origin_url == composer_url
&& Some(composer_url.as_str()) != target.get_source_url().as_deref()
{
diff --git a/crates/shirabe/src/downloader/svn_downloader.rs b/crates/shirabe/src/downloader/svn_downloader.rs
index d146337a..4931e539 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::Preg;
use shirabe_php_shim::{
CmpOp, PhpMixed, RuntimeException, impl_php_class, is_dir, php_regex, preg_split,
version_compare,
@@ -384,10 +384,7 @@ impl VcsDownloader for SvnDownloader {
let url_pattern = "#<url>(.*)</url>#";
let base_url = if let Some(matches) = Preg::match3(url_pattern, &output) {
- matches
- .get(&CaptureKey::ByIndex(1))
- .unwrap_or_default()
- .to_string()
+ matches.get(1).unwrap_or_default().to_string()
} else {
return Err(RuntimeException::new(format!(
"Unable to determine svn url for path {}",
diff --git a/crates/shirabe/src/downloader/zip_downloader.rs b/crates/shirabe/src/downloader/zip_downloader.rs
index 8ecd131f..b4802066 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::Preg;
use shirabe_php_shim::Catch as _;
use shirabe_php_shim::{
CmpOp, ErrorException, PhpMixed, RuntimeException, UnexpectedValueException, ZipArchive,
@@ -116,10 +116,7 @@ impl ZipDownloader {
&& let Some(m) =
Preg::is_match3(php_regex!(r"{^\s*7-Zip(?:\s\[64\])?\s([0-9.]+)}"), &output)
{
- let m1 = m
- .get(&CaptureKey::ByIndex(1))
- .unwrap_or_default()
- .to_string();
+ let m1 = m.get(1).unwrap_or_default().to_string();
if version_compare(&m1, "21.01", CmpOp::Lt) {
self.inner.io.borrow().write_error(&format!(
" <warning>Unzipping using {} {} may result in incorrect file permissions. Install {} 21.01+ or unzip to ensure you get correct permissions.</warning>",
diff --git a/crates/shirabe/src/event_dispatcher/event_dispatcher.rs b/crates/shirabe/src/event_dispatcher/event_dispatcher.rs
index 8617ba8f..fd4b4663 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::Preg;
use shirabe_php_rpc::{
PhpThrow, PluginValue, RustMethodDispatcher, RustObjHandle, call_function,
call_function_with_dispatcher, call_php_method, call_static_method,
@@ -956,13 +956,7 @@ try {{
if Platform::is_windows() {
path_and_args = Preg::replace_callback(
php_regex!("{^\\S+}"),
- |m| {
- str_replace(
- "/",
- "\\",
- m.get(&CaptureKey::ByIndex(0)).unwrap(),
- )
- },
+ |m| str_replace("/", "\\", m.get(0).unwrap()),
&path_and_args,
);
}
@@ -971,10 +965,7 @@ try {{
if let Some(m) =
Preg::is_match3(php_regex!("{^[^\\'\"\\s/\\\\]+}"), &path_and_args)
{
- let m0 = m
- .get(&CaptureKey::ByIndex(0))
- .unwrap_or_default()
- .to_string();
+ let m0 = m.get(0).unwrap_or_default().to_string();
if !file_exists(&m0) {
let finder = ExecutableFinder::new();
if let Some(path_to_exec) = finder.find(&m0, None, &[]) {
@@ -993,11 +984,7 @@ try {{
path_and_args = format!(
"{}{}",
path_to_exec,
- substr(
- &path_and_args,
- strlen(m.get(&CaptureKey::ByIndex(0)).unwrap()),
- None
- )
+ substr(&path_and_args, strlen(m.get(0).unwrap()), None)
);
}
}
@@ -1013,13 +1000,7 @@ try {{
if Platform::is_windows() {
exec = Preg::replace_callback(
php_regex!("{^\\S+}"),
- |m| {
- str_replace(
- "/",
- "\\",
- m.get(&CaptureKey::ByIndex(0)).unwrap(),
- )
- },
+ |m| str_replace("/", "\\", m.get(0).unwrap()),
&exec,
);
}
diff --git a/crates/shirabe/src/installer/binary_installer.rs b/crates/shirabe/src/installer/binary_installer.rs
index 1e750439..4bcb6865 100644
--- a/crates/shirabe/src/installer/binary_installer.rs
+++ b/crates/shirabe/src/installer/binary_installer.rs
@@ -8,7 +8,7 @@ use crate::util::Filesystem;
use crate::util::Platform;
use crate::util::ProcessExecutor;
use crate::util::Silencer;
-use shirabe_pcre::{CaptureKey, Preg};
+use shirabe_pcre::Preg;
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,
@@ -205,7 +205,7 @@ impl BinaryInstaller {
php_regex!(r"{^#!/(?:usr/bin/env )?(?:[^/]+/)*(.+)$}m"),
&line,
) {
- return trim(m.get(&CaptureKey::ByIndex(1)).unwrap_or(""), None);
+ return trim(m.get(1).unwrap_or(""), None);
}
"php".to_string()
@@ -321,7 +321,7 @@ impl BinaryInstaller {
&bin_contents,
) {
// carry over the existing shebang if present, otherwise add our own
- let proxy_code = match m.get(&CaptureKey::ByIndex(1)) {
+ let proxy_code = match m.get(1) {
None => "#!/usr/bin/env php".to_string(),
Some(shebang) => trim(shebang, None),
};
@@ -369,7 +369,7 @@ impl BinaryInstaller {
$data = str_replace('__FILE__', var_export($this->realpath, true), $data);"
.to_string();
}
- if trim(m.get(&CaptureKey::ByIndex(0)).unwrap_or(""), None) != "<?php" {
+ if trim(m.get(0).unwrap_or(""), None) != "<?php" {
stream_hint =
" using a stream wrapper to prevent the shebang from being output on PHP<8\n *"
.to_string();
diff --git a/crates/shirabe/src/io/buffer_io.rs b/crates/shirabe/src/io/buffer_io.rs
index ce67c7eb..466efe0b 100644
--- a/crates/shirabe/src/io/buffer_io.rs
+++ b/crates/shirabe/src/io/buffer_io.rs
@@ -77,15 +77,9 @@ impl BufferIO {
let next = Preg::replace_callback(
php_regex!(r"{(^|\n|\x08)(.+?)(\x08+)}"),
|matches: &shirabe_pcre::PregMatches| -> String {
- let g1 = matches
- .get(&shirabe_pcre::CaptureKey::ByIndex(1))
- .unwrap_or("");
- let g2 = matches
- .get(&shirabe_pcre::CaptureKey::ByIndex(2))
- .unwrap_or("");
- let g3 = matches
- .get(&shirabe_pcre::CaptureKey::ByIndex(3))
- .unwrap_or("");
+ let g1 = matches.get(1).unwrap_or("");
+ let g2 = matches.get(2).unwrap_or("");
+ let g3 = matches.get(3).unwrap_or("");
let pre = strip_tags(g2);
if pre.len() == g3.len() {
diff --git a/crates/shirabe/src/json/json_file.rs b/crates/shirabe/src/json/json_file.rs
index 2d1185e8..004645c5 100644
--- a/crates/shirabe/src/json/json_file.rs
+++ b/crates/shirabe/src/json/json_file.rs
@@ -8,7 +8,7 @@ use crate::json::JsonValidationException;
use crate::util::Filesystem;
use crate::util::HttpDownloader;
use crate::util::Silencer;
-use shirabe_pcre::{CaptureKey, Preg};
+use shirabe_pcre::Preg;
use shirabe_php_shim::Catch as _;
use shirabe_php_shim::{
InvalidArgumentException, JSON_PRETTY_PRINT, JSON_UNESCAPED_SLASHES, JSON_UNESCAPED_UNICODE,
@@ -451,7 +451,7 @@ impl JsonFile {
return Ok(Preg::replace_callback(
php_regex!(r"#^ {4,}#m"),
move |m: &shirabe_pcre::PregMatches| -> String {
- let whole = m.get(&shirabe_pcre::CaptureKey::ByIndex(0)).unwrap_or("");
+ let whole = m.get(0).unwrap_or("");
str_repeat(&indent_owned, (strlen(whole) / 4) as usize)
},
&json,
@@ -552,10 +552,7 @@ impl JsonFile {
pub fn detect_indenting(json: Option<&str>) -> String {
if let Some(m) = Preg::is_match3(php_regex!(r##"#^([ \t]+)"#m"##), json.unwrap_or("")) {
- return m
- .get(&CaptureKey::ByIndex(1))
- .unwrap_or_default()
- .to_string();
+ return m.get(1).unwrap_or_default().to_string();
}
Self::INDENT_DEFAULT.to_string()
diff --git a/crates/shirabe/src/json/json_manipulator.rs b/crates/shirabe/src/json/json_manipulator.rs
index 0f0d50de..9fa8e1e0 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::Preg;
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,
@@ -115,10 +115,7 @@ impl JsonManipulator {
if let Some(groups) =
Preg::is_match3(php_regex!("#^\\s*\\{\\s*\\S+.*?(\\s*\\}\\s*)$#s"), &links)
{
- let groups_1 = groups
- .get(&CaptureKey::ByIndex(1))
- .unwrap_or_default()
- .to_string();
+ let groups_1 = groups.get(1).unwrap_or_default().to_string();
// link missing but non empty links
links = Preg::replace(
format!("{{{}$}}", preg_quote(&groups_1, None)),
@@ -744,16 +741,14 @@ impl JsonManipulator {
&children,
) {
let mut whitespace = leading_match
- .get(&CaptureKey::ByName("trailingspace".to_string()))
+ .name("trailingspace")
.unwrap_or_default()
.to_string();
let leading_space = leading_match
- .get(&CaptureKey::ByName("leadingspace".to_string()))
+ .name("leadingspace")
.unwrap_or_default()
.to_string();
- let content_present = leading_match
- .get(&CaptureKey::ByName("content".to_string()))
- .is_some();
+ let content_present = leading_match.name("content").is_some();
if content_present {
let mut value_local = value;
if let Some(ref sub) = sub_name {
@@ -942,9 +937,7 @@ impl JsonManipulator {
if let Some(empty_match) = Preg::is_match3(
php_regex!("#^\\{\\s*?(?P<content>\\S+.*?)?(?P<trailingspace>\\s*)\\}$#s"),
&children_clean,
- ) && empty_match
- .get(&CaptureKey::ByName("content".to_string()))
- .is_none()
+ ) && empty_match.name("content").is_none()
{
self.contents = format!(
"{}{{{}{}}}{}",
@@ -1043,11 +1036,11 @@ impl JsonManipulator {
&children,
) {
let leading_whitespace = leading_match
- .get(&CaptureKey::ByName("leadingspace".to_string()))
+ .name("leadingspace")
.unwrap_or_default()
.to_string();
let mut whitespace = leading_match
- .get(&CaptureKey::ByName("trailingspace".to_string()))
+ .name("trailingspace")
.unwrap_or_default()
.to_string();
let mut leading_item_whitespace =
@@ -1062,10 +1055,7 @@ impl JsonManipulator {
item_depth = 0;
}
- if leading_match
- .get(&CaptureKey::ByName("content".to_string()))
- .is_some()
- {
+ if leading_match.name("content").is_some() {
// child missing but non empty children
if append {
children = Preg::replace(
@@ -1330,10 +1320,7 @@ impl JsonManipulator {
// append at the end of the file and keep whitespace
if let Some(tail_match) = Preg::is_match3(php_regex!("#[^{\\s](\\s*)\\}$#"), &self.contents)
{
- let tail_match_1 = tail_match
- .get(&CaptureKey::ByIndex(1))
- .unwrap_or_default()
- .to_string();
+ let tail_match_1 = tail_match.get(1).unwrap_or_default().to_string();
self.contents = Preg::replace(
format!("#{}\\}}$#", tail_match_1),
&addcslashes(
diff --git a/crates/shirabe/src/package/loader/root_package_loader.rs b/crates/shirabe/src/package/loader/root_package_loader.rs
index 1d068ad6..012c30fd 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::Preg;
use shirabe_php_shim::{
PhpMixed, RuntimeException, UnexpectedValueException, php_regex, preg_split, strtolower,
};
@@ -256,14 +256,8 @@ impl RootPackageLoader {
php_regex!(r"{(?:^|\| *|, *)([^,\s#|]+)(?:#[^ ]+)? +as +([^,\s|]+)(?:$| *\|| *,)}"),
req_version,
) {
- 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 mut alias = IndexMap::new();
alias.insert("package".to_string(), strtolower(req_name));
alias.insert(
@@ -324,10 +318,7 @@ impl RootPackageLoader {
for constraint in &constraints {
if let Some(m) = Preg::is_match3(&pattern, constraint) {
let name = strtolower(req_name);
- let m1 = m
- .get(&CaptureKey::ByIndex(1))
- .unwrap_or_default()
- .to_string();
+ let m1 = m.get(1).unwrap_or_default().to_string();
let normalized_m1 = VersionParser::normalize_stability(&m1).unwrap_or_default();
let stability = stabilities[normalized_m1.as_str()];
@@ -375,12 +366,7 @@ impl RootPackageLoader {
&& VersionParser::parse_stability(&req_version) == "dev"
{
let name = strtolower(req_name);
- references.insert(
- name,
- m.get(&CaptureKey::ByIndex(1))
- .unwrap_or_default()
- .to_string(),
- );
+ references.insert(name, m.get(1).unwrap_or_default().to_string());
}
}
references
diff --git a/crates/shirabe/src/package/locker.rs b/crates/shirabe/src/package/locker.rs
index f27f44a2..7d45e573 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::Preg;
use shirabe_php_shim::Catch as _;
use shirabe_php_shim::{
DATE_RFC3339, LogicException, PhpMixed, RuntimeException, array_intersect, array_keys,
@@ -848,7 +848,7 @@ impl Locker {
output.as_string().unwrap_or(""),
) {
let ts = m
- .get(&CaptureKey::ByIndex(1))
+ .get(1)
.unwrap_or_default()
.to_string()
.parse::<i64>()
diff --git a/crates/shirabe/src/package/package.rs b/crates/shirabe/src/package/package.rs
index c987f2fe..2e2d5feb 100644
--- a/crates/shirabe/src/package/package.rs
+++ b/crates/shirabe/src/package/package.rs
@@ -434,11 +434,7 @@ impl Package {
self.set_dist_url(Some(Preg::replace_callback(
php_regex!("{(/|sha=)[a-f0-9]{40}(/|$)}i"),
|m: &shirabe_pcre::PregMatches| -> String {
- let get = |i: usize| -> String {
- m.get(&shirabe_pcre::CaptureKey::ByIndex(i))
- .unwrap_or_default()
- .to_string()
- };
+ let get = |i: usize| -> String { m.get(i).unwrap_or_default().to_string() };
format!("{}{}{}", get(1), reference, get(2))
},
&self.get_dist_url().unwrap_or_default(),
diff --git a/crates/shirabe/src/package/version/version_guesser.rs b/crates/shirabe/src/package/version/version_guesser.rs
index a01bf469..c85000e7 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::Preg;
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,
@@ -236,14 +236,8 @@ impl VersionGuesser {
&branch,
)
{
- let g1 = m
- .get(&CaptureKey::ByIndex(1))
- .unwrap_or_default()
- .to_string();
- let g2 = m
- .get(&CaptureKey::ByIndex(2))
- .unwrap_or_default()
- .to_string();
+ let g1 = m.get(1).unwrap_or_default().to_string();
+ let g2 = m.get(2).unwrap_or_default().to_string();
if g1 == "(no branch)"
|| strpos(&g1, "(detached ") == Some(0)
|| strpos(&g1, "(HEAD detached at") == Some(0)
@@ -270,11 +264,7 @@ impl VersionGuesser {
&branch,
)
{
- branches.push(
- m.get(&CaptureKey::ByIndex(1))
- .unwrap_or_default()
- .to_string(),
- );
+ branches.push(m.get(1).unwrap_or_default().to_string());
}
}
@@ -708,9 +698,9 @@ impl VersionGuesser {
);
if let Some(matches) = Preg::is_match3(&url_pattern, &output) {
- let m1 = matches.get(&CaptureKey::ByIndex(1)).unwrap_or_default();
- let m2 = matches.get(&CaptureKey::ByIndex(2));
- let m3 = matches.get(&CaptureKey::ByIndex(3));
+ let m1 = matches.get(1).unwrap_or_default();
+ let m2 = matches.get(2);
+ let m3 = matches.get(3);
if let Some(m2) = m2
&& let Some(m3) = m3
&& (branches_path == *m2 || tags_path == *m2)
@@ -761,10 +751,7 @@ impl VersionGuesser {
}
};
if let Some(m) = Preg::is_match3(php_regex!(r"{^(\d+(?:\.\d+)*)-dev$}i"), &version) {
- return Ok(format!(
- "{}.x-dev",
- m.get(&CaptureKey::ByIndex(1)).unwrap_or_default()
- ));
+ return Ok(format!("{}.x-dev", m.get(1).unwrap_or_default()));
}
Ok(version)
diff --git a/crates/shirabe/src/platform/version.rs b/crates/shirabe/src/platform/version.rs
index 204bdccd..00ff3097 100644
--- a/crates/shirabe/src/platform/version.rs
+++ b/crates/shirabe/src/platform/version.rs
@@ -1,6 +1,6 @@
//! ref: composer/src/Composer/Platform/Version.php
-use shirabe_pcre::{CaptureKey, Preg};
+use shirabe_pcre::Preg;
use shirabe_php_shim::{CmpOp, php_regex, version_compare};
pub struct Version;
@@ -16,18 +16,9 @@ impl Version {
openssl_version,
)?;
- let version = matches
- .get(&CaptureKey::ByName("version".to_string()))
- .unwrap_or_default()
- .to_string();
- let patch_str = matches
- .get(&CaptureKey::ByName("patch".to_string()))
- .unwrap_or_default()
- .to_string();
- let suffix_str = matches
- .get(&CaptureKey::ByName("suffix".to_string()))
- .unwrap_or_default()
- .to_string();
+ let version = matches.name("version").unwrap_or_default().to_string();
+ let patch_str = matches.name("patch").unwrap_or_default().to_string();
+ let suffix_str = matches.name("suffix").unwrap_or_default().to_string();
let patch = if version_compare(&version, "3.0.0", CmpOp::Lt) {
format!(
@@ -56,14 +47,8 @@ impl Version {
libjpeg_version,
)?;
- let major = matches
- .get(&CaptureKey::ByName("major".to_string()))
- .unwrap_or_default()
- .to_string();
- let minor = matches
- .get(&CaptureKey::ByName("minor".to_string()))
- .unwrap_or_default()
- .to_string();
+ let major = matches.name("major").unwrap_or_default().to_string();
+ let minor = matches.name("minor").unwrap_or_default().to_string();
Some(format!(
"{}.{}",
major,
@@ -77,14 +62,8 @@ impl Version {
zoneinfo_version,
)?;
- let year = matches
- .get(&CaptureKey::ByName("year".to_string()))
- .unwrap_or_default()
- .to_string();
- let revision = matches
- .get(&CaptureKey::ByName("revision".to_string()))
- .unwrap_or_default()
- .to_string();
+ let year = matches.name("year").unwrap_or_default().to_string();
+ let revision = matches.name("revision").unwrap_or_default().to_string();
Some(format!(
"{}.{}",
year,
diff --git a/crates/shirabe/src/repository/composer_repository.rs b/crates/shirabe/src/repository/composer_repository.rs
index d42a9778..8970a227 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::Preg;
use shirabe_php_shim::Catch as _;
use shirabe_php_shim::{
AnyThrowable, CmpOp, InvalidArgumentException, LogicException, PHP_EOL, PhpMixed,
@@ -250,7 +250,7 @@ impl ComposerRepository {
&url,
) {
let proto = match_packagist
- .get(&CaptureKey::ByName("proto".to_string()))
+ .name("proto")
.unwrap_or_default()
.to_string();
url = format!("{}://repo.packagist.org", proto);
@@ -784,14 +784,8 @@ impl ComposerRepository {
&query,
) && let Some(list_url) = self.list_url.as_ref()
{
- let q = match_groups
- .get(&CaptureKey::ByName("query".to_string()))
- .unwrap_or_default()
- .to_string();
- let vendor = match_groups
- .get(&CaptureKey::ByName("vendor".to_string()))
- .unwrap_or_default()
- .to_string();
+ let q = match_groups.name("query").unwrap_or_default().to_string();
+ let vendor = match_groups.name("vendor").unwrap_or_default().to_string();
let url = format!(
"{}?vendor={}&filter={}",
list_url,
@@ -2427,11 +2421,7 @@ impl ComposerRepository {
if url.starts_with('/') {
if let Some(matches) = Preg::is_match3(php_regex!(r"{^[^:]++://[^/]*+}"), &self.url) {
- return Ok(format!(
- "{}{}",
- matches.get(&CaptureKey::ByIndex(0)).unwrap_or_default(),
- url
- ));
+ return Ok(format!("{}{}", matches.get(0).unwrap_or_default(), url));
}
return Ok(self.url.clone());
diff --git a/crates/shirabe/src/repository/platform_repository.rs b/crates/shirabe/src/repository/platform_repository.rs
index 94ecc015..3df346de 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::Preg;
use shirabe_php_rpc::PlatformInfo;
use shirabe_php_shim::{
InvalidArgumentException, PhpMixed, UnexpectedValueException, array_map_str_fn,
@@ -323,7 +323,7 @@ impl PlatformRepository {
self.add_library(
&mut libraries,
&format!("{}-librabbitmq", name),
- librabbitmq_matches.get(&CaptureKey::ByName("version".to_string())),
+ librabbitmq_matches.name("version"),
Some("AMQP librabbitmq version"),
&[],
&[],
@@ -336,7 +336,7 @@ impl PlatformRepository {
info,
) {
let version_str = protocol_matches
- .get(&CaptureKey::ByName("version".to_string()))
+ .name("version")
.unwrap_or_default()
.to_string();
self.add_library(
@@ -360,7 +360,7 @@ impl PlatformRepository {
self.add_library(
&mut libraries,
name,
- matches.get(&CaptureKey::ByName("version".to_string())),
+ matches.name("version"),
None,
&[],
&[],
@@ -386,14 +386,10 @@ impl PlatformRepository {
php_regex!("{^SSL Version => (?<library>[^/]+)/(?<version>.+)$}im"),
info,
) {
- let ssl_library_raw = ssl_matches
- .get(&CaptureKey::ByName("library".to_string()))
- .unwrap_or_default()
- .to_string();
- let ssl_version = ssl_matches
- .get(&CaptureKey::ByName("version".to_string()))
- .unwrap_or_default()
- .to_string();
+ let ssl_library_raw =
+ ssl_matches.name("library").unwrap_or_default().to_string();
+ let ssl_version =
+ ssl_matches.name("version").unwrap_or_default().to_string();
let library = strtolower(&ssl_library_raw);
if library == "openssl" {
let mut is_fips = false;
@@ -421,7 +417,7 @@ impl PlatformRepository {
) {
shortlib = "securetransport".to_string();
let m1 = securetransport_matches
- .get(&CaptureKey::ByIndex(1))
+ .get(1)
.unwrap_or_default()
.to_string();
ssl_lib = format!("curl-{}", m1);
@@ -451,14 +447,10 @@ impl PlatformRepository {
),
info,
) {
- let ssh_library = ssh_matches
- .get(&CaptureKey::ByName("library".to_string()))
- .unwrap_or_default()
- .to_string();
- let ssh_version = ssh_matches
- .get(&CaptureKey::ByName("version".to_string()))
- .unwrap_or_default()
- .to_string();
+ let ssh_library =
+ ssh_matches.name("library").unwrap_or_default().to_string();
+ let ssh_version =
+ ssh_matches.name("version").unwrap_or_default().to_string();
self.add_library(
&mut libraries,
&format!("{}-{}", name, strtolower(&ssh_library)),
@@ -476,7 +468,7 @@ impl PlatformRepository {
self.add_library(
&mut libraries,
&format!("{}-zlib", name),
- zlib_matches.get(&CaptureKey::ByName("version".to_string())),
+ zlib_matches.name("version"),
Some("curl zlib version"),
&[],
&[],
@@ -494,7 +486,7 @@ impl PlatformRepository {
self.add_library(
&mut libraries,
&format!("{}-timelib", name),
- timelib_matches.get(&CaptureKey::ByName("version".to_string())),
+ timelib_matches.name("version"),
Some("date timelib version"),
&[],
&[],
@@ -507,7 +499,7 @@ impl PlatformRepository {
info,
) {
let external = zoneinfo_source_matches
- .get(&CaptureKey::ByName("source".to_string()))
+ .name("source")
.map(|s| s == "external")
.unwrap_or(false);
if let Some(zoneinfo_matches) = Preg::is_match3(
@@ -517,7 +509,7 @@ impl PlatformRepository {
info,
) {
let zoneinfo_version = zoneinfo_matches
- .get(&CaptureKey::ByName("version".to_string()))
+ .name("version")
.unwrap_or_default()
.to_string();
// If the timezonedb is provided by ext/timezonedb, register that version as a replacement
@@ -556,7 +548,7 @@ impl PlatformRepository {
self.add_library(
&mut libraries,
&format!("{}-libmagic", name),
- magic_matches.get(&CaptureKey::ByName("version".to_string())),
+ magic_matches.name("version"),
Some("fileinfo libmagic version"),
&[],
&[],
@@ -586,7 +578,7 @@ impl PlatformRepository {
info,
) {
let libjpeg_version = libjpeg_matches
- .get(&CaptureKey::ByName("version".to_string()))
+ .name("version")
.unwrap_or_default()
.to_string();
let parsed = Version::parse_libjpeg(&libjpeg_version).unwrap_or_default();
@@ -606,7 +598,7 @@ impl PlatformRepository {
self.add_library(
&mut libraries,
&format!("{}-libpng", name),
- libpng_matches.get(&CaptureKey::ByName("version".to_string())),
+ libpng_matches.name("version"),
Some("libpng version for gd"),
&[],
&[],
@@ -620,7 +612,7 @@ impl PlatformRepository {
self.add_library(
&mut libraries,
&format!("{}-freetype", name),
- freetype_matches.get(&CaptureKey::ByName("version".to_string())),
+ freetype_matches.name("version"),
Some("freetype version for gd"),
&[],
&[],
@@ -632,7 +624,7 @@ impl PlatformRepository {
info,
) {
let version_id: i64 = libxpm_matches
- .get(&CaptureKey::ByName("versionId".to_string()))
+ .name("versionId")
.and_then(|s| s.parse().ok())
.unwrap_or(0);
let converted = Version::convert_libxpm_version_id(version_id);
@@ -705,7 +697,7 @@ impl PlatformRepository {
self.add_library(
&mut libraries,
"icu",
- matches.get(&CaptureKey::ByName("version".to_string())),
+ matches.name("version"),
Some(description),
&[],
&[],
@@ -719,7 +711,7 @@ impl PlatformRepository {
info,
) {
let zi_version = zoneinfo_matches
- .get(&CaptureKey::ByName("version".to_string()))
+ .name("version")
.unwrap_or_default()
.to_string();
if let Some(parsed) = Version::parse_zoneinfo_version(&zi_version) {
@@ -781,11 +773,9 @@ impl PlatformRepository {
php_regex!("/^ImageMagick (?<version>[\\d.]+)(?:-(?<patch>\\d+))?/"),
&image_magick_version_str,
) {
- let mut version_built = matches
- .get(&CaptureKey::ByName("version".to_string()))
- .unwrap_or_default()
- .to_string();
- if let Some(patch) = matches.get(&CaptureKey::ByName("patch".to_string())) {
+ let mut version_built =
+ matches.name("version").unwrap_or_default().to_string();
+ if let Some(patch) = matches.name("patch") {
version_built = format!("{}.{}", version_built, patch);
}
@@ -810,12 +800,12 @@ impl PlatformRepository {
Preg::is_match3(php_regex!("/^Vendor Name => (?<vendor>.+)$/im"), info)
{
let version_id: i64 = matches
- .get(&CaptureKey::ByName("versionId".to_string()))
+ .name("versionId")
.and_then(|s| s.parse().ok())
.unwrap_or(0);
let converted = Version::convert_openldap_version_id(version_id);
let vendor = vendor_matches
- .get(&CaptureKey::ByName("vendor".to_string()))
+ .name("vendor")
.unwrap_or_default()
.to_string();
self.add_library(
@@ -864,7 +854,7 @@ impl PlatformRepository {
self.add_library(
&mut libraries,
&format!("{}-libmbfl", name),
- libmbfl_matches.get(&CaptureKey::ByName("version".to_string())),
+ libmbfl_matches.name("version"),
Some("mbstring libmbfl version"),
&[],
&[],
@@ -898,7 +888,7 @@ impl PlatformRepository {
self.add_library(
&mut libraries,
&format!("{}-oniguruma", name),
- oniguruma_matches.get(&CaptureKey::ByName("version".to_string())),
+ oniguruma_matches.name("version"),
Some("mbstring oniguruma version"),
&[],
&[],
@@ -918,7 +908,7 @@ impl PlatformRepository {
self.add_library(
&mut libraries,
&format!("{}-libmemcached", name),
- matches.get(&CaptureKey::ByName("version".to_string())),
+ matches.name("version"),
Some("libmemcached version"),
&[],
&[],
@@ -937,10 +927,7 @@ impl PlatformRepository {
php_regex!("{^(?:OpenSSL|LibreSSL)?\\s*(?<version>\\S+)}i"),
&openssl_text_str,
) {
- let version = matches
- .get(&CaptureKey::ByName("version".to_string()))
- .unwrap_or_default()
- .to_string();
+ let version = matches.name("version").unwrap_or_default().to_string();
let mut is_fips = false;
let parsed_version =
Version::parse_openssl(&version, &mut is_fips).unwrap_or_default();
@@ -979,7 +966,7 @@ impl PlatformRepository {
self.add_library(
&mut libraries,
&format!("{}-unicode", name),
- pcre_unicode_matches.get(&CaptureKey::ByName("version".to_string())),
+ pcre_unicode_matches.name("version"),
Some("PCRE Unicode version support"),
&[],
&[],
@@ -999,7 +986,7 @@ impl PlatformRepository {
self.add_library(
&mut libraries,
&format!("{}-mysqlnd", name),
- matches.get(&CaptureKey::ByName("version".to_string())),
+ matches.name("version"),
Some(&format!("mysqlnd library version for {}", name)),
&[],
&[],
@@ -1017,7 +1004,7 @@ impl PlatformRepository {
self.add_library(
&mut libraries,
&format!("{}-libmongoc", name),
- libmongoc_matches.get(&CaptureKey::ByName("version".to_string())),
+ libmongoc_matches.name("version"),
Some("libmongoc version of mongodb"),
&[],
&[],
@@ -1031,7 +1018,7 @@ impl PlatformRepository {
self.add_library(
&mut libraries,
&format!("{}-libbson", name),
- libbson_matches.get(&CaptureKey::ByName("version".to_string())),
+ libbson_matches.name("version"),
Some("libbson version of mongodb"),
&[],
&[],
@@ -1065,7 +1052,7 @@ impl PlatformRepository {
self.add_library(
&mut libraries,
&format!("{}-libpq", name),
- matches.get(&CaptureKey::ByName("version".to_string())),
+ matches.name("version"),
Some(&format!("libpq for {}", name)),
&[],
&[],
@@ -1084,7 +1071,7 @@ impl PlatformRepository {
self.add_library(
&mut libraries,
&format!("{}-libpq", name),
- matches.get(&CaptureKey::ByName("version".to_string())),
+ matches.name("version"),
Some(&format!("libpq for {}", name)),
&[],
&[],
@@ -1104,7 +1091,7 @@ impl PlatformRepository {
self.add_library(
&mut libraries,
&format!("{}-libpq", name),
- matches.get(&CaptureKey::ByName("linked".to_string())),
+ matches.name("linked"),
Some(&format!("libpq for {}", name)),
&[],
&[],
@@ -1177,7 +1164,7 @@ impl PlatformRepository {
self.add_library(
&mut libraries,
&format!("{}-sqlite", name),
- matches.get(&CaptureKey::ByName("version".to_string())),
+ matches.name("version"),
None,
&[],
&[],
@@ -1194,7 +1181,7 @@ impl PlatformRepository {
self.add_library(
&mut libraries,
&format!("{}-libssh2", name),
- matches.get(&CaptureKey::ByName("version".to_string())),
+ matches.name("version"),
None,
&[],
&[],
@@ -1228,7 +1215,7 @@ impl PlatformRepository {
self.add_library(
&mut libraries,
"libxslt-libxml",
- matches.get(&CaptureKey::ByName("version".to_string())),
+ matches.name("version"),
Some("libxml version libxslt is compiled against"),
&[],
&[],
@@ -1245,7 +1232,7 @@ impl PlatformRepository {
self.add_library(
&mut libraries,
&format!("{}-libyaml", name),
- matches.get(&CaptureKey::ByName("version".to_string())),
+ matches.name("version"),
Some("libyaml version of yaml"),
&[],
&[],
@@ -1298,7 +1285,7 @@ impl PlatformRepository {
self.add_library(
&mut libraries,
name,
- matches.get(&CaptureKey::ByName("version".to_string())),
+ matches.name("version"),
None,
&[],
&[],
@@ -1494,10 +1481,7 @@ impl PlatformRepository {
php_regex!("{^(\\d+\\.\\d+\\.\\d+(?:\\.\\d+)?)}"),
&pretty_version,
) {
- pretty_version = m
- .get(&CaptureKey::ByIndex(1))
- .unwrap_or_default()
- .to_string();
+ pretty_version = m.get(1).unwrap_or_default().to_string();
} else {
pretty_version = "0".to_string();
}
diff --git a/crates/shirabe/src/repository/vcs/forgejo_driver.rs b/crates/shirabe/src/repository/vcs/forgejo_driver.rs
index 8aa72a6c..8047602a 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::Preg;
use shirabe_php_shim::Catch as _;
use shirabe_php_shim::{
PhpMixed, RuntimeException, base64_decode, explode, extension_loaded, php_regex, urlencode,
@@ -585,7 +585,7 @@ impl ForgejoDriver {
let links = explode(",", &header);
for link in links {
if let Some(m) = Preg::match3(php_regex!(r#"{<(.+?)>; *rel="next"}"#), &link)
- && let Some(url) = m.get(&CaptureKey::ByIndex(1))
+ && let Some(url) = m.get(1)
{
return Some(url.to_string());
}
diff --git a/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs b/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs
index e053cadf..5f83b4e1 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::Preg;
use shirabe_php_shim::Catch as _;
use shirabe_php_shim::{
InvalidArgumentException, LogicException, PhpMixed, RuntimeException, array_key_exists,
@@ -95,14 +95,8 @@ impl GitBitbucketDriver {
.into());
};
- self.owner = m
- .get(&CaptureKey::ByIndex(1))
- .unwrap_or_default()
- .to_string();
- self.repository = m
- .get(&CaptureKey::ByIndex(2))
- .unwrap_or_default()
- .to_string();
+ self.owner = m.get(1).unwrap_or_default().to_string();
+ self.repository = m.get(2).unwrap_or_default().to_string();
self.inner.origin_url = "bitbucket.org".to_string();
self.inner.cache = Some(Cache::new(
self.inner.io.clone(),
diff --git a/crates/shirabe/src/repository/vcs/git_driver.rs b/crates/shirabe/src/repository/vcs/git_driver.rs
index bd56766b..c224e8e6 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::Preg;
use shirabe_php_shim::Catch as _;
use shirabe_php_shim::{
InvalidArgumentException, RuntimeException, dirname, is_dir, is_writable, realpath,
@@ -200,7 +200,7 @@ impl GitDriver {
for branch in &branches {
if !branch.is_empty()
&& let Some(caps) = Preg::match3(php_regex!(r"{^\* +(\S+)}"), branch)
- && let Some(name) = caps.get(&CaptureKey::ByIndex(1))
+ && let Some(name) = caps.get(1)
{
self.root_identifier = Some(name.to_string());
break;
@@ -313,10 +313,7 @@ impl GitDriver {
php_regex!(r"{^([a-f0-9]{40}) refs/tags/(\S+?)(\^\{\})?$}"),
&tag,
)
- && let (Some(hash), Some(name)) = (
- caps.get(&CaptureKey::ByIndex(1)),
- caps.get(&CaptureKey::ByIndex(2)),
- )
+ && let (Some(hash), Some(name)) = (caps.get(1), caps.get(2))
{
self.tags
.as_mut()
@@ -352,10 +349,7 @@ impl GitDriver {
php_regex!(r"{^(?:\* )? *(\S+) *([a-f0-9]+)(?: .*)?$}"),
&branch,
)
- && let (Some(name), Some(hash)) = (
- caps.get(&CaptureKey::ByIndex(1)),
- caps.get(&CaptureKey::ByIndex(2)),
- )
+ && let (Some(name), Some(hash)) = (caps.get(1), caps.get(2))
&& !name.starts_with('-')
{
branches.insert(name.to_string(), hash.to_string());
diff --git a/crates/shirabe/src/repository/vcs/github_driver.rs b/crates/shirabe/src/repository/vcs/github_driver.rs
index 08561171..11bb9503 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::Preg;
use shirabe_php_shim::Catch as _;
use shirabe_php_shim::{
InvalidArgumentException, PhpMixed, RuntimeException, array_diff, array_map,
@@ -83,25 +83,14 @@ impl GitHubDriver {
.into());
};
- self.owner = match_
- .get(&CaptureKey::ByIndex(3))
- .unwrap_or_default()
- .to_string();
- self.repository = match_
- .get(&CaptureKey::ByIndex(4))
- .unwrap_or_default()
- .to_string();
+ self.owner = match_.get(3).unwrap_or_default().to_string();
+ self.repository = match_.get(4).unwrap_or_default().to_string();
self.inner.origin_url = strtolower(
&match_
- .get(&CaptureKey::ByIndex(1))
+ .get(1)
.filter(|s| !s.is_empty())
.map(str::to_string)
- .unwrap_or_else(|| {
- match_
- .get(&CaptureKey::ByIndex(2))
- .unwrap_or_default()
- .to_string()
- }),
+ .unwrap_or_else(|| match_.get(2).unwrap_or_default().to_string()),
);
if self.inner.origin_url == "www.github.com" {
self.inner.origin_url = "github.com".to_string();
@@ -494,23 +483,14 @@ impl GitHubDriver {
for line in preg_split(php_regex!(r"{\r?\n}"), &funding) {
let line = trim(&line, None);
if let Some(m) = Preg::is_match3(php_regex!(r"{^(\w+)\s*:\s*(.+)$}"), &line) {
- let g1 = m
- .get(&CaptureKey::ByIndex(1))
- .unwrap_or_default()
- .to_string();
- let g2 = m
- .get(&CaptureKey::ByIndex(2))
- .unwrap_or_default()
- .to_string();
+ let g1 = m.get(1).unwrap_or_default().to_string();
+ let g2 = m.get(2).unwrap_or_default().to_string();
if g2 == "[" {
key = Some(g1);
continue;
}
if let Some(m2) = Preg::is_match3(php_regex!(r"{^\[(.*?)\](?:\s*#.*)?$}"), &g2) {
- let inner = m2
- .get(&CaptureKey::ByIndex(1))
- .unwrap_or_default()
- .to_string();
+ let inner = m2.get(1).unwrap_or_default().to_string();
for item in array_map(
|s: &String| trim(s, None),
&preg_split(php_regex!(r#"{[\'\"]?\s*,\s*[\'\"]?}"#), &inner),
@@ -530,20 +510,13 @@ impl GitHubDriver {
entry.insert("type".to_string(), PhpMixed::String(g1.clone()));
entry.insert(
"url".to_string(),
- PhpMixed::String(trim(
- m2.get(&CaptureKey::ByIndex(1)).unwrap_or_default(),
- Some("\"' "),
- )),
+ PhpMixed::String(trim(m2.get(1).unwrap_or_default(), Some("\"' "))),
);
result.push(entry);
}
key = None;
} else if let Some(m) = Preg::is_match3(php_regex!(r"{^(\w+)\s*:\s*#\s*$}"), &line) {
- key = Some(
- m.get(&CaptureKey::ByIndex(1))
- .unwrap_or_default()
- .to_string(),
- );
+ key = Some(m.get(1).unwrap_or_default().to_string());
} else if key.is_some()
&& let Some(m) = Preg::is_match3(php_regex!(r"{^-\s*(.+)(?:\s+#.*)?$}"), &line)
.or_else(|| Preg::is_match3(php_regex!(r"{^(.+),(?:\s*#.*)?$}"), &line))
@@ -555,10 +528,7 @@ impl GitHubDriver {
);
entry.insert(
"url".to_string(),
- PhpMixed::String(trim(
- m.get(&CaptureKey::ByIndex(1)).unwrap_or_default(),
- Some("\"' "),
- )),
+ PhpMixed::String(trim(m.get(1).unwrap_or_default(), Some("\"' "))),
);
result.push(entry);
} else if key.is_some() && line == "]" {
@@ -948,15 +918,10 @@ impl GitHubDriver {
};
let origin_url = matches
- .get(&CaptureKey::ByIndex(2))
+ .get(2)
.filter(|s| !s.is_empty())
.map(str::to_string)
- .unwrap_or_else(|| {
- matches
- .get(&CaptureKey::ByIndex(3))
- .unwrap_or_default()
- .to_string()
- });
+ .unwrap_or_else(|| matches.get(3).unwrap_or_default().to_string());
if !in_array_loose(
strtolower(&Preg::replace(php_regex!(r"{^www\.}i"), "", &origin_url)),
config.borrow().get("github-domains").values(),
@@ -1285,11 +1250,7 @@ impl GitHubDriver {
let links = explode(",", &header);
for link in &links {
if let Some(m) = Preg::is_match3(php_regex!(r#"{<(.+?)>; *rel="next"}"#), link) {
- return Some(
- m.get(&CaptureKey::ByIndex(1))
- .unwrap_or_default()
- .to_string(),
- );
+ return Some(m.get(1).unwrap_or_default().to_string());
}
}
diff --git a/crates/shirabe/src/repository/vcs/gitlab_driver.rs b/crates/shirabe/src/repository/vcs/gitlab_driver.rs
index 5494feed..30c3f7ae 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::Preg;
use shirabe_php_shim::Catch as _;
use shirabe_php_shim::{
InvalidArgumentException, LogicException, PhpMixed, RuntimeException, array_search_mixed,
@@ -90,27 +90,14 @@ impl GitLabDriver {
};
let guessed_domain = match_
- .get(&CaptureKey::ByName("domain".to_string()))
+ .name("domain")
.filter(|s| !s.is_empty())
.map(str::to_string)
- .unwrap_or_else(|| {
- match_
- .get(&CaptureKey::ByName("domain2".to_string()))
- .unwrap_or_default()
- .to_string()
- });
+ .unwrap_or_else(|| match_.name("domain2").unwrap_or_default().to_string());
let configured_domains = self.inner.config.borrow_mut().get("gitlab-domains");
- let mut url_parts: Vec<String> = explode(
- "/",
- match_
- .get(&CaptureKey::ByName("parts".to_string()))
- .unwrap_or_default(),
- );
+ let mut url_parts: Vec<String> = explode("/", match_.name("parts").unwrap_or_default());
- let scheme_match = match_
- .get(&CaptureKey::ByName("scheme".to_string()))
- .unwrap_or_default()
- .to_string();
+ let scheme_match = match_.name("scheme").unwrap_or_default().to_string();
self.scheme = if matches!(scheme_match.as_str(), "https" | "http") {
scheme_match
} else if self
@@ -124,9 +111,7 @@ impl GitLabDriver {
} else {
"https".to_string()
};
- let port = match_
- .get(&CaptureKey::ByName("port".to_string()))
- .map(str::to_string);
+ let port = match_.name("port").map(str::to_string);
let origin =
Self::determine_origin(&configured_domains, guessed_domain, &mut url_parts, port);
let origin = match origin {
@@ -170,9 +155,7 @@ impl GitLabDriver {
self.repository = Preg::replace(
php_regex!(r"#(\.git)$#"),
"",
- match_
- .get(&CaptureKey::ByName("repo".to_string()))
- .unwrap_or_default(),
+ match_.name("repo").unwrap_or_default(),
);
self.inner.cache = Some(Cache::new(
@@ -948,34 +931,19 @@ impl GitLabDriver {
return Ok(false);
};
- let scheme = match_
- .get(&CaptureKey::ByName("scheme".to_string()))
- .unwrap_or_default()
- .to_string();
+ let scheme = match_.name("scheme").unwrap_or_default().to_string();
let guessed_domain = match_
- .get(&CaptureKey::ByName("domain".to_string()))
+ .name("domain")
.filter(|s| !s.is_empty())
.map(str::to_string)
- .unwrap_or_else(|| {
- match_
- .get(&CaptureKey::ByName("domain2".to_string()))
- .unwrap_or_default()
- .to_string()
- });
- let mut url_parts: Vec<String> = explode(
- "/",
- match_
- .get(&CaptureKey::ByName("parts".to_string()))
- .unwrap_or_default(),
- );
+ .unwrap_or_else(|| match_.name("domain2").unwrap_or_default().to_string());
+ let mut url_parts: Vec<String> = explode("/", match_.name("parts").unwrap_or_default());
if Self::determine_origin(
&config.borrow().get("gitlab-domains"),
guessed_domain,
&mut url_parts,
- match_
- .get(&CaptureKey::ByName("port".to_string()))
- .map(str::to_string),
+ match_.name("port").map(str::to_string),
)
.is_none()
{
@@ -1011,12 +979,7 @@ impl GitLabDriver {
let links = explode(",", &header);
for link in &links {
if let Some(match_) = Preg::is_match3(php_regex!(r#"{<(.+?)>; *rel="next"}"#), link) {
- return Some(
- match_
- .get(&CaptureKey::ByIndex(1))
- .unwrap_or_default()
- .to_string(),
- );
+ return Some(match_.get(1).unwrap_or_default().to_string());
}
}
diff --git a/crates/shirabe/src/repository/vcs/hg_driver.rs b/crates/shirabe/src/repository/vcs/hg_driver.rs
index aae9c7cb..120b8ea8 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::Preg;
use shirabe_php_shim::Catch as _;
use shirabe_php_shim::{PhpMixed, RuntimeException, dirname, is_dir, is_writable, php_regex};
@@ -236,12 +236,8 @@ impl HgDriver {
&& let Some(m) = Preg::match3(php_regex!(r"(^([^\s]+)\s+\d+:(.*)$)"), &tag)
{
tags.insert(
- m.get(&CaptureKey::ByIndex(1))
- .unwrap_or_default()
- .to_string(),
- m.get(&CaptureKey::ByIndex(2))
- .unwrap_or_default()
- .to_string(),
+ m.get(1).unwrap_or_default().to_string(),
+ m.get(2).unwrap_or_default().to_string(),
);
}
}
@@ -269,17 +265,9 @@ impl HgDriver {
&& let Some(m) =
Preg::match3(php_regex!(r"(^([^\s]+)\s+\d+:([a-f0-9]+))"), &branch)
{
- let name = m
- .get(&CaptureKey::ByIndex(1))
- .unwrap_or_default()
- .to_string();
+ let name = m.get(1).unwrap_or_default().to_string();
if !name.starts_with('-') {
- branches.insert(
- name,
- m.get(&CaptureKey::ByIndex(2))
- .unwrap_or_default()
- .to_string(),
- );
+ branches.insert(name, m.get(2).unwrap_or_default().to_string());
}
}
}
@@ -295,17 +283,9 @@ impl HgDriver {
&& let Some(m) =
Preg::match3(php_regex!(r"(^(?:[\s*]*)([^\s]+)\s+\d+:(.*)$)"), &branch)
{
- let name = m
- .get(&CaptureKey::ByIndex(1))
- .unwrap_or_default()
- .to_string();
+ let name = m.get(1).unwrap_or_default().to_string();
if !name.starts_with('-') {
- bookmarks.insert(
- name,
- m.get(&CaptureKey::ByIndex(2))
- .unwrap_or_default()
- .to_string(),
- );
+ bookmarks.insert(name, m.get(2).unwrap_or_default().to_string());
}
}
}
diff --git a/crates/shirabe/src/repository/vcs/svn_driver.rs b/crates/shirabe/src/repository/vcs/svn_driver.rs
index bdd7f021..6fb987a4 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::Preg;
use shirabe_php_shim::Catch as _;
use shirabe_php_shim::{
PhpMixed, RuntimeException, php_regex, stripos, strrpos, strtr, substr, trim,
@@ -259,14 +259,9 @@ impl SvnDriver {
let (path, rev) = if let Some(m) =
Preg::is_match3(php_regex!(r"{^(.+?)(@\d+)?/$}"), &identifier)
- && let Some(rev) = m.get(&CaptureKey::ByIndex(2))
+ && let Some(rev) = m.get(2)
{
- (
- m.get(&CaptureKey::ByIndex(1))
- .unwrap_or_default()
- .to_string(),
- rev.to_string(),
- )
+ (m.get(1).unwrap_or_default().to_string(), rev.to_string())
} else {
(identifier, String::new())
};
@@ -298,14 +293,9 @@ impl SvnDriver {
let (path, rev) = if let Some(m) =
Preg::is_match3(php_regex!(r"{^(.+?)(@\d+)?/$}"), &identifier)
- && let Some(rev) = m.get(&CaptureKey::ByIndex(2))
+ && let Some(rev) = m.get(2)
{
- (
- m.get(&CaptureKey::ByIndex(1))
- .unwrap_or_default()
- .to_string(),
- rev.to_string(),
- )
+ (m.get(1).unwrap_or_default().to_string(), rev.to_string())
} else {
(identifier, String::new())
};
@@ -319,10 +309,7 @@ impl SvnDriver {
&& let Some(m) =
Preg::is_match3(php_regex!(r"{^Last Changed Date: ([^(]+)}"), &line)
{
- let date_str = m
- .get(&CaptureKey::ByIndex(1))
- .unwrap_or_default()
- .to_string();
+ let date_str = m.get(1).unwrap_or_default().to_string();
return Ok(shirabe_php_shim::date_create::<Utc>(date_str.trim())
.ok()
.map(|d| d.fixed_offset()));
@@ -350,14 +337,8 @@ impl SvnDriver {
&& let Some(m) =
Preg::is_match3(php_regex!(r"{^\s*(\S+).*?(\S+)\s*$}"), &line)
{
- let rev: i64 = m
- .get(&CaptureKey::ByIndex(1))
- .and_then(|s| s.parse().ok())
- .unwrap_or(0);
- let path = m
- .get(&CaptureKey::ByIndex(2))
- .unwrap_or_default()
- .to_string();
+ let rev: i64 = m.get(1).and_then(|s| s.parse().ok()).unwrap_or(0);
+ let path = m.get(2).unwrap_or_default().to_string();
if path == "./" {
last_rev = rev;
} else {
@@ -399,14 +380,8 @@ impl SvnDriver {
&& let Some(m) =
Preg::is_match3(php_regex!(r"{^\s*(\S+).*?(\S+)\s*$}"), &line)
{
- let rev: i64 = m
- .get(&CaptureKey::ByIndex(1))
- .and_then(|s| s.parse().ok())
- .unwrap_or(0);
- let path = m
- .get(&CaptureKey::ByIndex(2))
- .unwrap_or_default()
- .to_string();
+ let rev: i64 = m.get(1).and_then(|s| s.parse().ok()).unwrap_or(0);
+ let path = m.get(2).unwrap_or_default().to_string();
if path == "./" {
let identifier = self.build_identifier(
&format!("/{}", self.trunk_path.clone().unwrap_or_default()),
@@ -440,14 +415,8 @@ impl SvnDriver {
&& let Some(m) =
Preg::is_match3(php_regex!(r"{^\s*(\S+).*?(\S+)\s*$}"), &line)
{
- let rev: i64 = m
- .get(&CaptureKey::ByIndex(1))
- .and_then(|s| s.parse().ok())
- .unwrap_or(0);
- let path = m
- .get(&CaptureKey::ByIndex(2))
- .unwrap_or_default()
- .to_string();
+ let rev: i64 = m.get(1).and_then(|s| s.parse().ok()).unwrap_or(0);
+ let path = m.get(2).unwrap_or_default().to_string();
if path == "./" {
last_rev = rev;
} else {
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)
diff --git a/crates/shirabe/tests/all_functional_test.rs b/crates/shirabe/tests/all_functional_test.rs
index ad075ad6..d947a054 100644
--- a/crates/shirabe/tests/all_functional_test.rs
+++ b/crates/shirabe/tests/all_functional_test.rs
@@ -9,7 +9,7 @@ use indexmap::IndexMap;
use serial_test::serial;
use shirabe::util::filesystem::Filesystem;
use shirabe_pcre::preg::Preg;
-use shirabe_php_shim::{CaptureKey, PhpMixed, intval, php_regex, preg_split_delim_capture};
+use shirabe_php_shim::{PhpMixed, intval, php_regex, preg_split_delim_capture};
use std::path::{Path, PathBuf};
/// ref: AllFunctionalTest's `$oldcwd` / `$testDir` instance state plus its `setUp`/`tearDown`.
@@ -144,11 +144,11 @@ fn expect_matches(expected: &str, output: &str) {
let Some(m) = Preg::is_match3(php_regex!("{%(.+?)%}"), &expected[i..]) else {
panic!("Failed to match %...% in {}", &expected[i..]);
};
- let regex = m.get(&CaptureKey::ByIndex(1)).map(str::to_string).unwrap();
+ let regex = m.get(1).map(str::to_string).unwrap();
let pattern = format!("{{{}}}", regex);
if let Some(m) = Preg::is_match3(&pattern, &output[j..]) {
- let full = m.get(&CaptureKey::ByIndex(0)).map(str::to_string).unwrap();
+ let full = m.get(0).map(str::to_string).unwrap();
i += regex.len() + 2;
j += full.len();
continue;