aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/util/filesystem.rs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-08-17 08:05:42 +0900
committernsfisis <nsfisis@gmail.com>2026-08-17 08:05:42 +0900
commit79b504e55cd4c4d1da102c3a076dc2a2e1edcd65 (patch)
tree2c12198742f289de49b9b77a2c2ad66ef417405c /crates/shirabe/src/util/filesystem.rs
parent9fd6aecad27240ccedab4487f6c157914142ca47 (diff)
downloadphp-shirabe-79b504e55cd4c4d1da102c3a076dc2a2e1edcd65.tar.gz
php-shirabe-79b504e55cd4c4d1da102c3a076dc2a2e1edcd65.tar.zst
php-shirabe-79b504e55cd4c4d1da102c3a076dc2a2e1edcd65.zip
refactor(pcre): return the Preg $matches instead of filling an out-param
`Composer\Pcre\Preg` fills `$matches` through a by-ref parameter, and the port mirrored that with a `&mut` (or `Option<&mut>`) out-param plus a bool or count return. Callers had to declare an empty map one line ahead of the call, and the type never said the map is only meaningful when the call matched. Return the matches instead: - match3/match4/is_match3/is_match4 -> Option<PregMatchedGroups> - is_match_named -> Option<PregNamedGroups> - match_all2/is_match_all -> PregMatchesAll - is_match_all_with_offsets3 -> PregMatchesAllWithOffsets Nothing is lost: the bool is `Option::is_some()`, and the occurrence count is the length of any one column of a PREG_PATTERN_ORDER map, now spelled `PregMatchesAll::occurrence_count()`. is_match() still answers the bool question directly for callers that want no groups. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/util/filesystem.rs')
-rw-r--r--crates/shirabe/src/util/filesystem.rs18
1 files changed, 8 insertions, 10 deletions
diff --git a/crates/shirabe/src/util/filesystem.rs b/crates/shirabe/src/util/filesystem.rs
index 21512a81..d59df55e 100644
--- a/crates/shirabe/src/util/filesystem.rs
+++ b/crates/shirabe/src/util/filesystem.rs
@@ -246,7 +246,7 @@ impl Filesystem {
return Ok(Some(true));
}
- if Preg::is_match3(php_regex!("{^(?:[a-z]:)?[/\\\\]+$}i"), directory, None) {
+ if Preg::is_match3(php_regex!("{^(?:[a-z]:)?[/\\\\]+$}i"), directory).is_some() {
return Err(RuntimeException::new(format!("Aborting an attempted deletion of {}, this was probably not intended, if it is a real use case please report it.", directory))
.into());
}
@@ -578,7 +578,7 @@ impl Filesystem {
let mut common_path = to.clone();
while strpos(&format!("{}/", from), &format!("{}/", common_path)) != Some(0)
&& "/" != common_path
- && !Preg::is_match3(php_regex!("{^[A-Z]:/?$}i"), &common_path, None)
+ && Preg::is_match3(php_regex!("{^[A-Z]:/?$}i"), &common_path).is_none()
{
common_path = strtr(&dirname(&common_path), "\\", "/");
}
@@ -635,7 +635,7 @@ impl Filesystem {
let mut common_path = to.clone();
while strpos(&format!("{}/", from), &format!("{}/", common_path)) != Some(0)
&& "/" != common_path
- && !Preg::is_match3(php_regex!("{^[A-Z]:/?$}i"), &common_path, None)
+ && Preg::is_match3(php_regex!("{^[A-Z]:/?$}i"), &common_path).is_none()
&& "." != common_path
{
common_path = strtr(&dirname(&common_path), "\\", "/");
@@ -735,11 +735,9 @@ impl Filesystem {
}
// extract a prefix being a protocol://, protocol:, protocol://drive: or simply drive:
- let mut prefix_match = shirabe_pcre::PregMatchedGroups::new();
- if Preg::is_match3(
+ if let Some(prefix_match) = Preg::is_match3(
php_regex!("{^( [0-9a-z]{2,}+: (?: // (?: [a-z]: )? )? | [a-z]: )}ix"),
&path,
- Some(&mut prefix_match),
) {
prefix = prefix_match
.get(&shirabe_pcre::CaptureKey::ByIndex(1))
@@ -785,7 +783,7 @@ impl Filesystem {
/// And other possible unforeseen disasters, see https://github.com/composer/composer/pull/9422
pub fn trim_trailing_slash(path: &str) -> String {
let mut path = path.to_string();
- if !Preg::is_match3(php_regex!("{^[/\\\\]+$}"), &path, None) {
+ if Preg::is_match3(php_regex!("{^[/\\\\]+$}"), &path).is_none() {
path = rtrim(&path, Some("/\\"));
}
@@ -802,15 +800,15 @@ impl Filesystem {
"{^(file://(?!//)|/(?!/)|/?[a-z]:[\\\\/]|\\.\\.[\\\\/]|[a-z0-9_.-]+[\\\\/])}i"
),
path,
- None,
- );
+ )
+ .is_some();
}
Preg::is_match3(
php_regex!("{^(file://|/|/?[a-z]:[\\\\/]|\\.\\.[\\\\/]|[a-z0-9_.-]+[\\\\/])}i"),
path,
- None,
)
+ .is_some()
}
pub fn get_platform_path(path: &str) -> String {