aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe-semver
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-08-16 19:06:49 +0900
committernsfisis <nsfisis@gmail.com>2026-08-16 19:07:15 +0900
commitb6604e1395f003748fe40a44e1190470632a40ce (patch)
tree27ce3c137c860a7bd8914852ba5f851e213d448c /crates/shirabe-semver
parentc5605cc072c1880af7d70647278c6aa0de43f402 (diff)
downloadphp-shirabe-b6604e1395f003748fe40a44e1190470632a40ce.tar.gz
php-shirabe-b6604e1395f003748fe40a44e1190470632a40ce.tar.zst
php-shirabe-b6604e1395f003748fe40a44e1190470632a40ce.zip
refactor(preg): import preg_*() instead of qualifying them
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe-semver')
-rw-r--r--crates/shirabe-semver/src/version_parser.rs58
1 files changed, 29 insertions, 29 deletions
diff --git a/crates/shirabe-semver/src/version_parser.rs b/crates/shirabe-semver/src/version_parser.rs
index 287716d9..d0031f04 100644
--- a/crates/shirabe-semver/src/version_parser.rs
+++ b/crates/shirabe-semver/src/version_parser.rs
@@ -4,7 +4,7 @@ use crate::constraint::AnyConstraint;
use crate::constraint::MatchAllConstraint;
use crate::constraint::MultiConstraint;
use crate::constraint::SimpleConstraint;
-use shirabe_php_shim::php_regex;
+use shirabe_php_shim::{php_regex, preg_match, preg_quote, preg_replace, preg_split};
// Regex to match pre-release data (sort of).
//
@@ -25,7 +25,7 @@ pub struct VersionParser;
impl VersionParser {
pub fn parse_stability(version: &str) -> String {
- let version = shirabe_php_shim::preg_replace(php_regex!("{#.+$}"), "", version);
+ let version = preg_replace(php_regex!("{#.+$}"), "", version);
if version.starts_with("dev-") || version.ends_with("-dev") {
return "dev".to_string();
@@ -34,7 +34,7 @@ impl VersionParser {
let pattern = format!("{{{}(?:\\+.*)?$}}i", MODIFIER_REGEX);
let lower = shirabe_php_shim::strtolower(&version);
let mut match_: Vec<Option<String>> = Vec::new();
- shirabe_php_shim::preg_match(&pattern, &lower, &mut match_);
+ preg_match(&pattern, &lower, &mut match_);
// match_[3] = the ([.-]?dev)? capture
if match_
@@ -87,7 +87,7 @@ impl VersionParser {
// strip off aliasing
let mut match_: Vec<Option<String>> = Vec::new();
- if shirabe_php_shim::preg_match(
+ if preg_match(
php_regex!("{^([^,\\s]++) ++as ++([^,\\s]++)$}"),
&version,
&mut match_,
@@ -98,7 +98,7 @@ impl VersionParser {
// strip off stability flag
let stab_pattern = format!("{{@(?:{})$}}i", STABILITIES_REGEX);
let mut match_: Vec<Option<String>> = Vec::new();
- if shirabe_php_shim::preg_match(&stab_pattern, &version, &mut match_) {
+ if preg_match(&stab_pattern, &version, &mut match_) {
let match0_len = match_[0].as_deref().unwrap_or("").len();
version = version[..version.len() - match0_len].to_string();
}
@@ -116,7 +116,7 @@ impl VersionParser {
// strip off build metadata
let mut match_: Vec<Option<String>> = Vec::new();
- if shirabe_php_shim::preg_match(
+ if preg_match(
php_regex!("{^([^,\\s+]++)\\+[^\\s]++$}"),
&version,
&mut match_,
@@ -137,7 +137,7 @@ impl VersionParser {
"{{^v?(\\d{{1,5}})(\\.\\d++)?(\\.\\d++)?(\\.\\d++)?{}$}}i",
MODIFIER_REGEX
);
- if shirabe_php_shim::preg_match(&classical_pattern, &version, &mut matches) {
+ if preg_match(&classical_pattern, &version, &mut matches) {
let m2 = matches[2].as_deref().unwrap_or("");
let m3 = matches[3].as_deref().unwrap_or("");
let m4 = matches[4].as_deref().unwrap_or("");
@@ -155,8 +155,8 @@ impl VersionParser {
"{{^v?(\\d{{4}}(?:[.:-]?\\d{{2}}){{1,6}}(?:[.:-]?\\d{{1,3}}){{0,2}}){}$}}i",
MODIFIER_REGEX
);
- if shirabe_php_shim::preg_match(&datetime_pattern, &version, &mut matches) {
- version = shirabe_php_shim::preg_replace(
+ if preg_match(&datetime_pattern, &version, &mut matches) {
+ version = preg_replace(
php_regex!("{\\D}"),
".",
matches[1].as_deref().unwrap_or(""),
@@ -202,7 +202,7 @@ impl VersionParser {
// match dev branches
let mut match_: Vec<Option<String>> = Vec::new();
- if shirabe_php_shim::preg_match(php_regex!("{(.*?)[.-]?dev$}i"), &version, &mut match_) {
+ if preg_match(php_regex!("{(.*?)[.-]?dev$}i"), &version, &mut match_) {
let branch_name = match_[1].clone().unwrap_or_default();
// a branch ending with -dev is only valid if it is numeric
// if it gets prefixed with dev- it means the branch name should
@@ -214,10 +214,10 @@ impl VersionParser {
}
}
- let extra_message = if shirabe_php_shim::preg_match(
+ let extra_message = if preg_match(
format!(
"{{ +as +{}(?:@(?:{}))?$}}",
- shirabe_php_shim::preg_quote(&version, None),
+ preg_quote(&version, None),
STABILITIES_REGEX
),
&full_version,
@@ -227,10 +227,10 @@ impl VersionParser {
" in \"{}\", the alias must be an exact version",
full_version
)
- } else if shirabe_php_shim::preg_match(
+ } else if preg_match(
format!(
"{{^{}(?:@(?:{}))? +as +}}",
- shirabe_php_shim::preg_quote(&version, None),
+ preg_quote(&version, None),
STABILITIES_REGEX
),
&full_version,
@@ -255,7 +255,7 @@ impl VersionParser {
pub fn parse_numeric_alias_prefix(&self, branch: &str) -> Option<String> {
let mut matches: Vec<Option<String>> = Vec::new();
// matches['version'] == matches[1] ((?P<version>...) is group 1)
- if shirabe_php_shim::preg_match(
+ if preg_match(
php_regex!("{^(?P<version>(\\d++\\.)*\\d++)(?:\\.x)?-dev$}i"),
branch,
&mut matches,
@@ -274,7 +274,7 @@ impl VersionParser {
// Groups: 1=major, 2=".minor"(outer), 3=minor(inner), 4=".patch"(outer),
// 5=patch(inner), 6=".fourth"(outer), 7=fourth(inner).
// We use the outer groups [1,2,4,6] to replicate PHP's groups [1,2,3,4].
- if shirabe_php_shim::preg_match(
+ if preg_match(
php_regex!("{^v?(\\d++)(\\.(\\d++|[xX*]))?(\\.(\\d++|[xX*]))?(\\.(\\d++|[xX*]))?$}i"),
&name,
&mut matches,
@@ -309,7 +309,7 @@ impl VersionParser {
pub fn parse_constraints(&self, constraints: &str) -> anyhow::Result<AnyConstraint> {
let pretty_constraint = constraints.to_string();
- let or_constraints = shirabe_php_shim::preg_split(
+ let or_constraints = preg_split(
php_regex!("{\\s*\\|\\|?\\s*}"),
&shirabe_php_shim::trim(constraints, None),
);
@@ -350,7 +350,7 @@ impl VersionParser {
// strip off aliasing
let mut match_: Vec<Option<String>> = Vec::new();
- if shirabe_php_shim::preg_match(
+ if preg_match(
php_regex!("{^([^,\\s]++) ++as ++([^,\\s]++)$}"),
&constraint,
&mut match_,
@@ -362,7 +362,7 @@ impl VersionParser {
let mut stability_modifier: Option<String> = None;
let mut match_: Vec<Option<String>> = Vec::new();
let stab_pattern = format!("{{^([^,\\s]*?)@({})$}}i", STABILITIES_REGEX);
- if shirabe_php_shim::preg_match(&stab_pattern, &constraint, &mut match_) {
+ if preg_match(&stab_pattern, &constraint, &mut match_) {
let m1 = match_[1].as_deref().unwrap_or("");
constraint = if !m1.is_empty() {
m1.to_string()
@@ -377,7 +377,7 @@ impl VersionParser {
// get rid of #refs as those are used by composer only
let mut match_: Vec<Option<String>> = Vec::new();
- if shirabe_php_shim::preg_match(
+ if preg_match(
php_regex!("{^(dev-[^,\\s@]+?|[^,\\s@]+?\\.x-dev)#.+$}i"),
&constraint,
&mut match_,
@@ -386,7 +386,7 @@ impl VersionParser {
}
let mut match_: Vec<Option<String>> = Vec::new();
- if shirabe_php_shim::preg_match(
+ if preg_match(
php_regex!("{^(v)?[xX*](\\.[xX*])*$}i"),
&constraint,
&mut match_,
@@ -425,7 +425,7 @@ impl VersionParser {
// the current version is used instead.
let mut matches: Vec<Option<String>> = Vec::new();
let tilde_pattern = format!("{{^~>?{}$}}i", version_regex);
- if shirabe_php_shim::preg_match(&tilde_pattern, &constraint, &mut matches) {
+ if preg_match(&tilde_pattern, &constraint, &mut matches) {
if constraint.starts_with("~>") {
anyhow::bail!(
"Could not parse version constraint {}: Invalid operator \"~>\", you probably \
@@ -488,7 +488,7 @@ impl VersionParser {
// and above, patch updates for versions 0.X >=0.1.0, and no updates for versions 0.0.X
let mut matches: Vec<Option<String>> = Vec::new();
let caret_pattern = format!("{{^\\^{}($)}}i", version_regex);
- if shirabe_php_shim::preg_match(&caret_pattern, &constraint, &mut matches) {
+ if preg_match(&caret_pattern, &constraint, &mut matches) {
// Work out which position in the version we are operating at
let m1 = matches[1].as_deref().unwrap_or("");
let m2 = matches[2].as_deref().unwrap_or("");
@@ -536,7 +536,7 @@ impl VersionParser {
// [major, minor, patch] tuple. A partial version range is treated as an X-Range, so the
// special character is in fact optional.
let mut matches: Vec<Option<String>> = Vec::new();
- if shirabe_php_shim::preg_match(
+ if preg_match(
php_regex!("{^v?(\\d++)(?:\\.(\\d++))?(?:\\.(\\d++))?(?:\\.[xX*])++$}"),
&constraint,
&mut matches,
@@ -586,7 +586,7 @@ impl VersionParser {
"{{^(?P<from>{}) +- +(?P<to>{})($)}}i",
version_regex, version_regex
);
- if shirabe_php_shim::preg_match(&hyphen_pattern, &constraint, &mut matches) {
+ if preg_match(&hyphen_pattern, &constraint, &mut matches) {
// matches[1]='from' string, matches[2..9]=from captures, matches[10]='to' string,
// matches[11..18]=to captures, matches[19]='($)'
// matches[6]=from stability, matches[8]=from dev, matches[9]=from wildcard-dev
@@ -652,7 +652,7 @@ impl VersionParser {
// Basic Comparators
let mut match_: Vec<Option<String>> = Vec::new();
- if shirabe_php_shim::preg_match(
+ if preg_match(
php_regex!("{^(<>|!=|>=?|<=?|==?)?\\s*(.*)}"),
&constraint,
&mut match_,
@@ -667,7 +667,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")
- && shirabe_php_shim::preg_match(
+ && preg_match(
php_regex!("{^[0-9a-zA-Z-./]+$}"),
&version_str,
&mut Vec::new(),
@@ -696,7 +696,7 @@ impl VersionParser {
}
if op == "<" || op == ">=" {
let modifier_pattern = format!("{{-{}$}}", MODIFIER_REGEX);
- if !shirabe_php_shim::preg_match(
+ if !preg_match(
&modifier_pattern,
&shirabe_php_shim::strtolower(&version_str),
&mut Vec::new(),
@@ -886,7 +886,7 @@ fn match_and_delimiter(b: &[u8], i: usize) -> Option<usize> {
}
#[cfg(test)]
-mod split_and_constraints_tests {
+mod tests {
use super::split_and_constraints;
fn split(s: &str) -> Vec<String> {