aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe-semver/src/version_parser.rs
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
commitfed0a6e7ac361af9b963c1f62411b1a85478230c (patch)
tree5cde64a24845c761890fbcbe05e0d702f1ec8df7 /crates/shirabe-semver/src/version_parser.rs
parente093b2be1c333e67c96aebb0a5291bea9ae3d6db (diff)
downloadphp-shirabe-fed0a6e7ac361af9b963c1f62411b1a85478230c.tar.gz
php-shirabe-fed0a6e7ac361af9b963c1f62411b1a85478230c.tar.zst
php-shirabe-fed0a6e7ac361af9b963c1f62411b1a85478230c.zip
refactor(preg): add preg_is_match for existence-only call sites
The capture groups were discarded at 162 of the preg_match call sites, which only tested the Option. They now call preg_is_match, which lets the regex engine skip capture tracking. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe-semver/src/version_parser.rs')
-rw-r--r--crates/shirabe-semver/src/version_parser.rs24
1 files changed, 10 insertions, 14 deletions
diff --git a/crates/shirabe-semver/src/version_parser.rs b/crates/shirabe-semver/src/version_parser.rs
index 79c368bb..8d86de2e 100644
--- a/crates/shirabe-semver/src/version_parser.rs
+++ b/crates/shirabe-semver/src/version_parser.rs
@@ -4,7 +4,9 @@ use crate::constraint::AnyConstraint;
use crate::constraint::MatchAllConstraint;
use crate::constraint::MultiConstraint;
use crate::constraint::SimpleConstraint;
-use shirabe_php_shim::{php_regex, preg_match, preg_quote, preg_replace, preg_split};
+use shirabe_php_shim::{
+ php_regex, preg_is_match, preg_match, preg_quote, preg_replace, preg_split,
+};
// Regex to match pre-release data (sort of).
//
@@ -194,30 +196,26 @@ impl VersionParser {
}
}
- let extra_message = if preg_match(
+ let extra_message = if preg_is_match(
format!(
"{{ +as +{}(?:@(?:{}))?$}}",
preg_quote(&version, None),
STABILITIES_REGEX
),
&full_version,
- )
- .is_some()
- {
+ ) {
format!(
" in \"{}\", the alias must be an exact version",
full_version
)
- } else if preg_match(
+ } else if preg_is_match(
format!(
"{{^{}(?:@(?:{}))? +as +}}",
preg_quote(&version, None),
STABILITIES_REGEX
),
&full_version,
- )
- .is_some()
- {
+ ) {
format!(
" in \"{}\", the alias source must be an exact version, if it is a branch name \
you should prefix it with dev-",
@@ -615,7 +613,7 @@ impl VersionParser {
// dev-foobar except if the constraint uses a known operator, in which
// case it must be a parse error
if version_str.ends_with("-dev")
- && preg_match(php_regex!("{^[0-9a-zA-Z-./]+$}"), &version_str).is_some()
+ && preg_is_match(php_regex!("{^[0-9a-zA-Z-./]+$}"), &version_str)
{
self.normalize(
&format!("dev-{}", &version_str[..version_str.len() - 4]),
@@ -640,12 +638,10 @@ impl VersionParser {
}
if op == "<" || op == ">=" {
let modifier_pattern = format!("{{-{}$}}", MODIFIER_REGEX);
- if preg_match(
+ if !preg_is_match(
&modifier_pattern,
&shirabe_php_shim::strtolower(&version_str),
- )
- .is_none()
- && !version_str.starts_with("dev-")
+ ) && !version_str.starts_with("dev-")
{
version = format!("{}-dev", version);
}