diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-08-18 01:57:02 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-08-18 01:57:02 +0900 |
| commit | e093b2be1c333e67c96aebb0a5291bea9ae3d6db (patch) | |
| tree | 0743fad689f419959c3a898605e21485087884fa /crates/shirabe/src/package/version | |
| parent | 050c56ef263d90d862ef565bc1762909110e02eb (diff) | |
| download | php-shirabe-e093b2be1c333e67c96aebb0a5291bea9ae3d6db.tar.gz php-shirabe-e093b2be1c333e67c96aebb0a5291bea9ae3d6db.tar.zst php-shirabe-e093b2be1c333e67c96aebb0a5291bea9ae3d6db.zip | |
refactor(preg): drop the offset argument from preg_match
Every call site but one passed offset 0. The remaining one, the UTF-8
chunking loop in Application, slices the subject instead: its pattern has
no anchor or lookaround, so matching a suffix is equivalent to starting
the search at that offset.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/package/version')
4 files changed, 16 insertions, 21 deletions
diff --git a/crates/shirabe/src/package/version/version_bumper.rs b/crates/shirabe/src/package/version/version_bumper.rs index 50808916..e75dea33 100644 --- a/crates/shirabe/src/package/version/version_bumper.rs +++ b/crates/shirabe/src/package/version/version_bumper.rs @@ -6,7 +6,7 @@ use crate::package::loader::ArrayLoader; use crate::package::version::VersionParser; use crate::util::Platform; use shirabe_php_shim::{ - CaptureKey, php_regex, preg_match_all_offset_capture, preg_match2, preg_replace, + CaptureKey, php_regex, preg_match, preg_match_all_offset_capture, preg_replace, }; use shirabe_semver::Intervals; use shirabe_semver::constraint::AnyConstraint; @@ -51,7 +51,7 @@ impl VersionBumper { preg_replace(php_regex!(r"{(?:\.(?:0|9999999))+(-dev)?$}"), "", &version); let new_pretty_constraint = format!("^{}", version_without_suffix); - if preg_match2(php_regex!(r"{^\^\d+(\.\d+)*$}"), &new_pretty_constraint, 0).is_none() { + if preg_match(php_regex!(r"{^\^\d+(\.\d+)*$}"), &new_pretty_constraint).is_none() { return Ok(pretty_constraint); } diff --git a/crates/shirabe/src/package/version/version_guesser.rs b/crates/shirabe/src/package/version/version_guesser.rs index fd7fe389..668fce02 100644 --- a/crates/shirabe/src/package/version/version_guesser.rs +++ b/crates/shirabe/src/package/version/version_guesser.rs @@ -14,7 +14,7 @@ use crate::util::sync_executor; use indexmap::IndexMap; use shirabe_php_shim::{ PhpMixed, RuntimeException, array_keys, array_map, array_merge, empty, function_exists, - implode, is_string, json_encode, php_regex, preg_match2, preg_quote, preg_replace, str_replace, + implode, is_string, json_encode, php_regex, preg_match, preg_quote, preg_replace, str_replace, strlen, strnatcasecmp, strpos, substr, trim, usort, }; @@ -156,10 +156,9 @@ impl VersionGuesser { } if "-dev" == substr(version_data.version.as_deref().unwrap_or(""), -4, None) - && preg_match2( + && preg_match( php_regex!(r"{\.9{7}}"), version_data.version.as_deref().unwrap_or(""), - 0, ) .is_some() { @@ -182,10 +181,9 @@ impl VersionGuesser { -4, None, ) - && preg_match2( + && preg_match( php_regex!(r"{\.9{7}}"), version_data.feature_version.as_deref().unwrap_or(""), - 0, ) .is_some() { @@ -232,12 +230,11 @@ impl VersionGuesser { // find current branch and collect all branch names for branch in self.process.borrow().split_lines(&output) { if !branch.is_empty() - && let Some(m) = preg_match2( + && let Some(m) = preg_match( php_regex!( r"{^(?:\* ) *(\(no branch\)|\(detached from \S+\)|\(HEAD detached at \S+\)|\S+) *([a-f0-9]+) .*$}" ), &branch, - 0, ) { let g1 = m.get(1).unwrap_or_default().to_string(); @@ -260,13 +257,12 @@ impl VersionGuesser { } if !branch.is_empty() - && preg_match2(php_regex!(r"{^ *.+/HEAD }"), &branch, 0).is_none() - && let Some(m) = preg_match2( + && preg_match(php_regex!(r"{^ *.+/HEAD }"), &branch).is_none() + && let Some(m) = preg_match( php_regex!( r"{^(?:\* )? *((?:remotes/(?:origin|upstream)/)?[^\s/]+) *([a-f0-9]+) .*$}" ), &branch, - 0, ) { branches.push(m.get(1).unwrap_or_default().to_string()); @@ -612,10 +608,10 @@ impl VersionGuesser { non_feature_branches = implode("|", &names); } - preg_match2(format!( + preg_match(format!( r"{{^({}|master|main|latest|next|current|support|tip|trunk|default|develop|\d+\..+)$}}", non_feature_branches, - ), branch_name.unwrap_or(""), 0).is_none() + ), branch_name.unwrap_or("")).is_none() } fn guess_fossil_version(&mut self, path: &str) -> anyhow::Result<VersionData> { @@ -698,7 +694,7 @@ impl VersionGuesser { trunk_path, branches_path, tags_path, ); - if let Some(matches) = preg_match2(&url_pattern, &output, 0) { + if let Some(matches) = preg_match(&url_pattern, &output) { let m1 = matches.get(1).unwrap_or_default(); let m2 = matches.get(2); let m3 = matches.get(3); @@ -751,7 +747,7 @@ impl VersionGuesser { .into()); } }; - if let Some(m) = preg_match2(php_regex!(r"{^(\d+(?:\.\d+)*)-dev$}i"), &version, 0) { + if let Some(m) = preg_match(php_regex!(r"{^(\d+(?:\.\d+)*)-dev$}i"), &version) { return Ok(format!("{}.x-dev", m.get(1).unwrap_or_default())); } diff --git a/crates/shirabe/src/package/version/version_parser.rs b/crates/shirabe/src/package/version/version_parser.rs index ad1a05cf..6e7c5825 100644 --- a/crates/shirabe/src/package/version/version_parser.rs +++ b/crates/shirabe/src/package/version/version_parser.rs @@ -2,7 +2,7 @@ use crate::repository::PlatformRepository; use indexmap::IndexMap; -use shirabe_php_shim::{php_regex, preg_match2, preg_replace}; +use shirabe_php_shim::{php_regex, preg_match, preg_replace}; use shirabe_semver::Semver; use shirabe_semver::VersionParser as SemverVersionParser; use shirabe_semver::constraint::AnyConstraint; @@ -57,10 +57,9 @@ impl VersionParser { if !pair.contains(' ') && i + 1 < count && !pairs[i + 1].contains('/') - && preg_match2( + && preg_match( php_regex!(r"{(?<=[a-z0-9_/-])\*|\*(?=[a-z0-9_/-])}i"), &pairs[i + 1], - 0, ) .is_none() && !PlatformRepository::is_platform_package(&pairs[i + 1]) diff --git a/crates/shirabe/src/package/version/version_selector.rs b/crates/shirabe/src/package/version/version_selector.rs index c7b7b31e..91929c40 100644 --- a/crates/shirabe/src/package/version/version_selector.rs +++ b/crates/shirabe/src/package/version/version_selector.rs @@ -16,7 +16,7 @@ use crate::repository::PlatformRepository; use crate::repository::RepositoryInterface; use crate::repository::RepositorySetInterface; use indexmap::IndexMap; -use shirabe_php_shim::{CmpOp, php_regex, preg_match2, preg_replace, strtolower, version_compare}; +use shirabe_php_shim::{CmpOp, php_regex, preg_match, preg_replace, strtolower, version_compare}; use shirabe_semver::constraint::AnyConstraint; use shirabe_semver::constraint::SimpleConstraint; @@ -302,7 +302,7 @@ impl VersionSelector { let semantic_version_parts: Vec<&str> = version.split('.').collect(); if semantic_version_parts.len() == 4 - && preg_match2(php_regex!(r"{^\d+\D?}"), semantic_version_parts[3], 0).is_some() + && preg_match(php_regex!(r"{^\d+\D?}"), semantic_version_parts[3]).is_some() { let mut parts: Vec<String> = semantic_version_parts .iter() |
