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/version_guesser.rs | |
| 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/version_guesser.rs')
| -rw-r--r-- | crates/shirabe/src/package/version/version_guesser.rs | 24 |
1 files changed, 10 insertions, 14 deletions
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())); } |
