aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/repository
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-08-18 01:57:02 +0900
committernsfisis <nsfisis@gmail.com>2026-08-18 01:57:02 +0900
commit530d085d4f3e19f94ac3cf8f8ac3b17000214b2e (patch)
treeb4de2c2443e2bb2cfc692454ac284dc1d2313e59 /crates/shirabe/src/repository
parent0caac63bacefb9a1f62848636d47fca07f592bba (diff)
downloadphp-shirabe-530d085d4f3e19f94ac3cf8f8ac3b17000214b2e.tar.gz
php-shirabe-530d085d4f3e19f94ac3cf8f8ac3b17000214b2e.tar.zst
php-shirabe-530d085d4f3e19f94ac3cf8f8ac3b17000214b2e.zip
refactor(pcre): inline Preg into its call sites and drop the crate
Preg had shed everything it owned: after the last few rounds its methods were one-line forwards to the shim's preg_*(), differing only in a default argument or a wrapper the caller unwrapped anyway. The 460 call sites now name the shim function, and shirabe-pcre is gone from the workspace along with its LICENSE entry. The forwards expand as they read: isMatch becomes preg_match2(.., 0).is_some() (is_none() where PHP negates it), isMatch3 and match3 drop the .is_some(), matchAll counts through preg_match_all2(..).occurrence_count(), and replace4/replace5 spell out the limit and count arguments preg_replace2 takes. Callbacks are the one place the shapes differ: preg_replace_callback carries an error out of the callback, so the fourteen infallible closures wrap their result in Ok() and expect() it back. Config::process() is the fifteenth, and it drops the `error` cell it captured to smuggle a failure past a closure that could only return a String. The `?` in the closure now carries it, which is what the PHP does -- a throw from the callback leaves preg_replace_callback at the failing match rather than running the remaining replacements and reporting the last error. The module doc that explained why composer/pcre's exceptions and *StrictGroups() variants have no counterpart moves to the shim's preg module, where the functions it describes live. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/repository')
-rw-r--r--crates/shirabe/src/repository/array_repository.rs11
-rw-r--r--crates/shirabe/src/repository/composer_repository.rs29
-rw-r--r--crates/shirabe/src/repository/filter_repository.rs7
-rw-r--r--crates/shirabe/src/repository/package_repository.rs5
-rw-r--r--crates/shirabe/src/repository/path_repository.rs7
-rw-r--r--crates/shirabe/src/repository/platform_repository.rs150
-rw-r--r--crates/shirabe/src/repository/repository_factory.rs7
-rw-r--r--crates/shirabe/src/repository/vcs/forgejo_driver.rs6
-rw-r--r--crates/shirabe/src/repository/vcs/fossil_driver.rs17
-rw-r--r--crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs16
-rw-r--r--crates/shirabe/src/repository/vcs/git_driver.rs36
-rw-r--r--crates/shirabe/src/repository/vcs/github_driver.rs30
-rw-r--r--crates/shirabe/src/repository/vcs/gitlab_driver.rs15
-rw-r--r--crates/shirabe/src/repository/vcs/hg_driver.rs20
-rw-r--r--crates/shirabe/src/repository/vcs/perforce_driver.rs7
-rw-r--r--crates/shirabe/src/repository/vcs/svn_driver.rs23
-rw-r--r--crates/shirabe/src/repository/vcs/vcs_driver.rs9
-rw-r--r--crates/shirabe/src/repository/vcs_repository.rs14
18 files changed, 235 insertions, 174 deletions
diff --git a/crates/shirabe/src/repository/array_repository.rs b/crates/shirabe/src/repository/array_repository.rs
index 0f3dc237..2e364d0e 100644
--- a/crates/shirabe/src/repository/array_repository.rs
+++ b/crates/shirabe/src/repository/array_repository.rs
@@ -12,8 +12,7 @@ use crate::repository::{
RepositoryInterfaceHandle, RepositoryInterfaceWeakHandle, SearchResult,
};
use indexmap::IndexMap;
-use shirabe_pcre::Preg;
-use shirabe_php_shim::{implode, php_regex, preg_quote, preg_split, strtolower};
+use shirabe_php_shim::{implode, php_regex, preg_match2, preg_quote, preg_split, strtolower};
use shirabe_semver::constraint::AnyConstraint;
use shirabe_semver::constraint::SimpleConstraint;
use std::rc::Weak;
@@ -358,7 +357,7 @@ impl RepositoryInterface for ArrayRepository {
let fulltext_match = mode == crate::repository::SEARCH_FULLTEXT
&& complete.is_some()
- && Preg::is_match(
+ && preg_match2(
&regex,
&format!(
"{} {}",
@@ -369,9 +368,11 @@ impl RepositoryInterface for ArrayRepository {
.get_description()
.unwrap_or_default()
),
- );
+ 0,
+ )
+ .is_some();
- if Preg::is_match(&regex, &name) || fulltext_match {
+ if preg_match2(&regex, &name, 0).is_some() || fulltext_match {
if mode == crate::repository::SEARCH_VENDOR {
matches.insert(
name.clone(),
diff --git a/crates/shirabe/src/repository/composer_repository.rs b/crates/shirabe/src/repository/composer_repository.rs
index 8970a227..9f6e6bf8 100644
--- a/crates/shirabe/src/repository/composer_repository.rs
+++ b/crates/shirabe/src/repository/composer_repository.rs
@@ -37,14 +37,13 @@ use futures::StreamExt;
use futures::stream::FuturesOrdered;
use indexmap::IndexMap;
use shirabe_metadata_minifier::MetadataMinifier;
-use shirabe_pcre::Preg;
-use shirabe_php_shim::Catch as _;
use shirabe_php_shim::{
AnyThrowable, CmpOp, InvalidArgumentException, LogicException, PHP_EOL, PhpMixed,
RuntimeException, UnexpectedValueException, extension_loaded, hash, http_build_query_mixed,
json_decode_assoc, parse_url, php_regex, preg_split, realpath, strtolower, strtr, urlencode,
var_export,
};
+use shirabe_php_shim::{Catch as _, preg_grep, preg_match2, preg_replace};
use shirabe_semver::CompilingMatcher;
use shirabe_semver::constraint::AnyConstraint;
use shirabe_semver::constraint::MatchAllConstraint;
@@ -162,7 +161,7 @@ impl ComposerRepository {
.and_then(|v| v.as_string())
.unwrap_or("")
.to_string();
- if !Preg::is_match(php_regex!(r"{^[\w.]+\??://}"), &url_str) {
+ if preg_match2(php_regex!(r"{^[\w.]+\??://}"), &url_str, 0).is_none() {
if let Some(local_file_path) = realpath(&url_str) {
// it is a local path, add file scheme
repo_config.insert(
@@ -245,9 +244,10 @@ impl ComposerRepository {
.to_string();
// force url for packagist.org to repo.packagist.org
- if let Some(match_packagist) = Preg::is_match3(
+ if let Some(match_packagist) = preg_match2(
php_regex!(r"{^(?P<proto>https?)://packagist\.org/?$}i"),
&url,
+ 0,
) {
let proto = match_packagist
.name("proto")
@@ -257,14 +257,14 @@ impl ComposerRepository {
}
let base_url_trimmed =
- Preg::replace(php_regex!(r"{(?:/[^/\\]+\.json)?(?:[?#].*)?$}"), "", &url);
+ preg_replace(php_regex!(r"{(?:/[^/\\]+\.json)?(?:[?#].*)?$}"), "", &url);
let base_url = base_url_trimmed.trim_end_matches('/').to_string();
assert!(!base_url.is_empty());
let cache_dir = format!(
"{}/{}",
config.get("cache-repo-dir").as_string().unwrap_or(""),
- Preg::replace(r"{[^a-z0-9.]}i", "-", &Url::sanitize(url.clone())),
+ preg_replace(r"{[^a-z0-9.]}i", "-", &Url::sanitize(url.clone())),
);
let cache = Cache::new(io.clone(), &cache_dir, Some("a-z0-9.$~"), None, false);
let version_parser = VersionParser::new();
@@ -429,7 +429,7 @@ impl ComposerRepository {
};
let filter_results = |results: Vec<String>| -> anyhow::Result<Vec<String>> {
match &package_filter_regex {
- Some(regex) => Ok(Preg::grep(regex, results).collect()),
+ Some(regex) => Ok(preg_grep(regex, results).collect()),
None => Ok(results),
}
};
@@ -767,7 +767,7 @@ impl ComposerRepository {
let regex = format!("{{(?:{})}}i", parts.join("|"));
let vendor_names = self.get_vendor_names()?;
- for name in Preg::grep(&regex, vendor_names) {
+ for name in preg_grep(&regex, vendor_names) {
let mut entry = IndexMap::new();
entry.insert("name".to_string(), PhpMixed::String(name));
entry.insert("description".to_string(), PhpMixed::String(String::new()));
@@ -779,9 +779,10 @@ impl ComposerRepository {
if self.has_providers()? || self.lazy_providers_url.is_some() {
// optimize search for "^foo/bar" where at least "^foo/" is present by loading this directly from the listUrl if present
- if let Some(match_groups) = Preg::is_match3(
+ if let Some(match_groups) = preg_match2(
php_regex!(r"{^\^(?P<query>(?P<vendor>[a-z0-9_.-]+)/[a-z0-9_.-]*)\*?$}i"),
&query,
+ 0,
) && let Some(list_url) = self.list_url.as_ref()
{
let q = match_groups.name("query").unwrap_or_default().to_string();
@@ -823,7 +824,7 @@ impl ComposerRepository {
let regex = format!("{{(?:{})}}i", parts.join("|"));
let package_names = self.get_package_names(None)?;
- for name in Preg::grep(&regex, package_names) {
+ for name in preg_grep(&regex, package_names) {
let mut entry = IndexMap::new();
entry.insert("name".to_string(), PhpMixed::String(name));
entry.insert("description".to_string(), PhpMixed::String(String::new()));
@@ -1735,7 +1736,7 @@ impl ComposerRepository {
.into_iter()
.filter_map(|(name, constraint)| {
let name = strtolower(&name);
- let real_name = Preg::replace(php_regex!(r"{~dev$}"), "", &name);
+ let real_name = preg_replace(php_regex!(r"{~dev$}"), "", &name);
// skip platform packages, root package and composer-plugin-api
if PlatformRepository::is_platform_package(&real_name) || real_name == "__root__" {
None
@@ -2420,7 +2421,7 @@ impl ComposerRepository {
}
if url.starts_with('/') {
- if let Some(matches) = Preg::is_match3(php_regex!(r"{^[^:]++://[^/]*+}"), &self.url) {
+ if let Some(matches) = preg_match2(php_regex!(r"{^[^:]++://[^/]*+}"), &self.url, 0) {
return Ok(format!("{}{}", matches.get(0).unwrap_or_default(), url));
}
@@ -2709,7 +2710,7 @@ impl ComposerRepository {
// url-encode $ signs in URLs as bad proxies choke on them
if let Some(pos) = filename.find('$')
&& pos > 0
- && Preg::is_match(php_regex!(r"{^https?://}i"), &filename)
+ && preg_match2(php_regex!(r"{^https?://}i"), &filename, 0).is_some()
{
filename = format!("{}%24{}", &filename[..pos], &filename[pos + 1..]);
}
@@ -3308,7 +3309,7 @@ impl ComposerRepository {
if let Some(ref patterns) = self.available_package_patterns {
for provider_regex in patterns.iter() {
- if Preg::is_match(provider_regex, name) {
+ if preg_match2(provider_regex, name, 0).is_some() {
return Ok(true);
}
}
diff --git a/crates/shirabe/src/repository/filter_repository.rs b/crates/shirabe/src/repository/filter_repository.rs
index 0f6f7526..3b36a969 100644
--- a/crates/shirabe/src/repository/filter_repository.rs
+++ b/crates/shirabe/src/repository/filter_repository.rs
@@ -9,8 +9,7 @@ use crate::repository::{
RepositoryInterfaceHandle, SearchResult,
};
use indexmap::IndexMap;
-use shirabe_pcre::Preg;
-use shirabe_php_shim::{InvalidArgumentException, PhpMixed};
+use shirabe_php_shim::{InvalidArgumentException, PhpMixed, preg_match2};
use shirabe_semver::constraint::AnyConstraint;
#[derive(Debug)]
@@ -124,14 +123,14 @@ impl FilterRepository {
}
if let Some(only) = &self.only {
- return Preg::is_match(only, name);
+ return preg_match2(only, name, 0).is_some();
}
if self.exclude.is_none() {
return true;
}
- !Preg::is_match(self.exclude.as_ref().unwrap(), name)
+ preg_match2(self.exclude.as_ref().unwrap(), name, 0).is_none()
}
}
diff --git a/crates/shirabe/src/repository/package_repository.rs b/crates/shirabe/src/repository/package_repository.rs
index 1016ee7f..ef1eb59f 100644
--- a/crates/shirabe/src/repository/package_repository.rs
+++ b/crates/shirabe/src/repository/package_repository.rs
@@ -15,8 +15,7 @@ use crate::repository::{
RepositoryInterface, SearchResult, SecurityAdvisoryResult,
};
use indexmap::IndexMap;
-use shirabe_pcre::Preg;
-use shirabe_php_shim::{PhpMixed, RuntimeException, php_regex, var_export};
+use shirabe_php_shim::{PhpMixed, RuntimeException, php_regex, preg_replace, var_export};
use shirabe_semver::constraint::AnyConstraint;
#[derive(Debug)]
@@ -85,7 +84,7 @@ impl PackageRepository {
// PHP: parent::getRepoName() counts through the late-bound $this->initialize(),
// which resolves to PackageRepository::initialize (loading the config packages).
self.ensure_initialized()?;
- Ok(Preg::replace(
+ Ok(preg_replace(
php_regex!(r"{^array }"),
"package ",
&self.inner.get_repo_name()?,
diff --git a/crates/shirabe/src/repository/path_repository.rs b/crates/shirabe/src/repository/path_repository.rs
index 680911eb..77cc0222 100644
--- a/crates/shirabe/src/repository/path_repository.rs
+++ b/crates/shirabe/src/repository/path_repository.rs
@@ -23,10 +23,9 @@ use crate::util::Platform;
use crate::util::ProcessExecutor;
use crate::util::Url;
use indexmap::IndexMap;
-use shirabe_pcre::Preg;
use shirabe_php_shim::{
GLOB_BRACE, GLOB_MARK, GLOB_ONLYDIR, PhpMixed, RuntimeException, defined, file_exists,
- file_get_contents, glob_with_flags, hash, php_regex, realpath, serialize,
+ file_get_contents, glob_with_flags, hash, php_regex, preg_match2, realpath, serialize,
};
#[derive(Debug)]
@@ -159,9 +158,9 @@ impl PathRepository {
let url_matches = self.get_url_matches()?;
if url_matches.is_empty() {
- if Preg::is_match(php_regex!(r"{[*{}]}"), &self.url) {
+ if preg_match2(php_regex!(r"{[*{}]}"), &self.url, 0).is_some() {
let mut url = self.url.clone();
- while Preg::is_match(php_regex!(r"{[*{}]}"), &url) {
+ while preg_match2(php_regex!(r"{[*{}]}"), &url, 0).is_some() {
url = shirabe_php_shim::dirname(&url);
}
// the parent directory before any wildcard exists, so we assume it is correctly configured but simply empty
diff --git a/crates/shirabe/src/repository/platform_repository.rs b/crates/shirabe/src/repository/platform_repository.rs
index 3df346de..4ded0163 100644
--- a/crates/shirabe/src/repository/platform_repository.rs
+++ b/crates/shirabe/src/repository/platform_repository.rs
@@ -16,12 +16,11 @@ use crate::plugin::plugin_interface::{self};
use crate::repository::ArrayRepository;
use crate::repository::RepositoryInterface;
use indexmap::IndexMap;
-use shirabe_pcre::Preg;
use shirabe_php_rpc::PlatformInfo;
use shirabe_php_shim::{
InvalidArgumentException, PhpMixed, UnexpectedValueException, array_map_str_fn,
- array_slice_strs, explode, get_class, implode, is_string, php_regex, str_replace, strpos,
- strtolower, var_export,
+ array_slice_strs, explode, get_class, implode, is_string, php_regex, preg_match2, preg_replace,
+ str_replace, strpos, strtolower, var_export,
};
use shirabe_semver::constraint::SimpleConstraint;
use std::sync::{LazyLock, Mutex};
@@ -221,7 +220,7 @@ impl PlatformRepository {
}
Err(_) => {
pretty_version =
- Preg::replace(php_regex!("#^([^~+-]+).*$#"), "$1", &php_version_str);
+ preg_replace(php_regex!("#^([^~+-]+).*$#"), "$1", &php_version_str);
version = self
.version_parser
.as_ref()
@@ -316,9 +315,10 @@ impl PlatformRepository {
let info = platform_info.get_extension_info(name);
// librabbitmq version => 0.9.0
- if let Some(librabbitmq_matches) = Preg::is_match3(
+ if let Some(librabbitmq_matches) = preg_match2(
php_regex!("/^librabbitmq version => (?<version>.+)$/im"),
info,
+ 0,
) {
self.add_library(
&mut libraries,
@@ -331,9 +331,10 @@ impl PlatformRepository {
}
// AMQP protocol version => 0-9-1
- if let Some(protocol_matches) = Preg::is_match3(
+ if let Some(protocol_matches) = preg_match2(
php_regex!("/^AMQP protocol version => (?<version>.+)$/im"),
info,
+ 0,
) {
let version_str = protocol_matches
.name("version")
@@ -355,7 +356,7 @@ impl PlatformRepository {
// BZip2 Version => 1.0.6, 6-Sept-2010
if let Some(matches) =
- Preg::is_match3(php_regex!("/^BZip2 Version => (?<version>.*),/im"), info)
+ preg_match2(php_regex!("/^BZip2 Version => (?<version>.*),/im"), info, 0)
{
self.add_library(
&mut libraries,
@@ -382,9 +383,10 @@ impl PlatformRepository {
let info = platform_info.get_extension_info(name);
// SSL Version => OpenSSL/1.0.1t
- if let Some(ssl_matches) = Preg::is_match3(
+ if let Some(ssl_matches) = preg_match2(
php_regex!("{^SSL Version => (?<library>[^/]+)/(?<version>.+)$}im"),
info,
+ 0,
) {
let ssl_library_raw =
ssl_matches.name("library").unwrap_or_default().to_string();
@@ -411,9 +413,10 @@ impl PlatformRepository {
} else {
let (shortlib, ssl_lib);
if library.starts_with("(securetransport)") {
- if let Some(securetransport_matches) = Preg::is_match3(
+ if let Some(securetransport_matches) = preg_match2(
php_regex!("{^\\(securetransport\\) ([a-z0-9]+)}"),
&library,
+ 0,
) {
shortlib = "securetransport".to_string();
let m1 = securetransport_matches
@@ -441,11 +444,12 @@ impl PlatformRepository {
}
// libSSH Version => libssh2/1.4.3
- if let Some(ssh_matches) = Preg::is_match3(
+ if let Some(ssh_matches) = preg_match2(
php_regex!(
"{^libSSH Version => (?<library>[^/]+)/(?<version>.+?)(?:/.*)?$}im"
),
info,
+ 0,
) {
let ssh_library =
ssh_matches.name("library").unwrap_or_default().to_string();
@@ -463,7 +467,7 @@ impl PlatformRepository {
// ZLib Version => 1.2.8
if let Some(zlib_matches) =
- Preg::is_match3(php_regex!("{^ZLib Version => (?<version>.+)$}im"), info)
+ preg_match2(php_regex!("{^ZLib Version => (?<version>.+)$}im"), info, 0)
{
self.add_library(
&mut libraries,
@@ -480,9 +484,11 @@ impl PlatformRepository {
let info = platform_info.get_extension_info(name);
// timelib version => 2018.03
- if let Some(timelib_matches) =
- Preg::is_match3(php_regex!("/^timelib version => (?<version>.+)$/im"), info)
- {
+ if let Some(timelib_matches) = preg_match2(
+ php_regex!("/^timelib version => (?<version>.+)$/im"),
+ info,
+ 0,
+ ) {
self.add_library(
&mut libraries,
&format!("{}-timelib", name),
@@ -494,19 +500,21 @@ impl PlatformRepository {
}
// Timezone Database => internal
- if let Some(zoneinfo_source_matches) = Preg::is_match3(
+ if let Some(zoneinfo_source_matches) = preg_match2(
php_regex!("/^Timezone Database => (?<source>internal|external)$/im"),
info,
+ 0,
) {
let external = zoneinfo_source_matches
.name("source")
.map(|s| s == "external")
.unwrap_or(false);
- if let Some(zoneinfo_matches) = Preg::is_match3(
+ if let Some(zoneinfo_matches) = preg_match2(
php_regex!(
"/^\"Olson\" Timezone Database Version => (?<version>.+?)(?:\\.system)?$/im"
),
info,
+ 0,
) {
let zoneinfo_version = zoneinfo_matches
.name("version")
@@ -543,7 +551,7 @@ impl PlatformRepository {
// libmagic => 537
if let Some(magic_matches) =
- Preg::is_match3(php_regex!("/^libmagic => (?<version>.+)$/im"), info)
+ preg_match2(php_regex!("/^libmagic => (?<version>.+)$/im"), info, 0)
{
self.add_library(
&mut libraries,
@@ -573,9 +581,10 @@ impl PlatformRepository {
let info = platform_info.get_extension_info(name);
- if let Some(libjpeg_matches) = Preg::is_match3(
+ if let Some(libjpeg_matches) = preg_match2(
php_regex!("/^libJPEG Version => (?<version>.+?)(?: compatible)?$/im"),
info,
+ 0,
) {
let libjpeg_version = libjpeg_matches
.name("version")
@@ -592,9 +601,11 @@ impl PlatformRepository {
)?;
}
- if let Some(libpng_matches) =
- Preg::is_match3(php_regex!("/^libPNG Version => (?<version>.+)$/im"), info)
- {
+ if let Some(libpng_matches) = preg_match2(
+ php_regex!("/^libPNG Version => (?<version>.+)$/im"),
+ info,
+ 0,
+ ) {
self.add_library(
&mut libraries,
&format!("{}-libpng", name),
@@ -605,9 +616,10 @@ impl PlatformRepository {
)?;
}
- if let Some(freetype_matches) = Preg::is_match3(
+ if let Some(freetype_matches) = preg_match2(
php_regex!("/^FreeType Version => (?<version>.+)$/im"),
info,
+ 0,
) {
self.add_library(
&mut libraries,
@@ -619,9 +631,10 @@ impl PlatformRepository {
)?;
}
- if let Some(libxpm_matches) = Preg::is_match3(
+ if let Some(libxpm_matches) = preg_match2(
php_regex!("/^libXpm Version => (?<versionId>\\d+)$/im"),
info,
+ 0,
) {
let version_id: i64 = libxpm_matches
.name("versionId")
@@ -692,7 +705,7 @@ impl PlatformRepository {
)?;
} else {
if let Some(matches) =
- Preg::is_match3(php_regex!("/^ICU version => (?<version>.+)$/im"), info)
+ preg_match2(php_regex!("/^ICU version => (?<version>.+)$/im"), info, 0)
{
self.add_library(
&mut libraries,
@@ -706,9 +719,10 @@ impl PlatformRepository {
}
// ICU TZData version => 2019c
- if let Some(zoneinfo_matches) = Preg::is_match3(
+ if let Some(zoneinfo_matches) = preg_match2(
php_regex!("/^ICU TZData version => (?<version>.*)$/im"),
info,
+ 0,
) {
let zi_version = zoneinfo_matches
.name("version")
@@ -769,9 +783,10 @@ impl PlatformRepository {
Self::imagick_get_version_string(image_magick_version);
// 6.x: ImageMagick 6.2.9 08/24/06 Q16 http://www.imagemagick.org
// 7.x: ImageMagick 7.0.8-34 Q16 x86_64 2019-03-23 https://imagemagick.org
- if let Some(matches) = Preg::is_match3(
+ if let Some(matches) = preg_match2(
php_regex!("/^ImageMagick (?<version>[\\d.]+)(?:-(?<patch>\\d+))?/"),
&image_magick_version_str,
+ 0,
) {
let mut version_built =
matches.name("version").unwrap_or_default().to_string();
@@ -793,11 +808,12 @@ impl PlatformRepository {
"ldap" => {
let info = platform_info.get_extension_info(name);
- if let Some(matches) = Preg::is_match3(
+ if let Some(matches) = preg_match2(
php_regex!("/^Vendor Version => (?<versionId>\\d+)$/im"),
info,
+ 0,
) && let Some(vendor_matches) =
- Preg::is_match3(php_regex!("/^Vendor Name => (?<vendor>.+)$/im"), info)
+ preg_match2(php_regex!("/^Vendor Name => (?<vendor>.+)$/im"), info, 0)
{
let version_id: i64 = matches
.name("versionId")
@@ -848,9 +864,11 @@ impl PlatformRepository {
let info = platform_info.get_extension_info(name);
// libmbfl version => 1.3.2
- if let Some(libmbfl_matches) =
- Preg::is_match3(php_regex!("/^libmbfl version => (?<version>.+)$/im"), info)
- {
+ if let Some(libmbfl_matches) = preg_match2(
+ php_regex!("/^libmbfl version => (?<version>.+)$/im"),
+ info,
+ 0,
+ ) {
self.add_library(
&mut libraries,
&format!("{}-libmbfl", name),
@@ -879,11 +897,12 @@ impl PlatformRepository {
// Multibyte regex (oniguruma) version => 5.9.5
// oniguruma version => 6.9.0
} else {
- if let Some(oniguruma_matches) = Preg::is_match3(
+ if let Some(oniguruma_matches) = preg_match2(
php_regex!(
"/^(?:oniguruma|Multibyte regex \\(oniguruma\\)) version => (?<version>.+)$/im"
),
info,
+ 0,
) {
self.add_library(
&mut libraries,
@@ -901,9 +920,10 @@ impl PlatformRepository {
let info = platform_info.get_extension_info(name);
// libmemcached version => 1.0.18
- if let Some(matches) = Preg::is_match3(
+ if let Some(matches) = preg_match2(
php_regex!("/^libmemcached version => (?<version>.+)$/im"),
info,
+ 0,
) {
self.add_library(
&mut libraries,
@@ -923,9 +943,10 @@ impl PlatformRepository {
_ => "".to_string(),
};
// OpenSSL 1.1.1g 21 Apr 2020
- if let Some(matches) = Preg::is_match3(
+ if let Some(matches) = preg_match2(
php_regex!("{^(?:OpenSSL|LibreSSL)?\\s*(?<version>\\S+)}i"),
&openssl_text_str,
+ 0,
) {
let version = matches.name("version").unwrap_or_default().to_string();
let mut is_fips = false;
@@ -952,16 +973,16 @@ impl PlatformRepository {
PhpMixed::String(s) => s.clone(),
_ => "".to_string(),
};
- let stripped =
- Preg::replace(php_regex!("{^(\\S+).*}"), "$1", &pcre_version_str);
+ let stripped = preg_replace(php_regex!("{^(\\S+).*}"), "$1", &pcre_version_str);
self.add_library(&mut libraries, name, Some(&stripped), None, &[], &[])?;
let info = platform_info.get_extension_info(name);
// PCRE Unicode Version => 12.1.0
- if let Some(pcre_unicode_matches) = Preg::is_match3(
+ if let Some(pcre_unicode_matches) = preg_match2(
php_regex!("/^PCRE Unicode Version => (?<version>.+)$/im"),
info,
+ 0,
) {
self.add_library(
&mut libraries,
@@ -977,11 +998,12 @@ impl PlatformRepository {
"mysqlnd" | "pdo_mysql" => {
let info = platform_info.get_extension_info(name);
- if let Some(matches) = Preg::is_match3(
+ if let Some(matches) = preg_match2(
php_regex!(
"/^(?:Client API version|Version) => mysqlnd (?<version>.+?) /mi"
),
info,
+ 0,
) {
self.add_library(
&mut libraries,
@@ -997,9 +1019,10 @@ impl PlatformRepository {
"mongodb" => {
let info = platform_info.get_extension_info(name);
- if let Some(libmongoc_matches) = Preg::is_match3(
+ if let Some(libmongoc_matches) = preg_match2(
php_regex!("/^libmongoc bundled version => (?<version>.+)$/im"),
info,
+ 0,
) {
self.add_library(
&mut libraries,
@@ -1011,9 +1034,10 @@ impl PlatformRepository {
)?;
}
- if let Some(libbson_matches) = Preg::is_match3(
+ if let Some(libbson_matches) = preg_match2(
php_regex!("/^libbson bundled version => (?<version>.+)$/im"),
info,
+ 0,
) {
self.add_library(
&mut libraries,
@@ -1045,9 +1069,10 @@ impl PlatformRepository {
// intentional fall-through to next case...
let info = platform_info.get_extension_info(name);
- if let Some(matches) = Preg::is_match3(
+ if let Some(matches) = preg_match2(
php_regex!("/^PostgreSQL\\(libpq\\) Version => (?<version>.*)$/im"),
info,
+ 0,
) {
self.add_library(
&mut libraries,
@@ -1064,9 +1089,10 @@ impl PlatformRepository {
"pdo_pgsql" => {
let info = platform_info.get_extension_info(name);
- if let Some(matches) = Preg::is_match3(
+ if let Some(matches) = preg_match2(
php_regex!("/^PostgreSQL\\(libpq\\) Version => (?<version>.*)$/im"),
info,
+ 0,
) {
self.add_library(
&mut libraries,
@@ -1084,9 +1110,10 @@ impl PlatformRepository {
// Used Library => Compiled => Linked
// libpq => 14.3 (Ubuntu 14.3-1.pgdg22.04+1) => 15.0.2
- if let Some(matches) = Preg::is_match3(
+ if let Some(matches) = preg_match2(
php_regex!("/^libpq => (?<compiled>.+) => (?<linked>.+)$/im"),
info,
+ 0,
) {
self.add_library(
&mut libraries,
@@ -1158,9 +1185,11 @@ impl PlatformRepository {
"sqlite3" | "pdo_sqlite" => {
let info = platform_info.get_extension_info(name);
- if let Some(matches) =
- Preg::is_match3(php_regex!("/^SQLite Library => (?<version>.+)$/im"), info)
- {
+ if let Some(matches) = preg_match2(
+ php_regex!("/^SQLite Library => (?<version>.+)$/im"),
+ info,
+ 0,
+ ) {
self.add_library(
&mut libraries,
&format!("{}-sqlite", name),
@@ -1175,9 +1204,11 @@ impl PlatformRepository {
"ssh2" => {
let info = platform_info.get_extension_info(name);
- if let Some(matches) =
- Preg::is_match3(php_regex!("/^libssh2 version => (?<version>.+)$/im"), info)
- {
+ if let Some(matches) = preg_match2(
+ php_regex!("/^libssh2 version => (?<version>.+)$/im"),
+ info,
+ 0,
+ ) {
self.add_library(
&mut libraries,
&format!("{}-libssh2", name),
@@ -1206,11 +1237,12 @@ impl PlatformRepository {
)?;
let info = platform_info.get_extension_info("xsl");
- if let Some(matches) = Preg::is_match3(
+ if let Some(matches) = preg_match2(
php_regex!(
"/^libxslt compiled against libxml Version => (?<version>.+)$/im"
),
info,
+ 0,
) {
self.add_library(
&mut libraries,
@@ -1226,9 +1258,11 @@ impl PlatformRepository {
"yaml" => {
let info = platform_info.get_extension_info("yaml");
- if let Some(matches) =
- Preg::is_match3(php_regex!("/^LibYAML Version => (?<version>.+)$/im"), info)
- {
+ if let Some(matches) = preg_match2(
+ php_regex!("/^LibYAML Version => (?<version>.+)$/im"),
+ info,
+ 0,
+ ) {
self.add_library(
&mut libraries,
&format!("{}-libyaml", name),
@@ -1278,9 +1312,10 @@ impl PlatformRepository {
// Linked Version => 1.2.8
} else {
let info = platform_info.get_extension_info(name);
- if let Some(matches) = Preg::is_match3(
+ if let Some(matches) = preg_match2(
php_regex!("/^Linked Version => (?<version>.+)$/im"),
info,
+ 0,
) {
self.add_library(
&mut libraries,
@@ -1313,7 +1348,7 @@ impl PlatformRepository {
}
Err(_) => {
pretty_version =
- Preg::replace(php_regex!("#^([^~+-]+).*$#"), "$1", &hhvm_version);
+ preg_replace(php_regex!("#^([^~+-]+).*$#"), "$1", &hhvm_version);
version = self
.version_parser
.as_ref()
@@ -1477,9 +1512,10 @@ impl PlatformRepository {
Ok(v) => v,
Err(_) => {
extra_description = Some(format!(" (actual version: {})", pretty_version));
- if let Some(m) = Preg::is_match3(
+ if let Some(m) = preg_match2(
php_regex!("{^(\\d+\\.\\d+\\.\\d+(?:\\.\\d+)?)}"),
&pretty_version,
+ 0,
) {
pretty_version = m.get(1).unwrap_or_default().to_string();
} else {
@@ -1608,7 +1644,7 @@ impl PlatformRepository {
return cached;
}
- let result = Preg::is_match(Self::PLATFORM_PACKAGE_REGEX, name);
+ let result = preg_match2(Self::PLATFORM_PACKAGE_REGEX, name, 0).is_some();
cache.insert(name.to_string(), result);
result
}
diff --git a/crates/shirabe/src/repository/repository_factory.rs b/crates/shirabe/src/repository/repository_factory.rs
index 279fafc5..cd492628 100644
--- a/crates/shirabe/src/repository/repository_factory.rs
+++ b/crates/shirabe/src/repository/repository_factory.rs
@@ -12,10 +12,9 @@ use crate::repository::RepositoryManagerInterface;
use crate::util::HttpDownloader;
use crate::util::ProcessExecutor;
use indexmap::IndexMap;
-use shirabe_pcre::Preg;
use shirabe_php_shim::{
InvalidArgumentException, PhpMixed, UnexpectedValueException, get_debug_type, json_encode,
- php_regex, php_to_string,
+ php_regex, php_to_string, preg_replace,
};
pub struct RepositoryFactory;
@@ -302,7 +301,7 @@ impl RepositoryFactory {
) -> String {
let mut name = if matches!(index, PhpMixed::Int(_)) && repo.contains_key("url") {
let url = repo.get("url").and_then(|v| v.as_string()).unwrap_or("");
- Preg::replace(php_regex!("{^https?://}i"), "", url)
+ preg_replace(php_regex!("{^https?://}i"), "", url)
} else {
php_to_string(index)
};
@@ -318,7 +317,7 @@ impl RepositoryFactory {
existing_repos: &IndexMap<String, RepositoryInterfaceHandle>,
) -> String {
let mut name = if let Some(url) = repo.get("url").and_then(|v| v.as_string()) {
- Preg::replace(php_regex!("{^https?://}i"), "", url)
+ preg_replace(php_regex!("{^https?://}i"), "", url)
} else {
index.to_string()
};
diff --git a/crates/shirabe/src/repository/vcs/forgejo_driver.rs b/crates/shirabe/src/repository/vcs/forgejo_driver.rs
index 8047602a..90480add 100644
--- a/crates/shirabe/src/repository/vcs/forgejo_driver.rs
+++ b/crates/shirabe/src/repository/vcs/forgejo_driver.rs
@@ -15,10 +15,10 @@ use crate::util::ForgejoRepositoryData;
use crate::util::ForgejoUrl;
use crate::util::http::Response;
use indexmap::IndexMap;
-use shirabe_pcre::Preg;
use shirabe_php_shim::Catch as _;
use shirabe_php_shim::{
- PhpMixed, RuntimeException, base64_decode, explode, extension_loaded, php_regex, urlencode,
+ PhpMixed, RuntimeException, base64_decode, explode, extension_loaded, php_regex, preg_match2,
+ urlencode,
};
#[derive(Debug)]
@@ -584,7 +584,7 @@ impl ForgejoDriver {
let links = explode(",", &header);
for link in links {
- if let Some(m) = Preg::match3(php_regex!(r#"{<(.+?)>; *rel="next"}"#), &link)
+ if let Some(m) = preg_match2(php_regex!(r#"{<(.+?)>; *rel="next"}"#), &link, 0)
&& let Some(url) = m.get(1)
{
return Some(url.to_string());
diff --git a/crates/shirabe/src/repository/vcs/fossil_driver.rs b/crates/shirabe/src/repository/vcs/fossil_driver.rs
index 8ce479fd..c42ca271 100644
--- a/crates/shirabe/src/repository/vcs/fossil_driver.rs
+++ b/crates/shirabe/src/repository/vcs/fossil_driver.rs
@@ -11,10 +11,10 @@ use crate::util::Filesystem;
use crate::util::ProcessExecutor;
use chrono::{DateTime, FixedOffset, Utc};
use indexmap::IndexMap;
-use shirabe_pcre::Preg;
use shirabe_php_shim::Catch as _;
use shirabe_php_shim::{
- PhpMixed, RuntimeException, dirname, is_dir, is_file, is_writable, php_regex,
+ PhpMixed, RuntimeException, dirname, is_dir, is_file, is_writable, php_regex, preg_match2,
+ preg_replace,
};
#[derive(Debug)]
@@ -82,7 +82,7 @@ impl FossilDriver {
.into());
}
- let local_name = Preg::replace(php_regex!(r"{[^a-z0-9]}i"), "-", &self.inner.url);
+ let local_name = preg_replace(php_regex!(r"{[^a-z0-9]}i"), "-", &self.inner.url);
self.repo_file = Some(format!("{}/{}.fossil", cache_repo_dir, local_name));
self.checkout_dir = format!("{}/{}/", cache_vcs_dir, local_name);
@@ -286,7 +286,7 @@ impl FossilDriver {
Some(&self.checkout_dir),
);
for branch in self.inner.process.borrow().split_lines(&output) {
- let branch = Preg::replace(php_regex!(r"/^\*/"), "", branch.trim());
+ let branch = preg_replace(php_regex!(r"/^\*/"), "", branch.trim());
let branch = branch.trim().to_string();
branches.insert(branch.clone(), branch);
}
@@ -301,14 +301,17 @@ impl FossilDriver {
url: &str,
deep: bool,
) -> anyhow::Result<bool> {
- if Preg::is_match(
+ if preg_match2(
php_regex!(r"#(^(?:https?|ssh)://(?:[^@]@)?(?:chiselapp\.com|fossil\.))#i"),
url,
- ) {
+ 0,
+ )
+ .is_some()
+ {
return Ok(true);
}
- if Preg::is_match(php_regex!(r"!/fossil/|\.fossil!"), url) {
+ if preg_match2(php_regex!(r"!/fossil/|\.fossil!"), url, 0).is_some() {
return Ok(true);
}
diff --git a/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs b/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs
index 5f83b4e1..9f8e7a80 100644
--- a/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs
+++ b/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs
@@ -15,11 +15,11 @@ use crate::util::Bitbucket;
use crate::util::http::Response;
use chrono::{DateTime, FixedOffset};
use indexmap::IndexMap;
-use shirabe_pcre::Preg;
use shirabe_php_shim::Catch as _;
use shirabe_php_shim::{
InvalidArgumentException, LogicException, PhpMixed, RuntimeException, array_key_exists,
- array_search_mixed, extension_loaded, http_build_query, implode, is_array, php_regex, strpos,
+ array_search_mixed, extension_loaded, http_build_query, implode, is_array, php_regex,
+ preg_match2, preg_replace, strpos,
};
#[derive(Debug)]
@@ -84,9 +84,10 @@ impl GitBitbucketDriver {
/// @inheritDoc
pub fn initialize(&mut self) -> anyhow::Result<()> {
- let Some(m) = Preg::is_match3(
+ let Some(m) = preg_match2(
php_regex!(r"#^https?://bitbucket\.org/([^/]+)/([^/]+?)(?:\.git|/?)?$#i"),
&self.inner.url,
+ 0,
) else {
return Err(InvalidArgumentException::new(format!(
"The Bitbucket repository URL {} is invalid. It must be the HTTPS URL of a Bitbucket repository.",
@@ -739,7 +740,7 @@ impl GitBitbucketDriver {
{
// Format: https://(user@)bitbucket.org/{user}/{repo}
// Strip username from URL (only present in clone URL's for private repositories)
- self.clone_https_url = Preg::replace(
+ self.clone_https_url = preg_replace(
php_regex!(r"/https:\/\/([^@]+@)?/"),
"https://",
m.get("href").and_then(|v| v.as_string()).unwrap_or(""),
@@ -797,10 +798,13 @@ impl GitBitbucketDriver {
url: &str,
_deep: bool,
) -> anyhow::Result<bool> {
- if !Preg::is_match(
+ if preg_match2(
php_regex!(r"#^https?://bitbucket\.org/([^/]+)/([^/]+?)(\.git|/?)?$#i"),
url,
- ) {
+ 0,
+ )
+ .is_none()
+ {
return Ok(false);
}
diff --git a/crates/shirabe/src/repository/vcs/git_driver.rs b/crates/shirabe/src/repository/vcs/git_driver.rs
index c224e8e6..62cca379 100644
--- a/crates/shirabe/src/repository/vcs/git_driver.rs
+++ b/crates/shirabe/src/repository/vcs/git_driver.rs
@@ -14,11 +14,10 @@ use crate::util::Url;
use chrono::TimeZone;
use chrono::{DateTime, FixedOffset, Utc};
use indexmap::IndexMap;
-use shirabe_pcre::Preg;
use shirabe_php_shim::Catch as _;
use shirabe_php_shim::{
- InvalidArgumentException, RuntimeException, dirname, is_dir, is_writable, realpath,
- sys_get_temp_dir,
+ InvalidArgumentException, RuntimeException, dirname, is_dir, is_writable, preg_match2,
+ preg_replace, realpath, sys_get_temp_dir,
};
use shirabe_php_shim::{PhpMixed, php_regex};
@@ -51,7 +50,7 @@ impl GitDriver {
pub fn initialize(&mut self) -> anyhow::Result<()> {
let cache_url;
if Filesystem::is_local_path(&self.inner.url) {
- self.inner.url = Preg::replace(php_regex!(r"{[\\/]\.git/?$}"), "", &self.inner.url);
+ self.inner.url = preg_replace(php_regex!(r"{[\\/]\.git/?$}"), "", &self.inner.url);
if !is_dir(&self.inner.url) {
return Err(RuntimeException::new(format!(
"Failed to read package information from {} as the path does not exist",
@@ -78,7 +77,7 @@ impl GitDriver {
self.repo_dir = format!(
"{}/{}/",
cache_vcs_dir,
- Preg::replace(
+ preg_replace(
r"{[^a-z0-9.]}i",
"-",
&Url::sanitize(self.inner.url.clone())
@@ -99,7 +98,13 @@ impl GitDriver {
.into());
}
- if Preg::is_match(php_regex!(r"{^ssh://[^@]+@[^:]+:[^0-9]+}"), &self.inner.url) {
+ if preg_match2(
+ php_regex!(r"{^ssh://[^@]+@[^:]+:[^0-9]+}"),
+ &self.inner.url,
+ 0,
+ )
+ .is_some()
+ {
return Err(InvalidArgumentException::new(format!(
"The source URL {} is invalid, ssh URLs should have a port number after \":\".\nUse ssh://git@example.com:22/path or just git@example.com:path if you do not want to provide a password or custom port.",
self.inner.url
@@ -146,7 +151,7 @@ impl GitDriver {
&format!(
"{}/{}",
cache_repo_dir,
- Preg::replace(r"{[^a-z0-9.]}i", "-", &Url::sanitize(cache_url))
+ preg_replace(r"{[^a-z0-9.]}i", "-", &Url::sanitize(cache_url))
),
None,
None,
@@ -199,7 +204,7 @@ impl GitDriver {
if !branches.contains(&"* master".to_string()) {
for branch in &branches {
if !branch.is_empty()
- && let Some(caps) = Preg::match3(php_regex!(r"{^\* +(\S+)}"), branch)
+ && let Some(caps) = preg_match2(php_regex!(r"{^\* +(\S+)}"), branch, 0)
&& let Some(name) = caps.get(1)
{
self.root_identifier = Some(name.to_string());
@@ -309,9 +314,10 @@ impl GitDriver {
);
for tag in self.inner.process.borrow().split_lines(&output) {
if !tag.is_empty()
- && let Some(caps) = Preg::match3(
+ && let Some(caps) = preg_match2(
php_regex!(r"{^([a-f0-9]{40}) refs/tags/(\S+?)(\^\{\})?$}"),
&tag,
+ 0,
)
&& let (Some(hash), Some(name)) = (caps.get(1), caps.get(2))
{
@@ -344,10 +350,11 @@ impl GitDriver {
);
for branch in self.inner.process.borrow().split_lines(&output) {
if !branch.is_empty()
- && !Preg::is_match(php_regex!(r"{^ *[^/]+/HEAD }"), &branch)
- && let Some(caps) = Preg::match3(
+ && preg_match2(php_regex!(r"{^ *[^/]+/HEAD }"), &branch, 0).is_none()
+ && let Some(caps) = preg_match2(
php_regex!(r"{^(?:\* )? *(\S+) *([a-f0-9]+)(?: .*)?$}"),
&branch,
+ 0,
)
&& let (Some(name), Some(hash)) = (caps.get(1), caps.get(2))
&& !name.starts_with('-')
@@ -368,10 +375,13 @@ impl GitDriver {
url: &str,
deep: bool,
) -> anyhow::Result<bool> {
- if Preg::is_match(
+ if preg_match2(
php_regex!(r"#(^git://|\.git/?$|git(?:olite)?@|//git\.|//github.com/)#i"),
url,
- ) {
+ 0,
+ )
+ .is_some()
+ {
return Ok(true);
}
diff --git a/crates/shirabe/src/repository/vcs/github_driver.rs b/crates/shirabe/src/repository/vcs/github_driver.rs
index 11bb9503..e9c17d30 100644
--- a/crates/shirabe/src/repository/vcs/github_driver.rs
+++ b/crates/shirabe/src/repository/vcs/github_driver.rs
@@ -14,12 +14,12 @@ use crate::util::GitHub;
use crate::util::http::Response;
use chrono::{DateTime, FixedOffset};
use indexmap::IndexMap;
-use shirabe_pcre::Preg;
use shirabe_php_shim::Catch as _;
use shirabe_php_shim::{
InvalidArgumentException, PhpMixed, RuntimeException, array_diff, array_map,
array_search_mixed, base64_decode, basename, empty, explode, extension_loaded, in_array_loose,
- parse_url, php_regex, preg_split, strpos, strtolower, substr, trim, urlencode,
+ parse_url, php_regex, preg_match2, preg_replace, preg_split, strpos, strtolower, substr, trim,
+ urlencode,
};
#[derive(Debug)]
@@ -70,11 +70,12 @@ impl GitHubDriver {
}
pub fn initialize(&mut self) -> anyhow::Result<()> {
- let Some(match_) = Preg::is_match3(
+ let Some(match_) = preg_match2(
php_regex!(
r"#^(?:(?:https?|git)://([^/]+)/|git@([^:]+):/?)([^/]+)/([^/]+?)(?:\.git|/)?$#"
),
&self.inner.url,
+ 0,
) else {
return Err(InvalidArgumentException::new(format!(
"The GitHub repository URL {} is invalid.",
@@ -482,14 +483,14 @@ impl GitHubDriver {
let mut key: Option<String> = None;
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) {
+ if let Some(m) = preg_match2(php_regex!(r"{^(\w+)\s*:\s*(.+)$}"), &line, 0) {
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) {
+ if let Some(m2) = preg_match2(php_regex!(r"{^\[(.*?)\](?:\s*#.*)?$}"), &g2, 0) {
let inner = m2.get(1).unwrap_or_default().to_string();
for item in array_map(
|s: &String| trim(s, None),
@@ -504,7 +505,7 @@ impl GitHubDriver {
result.push(entry);
}
} else if let Some(m2) =
- Preg::is_match3(php_regex!(r"{^([^#].*?)(?:\s+#.*)?$}"), &g2)
+ preg_match2(php_regex!(r"{^([^#].*?)(?:\s+#.*)?$}"), &g2, 0)
{
let mut entry = IndexMap::new();
entry.insert("type".to_string(), PhpMixed::String(g1.clone()));
@@ -515,11 +516,11 @@ impl GitHubDriver {
result.push(entry);
}
key = None;
- } else if let Some(m) = Preg::is_match3(php_regex!(r"{^(\w+)\s*:\s*#\s*$}"), &line) {
+ } else if let Some(m) = preg_match2(php_regex!(r"{^(\w+)\s*:\s*#\s*$}"), &line, 0) {
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))
+ && let Some(m) = preg_match2(php_regex!(r"{^-\s*(.+)(?:\s+#.*)?$}"), &line, 0)
+ .or_else(|| preg_match2(php_regex!(r"{^(.+),(?:\s*#.*)?$}"), &line, 0))
{
let mut entry = IndexMap::new();
entry.insert(
@@ -644,7 +645,9 @@ impl GitHubDriver {
};
if bits.scheme.is_none() && bits.host.is_none() {
- if Preg::is_match(php_regex!(r"{^[a-z0-9-]++\.[a-z]{2,3}$}"), &item_url) {
+ if preg_match2(php_regex!(r"{^[a-z0-9-]++\.[a-z]{2,3}$}"), &item_url, 0)
+ .is_some()
+ {
result[key_idx].insert(
"url".to_string(),
PhpMixed::String(format!("https://{}", item_url)),
@@ -908,11 +911,12 @@ impl GitHubDriver {
url: &str,
_deep: bool,
) -> anyhow::Result<bool> {
- let Some(matches) = Preg::is_match3(
+ let Some(matches) = preg_match2(
php_regex!(
r"#^((?:https?|git)://([^/]+)/|git@([^:]+):/?)([^/]+)/([^/]+?)(?:\.git|/)?$#"
),
url,
+ 0,
) else {
return Ok(false);
};
@@ -923,7 +927,7 @@ impl GitHubDriver {
.map(str::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)),
+ strtolower(&preg_replace(php_regex!(r"{^www\.}i"), "", &origin_url)),
config.borrow().get("github-domains").values(),
) {
return Ok(false);
@@ -1249,7 +1253,7 @@ impl GitHubDriver {
let links = explode(",", &header);
for link in &links {
- if let Some(m) = Preg::is_match3(php_regex!(r#"{<(.+?)>; *rel="next"}"#), link) {
+ if let Some(m) = preg_match2(php_regex!(r#"{<(.+?)>; *rel="next"}"#), link, 0) {
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 30c3f7ae..6054d941 100644
--- a/crates/shirabe/src/repository/vcs/gitlab_driver.rs
+++ b/crates/shirabe/src/repository/vcs/gitlab_driver.rs
@@ -15,12 +15,11 @@ use crate::util::HttpDownloader;
use crate::util::http::Response;
use chrono::{DateTime, FixedOffset};
use indexmap::IndexMap;
-use shirabe_pcre::Preg;
use shirabe_php_shim::Catch as _;
use shirabe_php_shim::{
InvalidArgumentException, LogicException, PhpMixed, RuntimeException, array_search_mixed,
array_shift, ctype_alnum, empty, explode, extension_loaded, implode, in_array_loose, is_array,
- is_string, ord, php_regex, strpos, strtolower,
+ is_string, ord, php_regex, preg_match2, preg_replace, strpos, strtolower,
};
/// Driver for GitLab API, use the Git driver for local checkouts.
@@ -81,7 +80,7 @@ impl GitLabDriver {
///
/// SSH urls use https by default. Set "secure-http": false on the repository config to use http instead.
pub fn initialize(&mut self) -> anyhow::Result<()> {
- let Some(match_) = Preg::is_match3(Self::URL_REGEX, &self.inner.url) else {
+ let Some(match_) = preg_match2(Self::URL_REGEX, &self.inner.url, 0) else {
return Err(InvalidArgumentException::new(format!(
"The GitLab repository URL {} is invalid. It must be the HTTP URL of a GitLab project.",
self.inner.url.clone(),
@@ -152,7 +151,7 @@ impl GitLabDriver {
}
self.namespace = implode("/", &url_parts);
- self.repository = Preg::replace(
+ self.repository = preg_replace(
php_regex!(r"#(\.git)$#"),
"",
match_.name("repo").unwrap_or_default(),
@@ -383,7 +382,7 @@ impl GitLabDriver {
// Convert the root identifier to a cacheable commit id
let mut identifier = identifier.to_string();
- if !Preg::is_match(php_regex!(r"{[a-f0-9]{40}}i"), &identifier) {
+ if preg_match2(php_regex!(r"{[a-f0-9]{40}}i"), &identifier, 0).is_none() {
let branches = self.get_branches()?;
if let Some(sha) = branches.get(&identifier) {
identifier = sha.clone();
@@ -927,7 +926,7 @@ impl GitLabDriver {
url: &str,
_deep: bool,
) -> anyhow::Result<bool> {
- let Some(match_) = Preg::is_match3(Self::URL_REGEX, url) else {
+ let Some(match_) = preg_match2(Self::URL_REGEX, url, 0) else {
return Ok(false);
};
@@ -978,7 +977,7 @@ impl GitLabDriver {
let links = explode(",", &header);
for link in &links {
- if let Some(match_) = Preg::is_match3(php_regex!(r#"{<(.+?)>; *rel="next"}"#), link) {
+ if let Some(match_) = preg_match2(php_regex!(r#"{<(.+?)>; *rel="next"}"#), link, 0) {
return Some(match_.get(1).unwrap_or_default().to_string());
}
}
@@ -1022,7 +1021,7 @@ impl GitLabDriver {
if in_array_loose(guessed_domain.clone(), configured_domains.values())
|| (port_number.is_some()
&& in_array_loose(
- Preg::replace(php_regex!(r"{:\d+}"), "", &guessed_domain),
+ preg_replace(php_regex!(r"{:\d+}"), "", &guessed_domain),
configured_domains.values(),
))
{
diff --git a/crates/shirabe/src/repository/vcs/hg_driver.rs b/crates/shirabe/src/repository/vcs/hg_driver.rs
index 120b8ea8..ada1063e 100644
--- a/crates/shirabe/src/repository/vcs/hg_driver.rs
+++ b/crates/shirabe/src/repository/vcs/hg_driver.rs
@@ -11,9 +11,10 @@ use crate::util::Hg as HgUtils;
use crate::util::Url;
use chrono::{DateTime, FixedOffset, Utc};
use indexmap::IndexMap;
-use shirabe_pcre::Preg;
use shirabe_php_shim::Catch as _;
-use shirabe_php_shim::{PhpMixed, RuntimeException, dirname, is_dir, is_writable, php_regex};
+use shirabe_php_shim::{
+ PhpMixed, RuntimeException, dirname, is_dir, is_writable, php_regex, preg_match2, preg_replace,
+};
#[derive(Debug)]
pub struct HgDriver {
@@ -57,7 +58,7 @@ impl HgDriver {
return Err(RuntimeException::new("HgDriver requires a usable cache directory, and it looks like you set it to be disabled".to_string()).into());
}
- let sanitized = Preg::replace(
+ let sanitized = preg_replace(
php_regex!(r"{[^a-z0-9]}i"),
"-",
&Url::sanitize(self.inner.url.clone()),
@@ -233,7 +234,7 @@ impl HgDriver {
);
for tag in self.inner.process.borrow().split_lines(&output) {
if !tag.is_empty()
- && let Some(m) = Preg::match3(php_regex!(r"(^([^\s]+)\s+\d+:(.*)$)"), &tag)
+ && let Some(m) = preg_match2(php_regex!(r"(^([^\s]+)\s+\d+:(.*)$)"), &tag, 0)
{
tags.insert(
m.get(1).unwrap_or_default().to_string(),
@@ -263,7 +264,7 @@ impl HgDriver {
for branch in self.inner.process.borrow().split_lines(&output) {
if !branch.is_empty()
&& let Some(m) =
- Preg::match3(php_regex!(r"(^([^\s]+)\s+\d+:([a-f0-9]+))"), &branch)
+ preg_match2(php_regex!(r"(^([^\s]+)\s+\d+:([a-f0-9]+))"), &branch, 0)
{
let name = m.get(1).unwrap_or_default().to_string();
if !name.starts_with('-') {
@@ -281,7 +282,7 @@ impl HgDriver {
for branch in self.inner.process.borrow().split_lines(&output) {
if !branch.is_empty()
&& let Some(m) =
- Preg::match3(php_regex!(r"(^(?:[\s*]*)([^\s]+)\s+\d+:(.*)$)"), &branch)
+ preg_match2(php_regex!(r"(^(?:[\s*]*)([^\s]+)\s+\d+:(.*)$)"), &branch, 0)
{
let name = m.get(1).unwrap_or_default().to_string();
if !name.starts_with('-') {
@@ -304,12 +305,15 @@ impl HgDriver {
url: &str,
deep: bool,
) -> anyhow::Result<bool> {
- if Preg::is_match(
+ if preg_match2(
php_regex!(
r"#(^(?:https?|ssh)://(?:[^@]+@)?bitbucket.org|https://(?:.*?)\.kilnhg.com)#i"
),
url,
- ) {
+ 0,
+ )
+ .is_some()
+ {
return Ok(true);
}
diff --git a/crates/shirabe/src/repository/vcs/perforce_driver.rs b/crates/shirabe/src/repository/vcs/perforce_driver.rs
index ce9ffb49..50aed379 100644
--- a/crates/shirabe/src/repository/vcs/perforce_driver.rs
+++ b/crates/shirabe/src/repository/vcs/perforce_driver.rs
@@ -9,8 +9,9 @@ use crate::util::PerforceInterface;
use crate::util::ProcessExecutor;
use crate::util::http::Response;
use indexmap::IndexMap;
-use shirabe_pcre::Preg;
-use shirabe_php_shim::{BadMethodCallException, PhpMixed, RuntimeException, php_regex};
+use shirabe_php_shim::{
+ BadMethodCallException, PhpMixed, RuntimeException, php_regex, preg_match2,
+};
#[derive(Debug)]
pub struct PerforceDriver {
@@ -189,7 +190,7 @@ impl PerforceDriver {
url: &str,
deep: bool,
) -> anyhow::Result<bool> {
- if deep || Preg::is_match(php_regex!(r"#\b(perforce|p4)\b#i"), url) {
+ if deep || preg_match2(php_regex!(r"#\b(perforce|p4)\b#i"), url, 0).is_some() {
return Ok(Perforce::check_server_exists(
url,
&mut ProcessExecutor::new(Some(io)),
diff --git a/crates/shirabe/src/repository/vcs/svn_driver.rs b/crates/shirabe/src/repository/vcs/svn_driver.rs
index 6fb987a4..3398eb59 100644
--- a/crates/shirabe/src/repository/vcs/svn_driver.rs
+++ b/crates/shirabe/src/repository/vcs/svn_driver.rs
@@ -13,10 +13,10 @@ use crate::util::Svn as SvnUtil;
use crate::util::Url;
use chrono::{DateTime, FixedOffset, Utc};
use indexmap::IndexMap;
-use shirabe_pcre::Preg;
use shirabe_php_shim::Catch as _;
use shirabe_php_shim::{
- PhpMixed, RuntimeException, php_regex, stripos, strrpos, strtr, substr, trim,
+ PhpMixed, RuntimeException, php_regex, preg_match2, preg_replace, stripos, strrpos, strtr,
+ substr, trim,
};
#[derive(Debug)]
@@ -110,7 +110,7 @@ impl SvnDriver {
.get("cache-repo-dir")
.as_string()
.unwrap_or(""),
- Preg::replace(r"{[^a-z0-9.]}i", "-", &Url::sanitize(self.base_url.clone())),
+ preg_replace(r"{[^a-z0-9.]}i", "-", &Url::sanitize(self.base_url.clone())),
),
None,
None,
@@ -153,7 +153,7 @@ impl SvnDriver {
}
fn should_cache(&self, identifier: &str) -> bool {
- self.inner.cache.is_some() && Preg::is_match(php_regex!(r"{@\d+$}"), identifier)
+ self.inner.cache.is_some() && preg_match2(php_regex!(r"{@\d+$}"), identifier, 0).is_some()
}
pub fn get_composer_information(
@@ -258,7 +258,7 @@ impl SvnDriver {
let identifier = format!("/{}/", trim(identifier, Some("/")));
let (path, rev) = if let Some(m) =
- Preg::is_match3(php_regex!(r"{^(.+?)(@\d+)?/$}"), &identifier)
+ preg_match2(php_regex!(r"{^(.+?)(@\d+)?/$}"), &identifier, 0)
&& let Some(rev) = m.get(2)
{
(m.get(1).unwrap_or_default().to_string(), rev.to_string())
@@ -292,7 +292,7 @@ impl SvnDriver {
let identifier = format!("/{}/", trim(identifier, Some("/")));
let (path, rev) = if let Some(m) =
- Preg::is_match3(php_regex!(r"{^(.+?)(@\d+)?/$}"), &identifier)
+ preg_match2(php_regex!(r"{^(.+?)(@\d+)?/$}"), &identifier, 0)
&& let Some(rev) = m.get(2)
{
(m.get(1).unwrap_or_default().to_string(), rev.to_string())
@@ -306,8 +306,7 @@ impl SvnDriver {
)?;
for line in self.inner.process.borrow().split_lines(&output) {
if !line.is_empty()
- && let Some(m) =
- Preg::is_match3(php_regex!(r"{^Last Changed Date: ([^(]+)}"), &line)
+ && let Some(m) = preg_match2(php_regex!(r"{^Last Changed Date: ([^(]+)}"), &line, 0)
{
let date_str = m.get(1).unwrap_or_default().to_string();
return Ok(shirabe_php_shim::date_create::<Utc>(date_str.trim())
@@ -335,7 +334,7 @@ impl SvnDriver {
let line = trim(&line, None);
if !line.is_empty()
&& let Some(m) =
- Preg::is_match3(php_regex!(r"{^\s*(\S+).*?(\S+)\s*$}"), &line)
+ preg_match2(php_regex!(r"{^\s*(\S+).*?(\S+)\s*$}"), &line, 0)
{
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();
@@ -378,7 +377,7 @@ impl SvnDriver {
let line = trim(&line, None);
if !line.is_empty()
&& let Some(m) =
- Preg::is_match3(php_regex!(r"{^\s*(\S+).*?(\S+)\s*$}"), &line)
+ preg_match2(php_regex!(r"{^\s*(\S+).*?(\S+)\s*$}"), &line, 0)
{
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();
@@ -413,7 +412,7 @@ impl SvnDriver {
let line = trim(&line, None);
if !line.is_empty()
&& let Some(m) =
- Preg::is_match3(php_regex!(r"{^\s*(\S+).*?(\S+)\s*$}"), &line)
+ preg_match2(php_regex!(r"{^\s*(\S+).*?(\S+)\s*$}"), &line, 0)
{
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();
@@ -444,7 +443,7 @@ impl SvnDriver {
deep: bool,
) -> anyhow::Result<bool> {
let url = Self::normalize_url(url);
- if Preg::is_match(php_regex!(r"#(^svn://|^svn\+ssh://|svn\.)#i"), &url) {
+ if preg_match2(php_regex!(r"#(^svn://|^svn\+ssh://|svn\.)#i"), &url, 0).is_some() {
return Ok(true);
}
diff --git a/crates/shirabe/src/repository/vcs/vcs_driver.rs b/crates/shirabe/src/repository/vcs/vcs_driver.rs
index a5192937..1a5ee72e 100644
--- a/crates/shirabe/src/repository/vcs/vcs_driver.rs
+++ b/crates/shirabe/src/repository/vcs/vcs_driver.rs
@@ -12,9 +12,8 @@ use crate::util::ProcessExecutor;
use crate::util::http::Response;
use chrono::{DateTime, FixedOffset};
use indexmap::IndexMap;
-use shirabe_pcre::Preg;
use shirabe_php_shim::Catch as _;
-use shirabe_php_shim::{DATE_RFC3339, PhpMixed, extension_loaded, php_regex};
+use shirabe_php_shim::{DATE_RFC3339, PhpMixed, extension_loaded, php_regex, preg_match2};
#[derive(Debug)]
pub struct VcsDriverBase {
@@ -57,7 +56,8 @@ impl VcsDriverBase {
}
pub fn should_cache(&self, identifier: &str) -> bool {
- self.cache.is_some() && Preg::is_match(php_regex!("{^[a-f0-9]{40}$}iD"), identifier)
+ self.cache.is_some()
+ && preg_match2(php_regex!("{^[a-f0-9]{40}$}iD"), identifier, 0).is_some()
}
pub fn get_scheme(&self) -> &str {
@@ -202,7 +202,8 @@ pub trait VcsDriver: VcsDriverInterface {
fn cache_mut(&mut self) -> Option<&mut Cache>;
fn should_cache(&self, identifier: &str) -> bool {
- self.cache().is_some() && Preg::is_match(php_regex!("{^[a-f0-9]{40}$}iD"), identifier)
+ self.cache().is_some()
+ && preg_match2(php_regex!("{^[a-f0-9]{40}$}iD"), identifier, 0).is_some()
}
fn get_composer_information(
diff --git a/crates/shirabe/src/repository/vcs_repository.rs b/crates/shirabe/src/repository/vcs_repository.rs
index 4066ac44..33de3dfb 100644
--- a/crates/shirabe/src/repository/vcs_repository.rs
+++ b/crates/shirabe/src/repository/vcs_repository.rs
@@ -27,10 +27,10 @@ use crate::util::Platform;
use crate::util::ProcessExecutor;
use crate::util::Url;
use indexmap::IndexMap;
-use shirabe_pcre::Preg;
use shirabe_php_shim::Catch as _;
use shirabe_php_shim::{
- InvalidArgumentException, PhpClass, PhpMixed, php_regex, str_replace, strpos,
+ InvalidArgumentException, PhpClass, PhpMixed, php_regex, preg_match2, preg_replace,
+ str_replace, strpos,
};
use shirabe_semver::constraint::SimpleConstraint;
@@ -479,7 +479,7 @@ impl VcsRepository {
// make sure tag packages have no -dev flag
data.insert(
"version".to_string(),
- PhpMixed::String(Preg::replace(
+ PhpMixed::String(preg_replace(
php_regex!(r"{[.-]?dev$}i"),
"",
data.get("version")
@@ -489,7 +489,7 @@ impl VcsRepository {
);
data.insert(
"version_normalized".to_string(),
- PhpMixed::String(Preg::replace(
+ PhpMixed::String(preg_replace(
php_regex!(r"{(^dev-|[.-]?dev$)}i"),
"",
data.get("version_normalized")
@@ -510,7 +510,9 @@ impl VcsRepository {
// broken package, version doesn't match tag
if version_normalized != parsed_tag {
if is_very_verbose {
- if Preg::is_match(php_regex!(r"{(^dev-|[.-]?dev$)}i"), &parsed_tag) {
+ if preg_match2(php_regex!(r"{(^dev-|[.-]?dev$)}i"), &parsed_tag, 0)
+ .is_some()
+ {
self.io.write_error(&format!(
"<warning>Skipped tag {}, invalid tag name, tags can not use dev prefixes or suffixes</warning>",
tag
@@ -678,7 +680,7 @@ impl VcsRepository {
version = format!(
"{}{}",
prefix,
- Preg::replace(r"{(\.9{7})+}", ".x", &parsed_branch)
+ preg_replace(r"{(\.9{7})+}", ".x", &parsed_branch)
);
}