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/loader | |
| 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/loader')
3 files changed, 16 insertions, 19 deletions
diff --git a/crates/shirabe/src/package/loader/array_loader.rs b/crates/shirabe/src/package/loader/array_loader.rs index b6b5ac1e..00f9026e 100644 --- a/crates/shirabe/src/package/loader/array_loader.rs +++ b/crates/shirabe/src/package/loader/array_loader.rs @@ -19,7 +19,7 @@ use chrono::Utc; use indexmap::IndexMap; use shirabe_php_shim::{ AnyThrowable, E_USER_DEPRECATED, PhpMixed, UnexpectedValueException, is_scalar, is_string, - json_encode, ltrim, php_regex, preg_match2, preg_replace, stripos, strpos, strtolower, strval, + json_encode, ltrim, php_regex, preg_match, preg_replace, stripos, strpos, strtolower, strval, substr, trigger_error, trim, }; @@ -339,7 +339,7 @@ impl ArrayLoader { && !shirabe_php_shim::empty(time_value) { let time_str = time_value.as_string().unwrap_or(""); - let time = if preg_match2(php_regex!(r"/^\d++$/D"), time_str, 0).is_some() { + let time = if preg_match(php_regex!(r"/^\d++$/D"), time_str).is_some() { format!("@{}", time_str) } else { time_str.to_string() diff --git a/crates/shirabe/src/package/loader/root_package_loader.rs b/crates/shirabe/src/package/loader/root_package_loader.rs index bc49ffc0..491961a6 100644 --- a/crates/shirabe/src/package/loader/root_package_loader.rs +++ b/crates/shirabe/src/package/loader/root_package_loader.rs @@ -16,7 +16,7 @@ use crate::util::Platform; use crate::util::ProcessExecutor; use indexmap::IndexMap; use shirabe_php_shim::{ - PhpMixed, RuntimeException, UnexpectedValueException, php_regex, preg_match2, preg_replace, + PhpMixed, RuntimeException, UnexpectedValueException, php_regex, preg_match, preg_replace, preg_split, strtolower, }; @@ -252,10 +252,9 @@ impl RootPackageLoader { mut aliases: Vec<IndexMap<String, String>>, ) -> Vec<IndexMap<String, String>> { for (req_name, req_version) in requires { - if let Some(m) = preg_match2( + if let Some(m) = preg_match( php_regex!(r"{(?:^|\| *|, *)([^,\s#|]+)(?:#[^ ]+)? +as +([^,\s|]+)(?:$| *\|| *,)}"), req_version, - 0, ) { let m1 = m.get(1).unwrap_or_default().to_string(); let m2 = m.get(2).unwrap_or_default().to_string(); @@ -317,7 +316,7 @@ impl RootPackageLoader { let mut matched = false; for constraint in &constraints { - if let Some(m) = preg_match2(&pattern, constraint, 0) { + if let Some(m) = preg_match(&pattern, constraint) { let name = strtolower(req_name); let m1 = m.get(1).unwrap_or_default().to_string(); let normalized_m1 = VersionParser::normalize_stability(&m1).unwrap_or_default(); @@ -338,7 +337,7 @@ impl RootPackageLoader { for constraint in &constraints { let req_version_stripped = preg_replace(php_regex!(r"{^([^,\s@]+) as .+$}"), "$1", constraint); - if preg_match2(php_regex!(r"{^[^,\s@]+$}"), &req_version_stripped, 0).is_some() { + if preg_match(php_regex!(r"{^[^,\s@]+$}"), &req_version_stripped).is_some() { let stability_name = VersionParser::parse_stability(&req_version_stripped); if stability_name != "stable" { let name = strtolower(req_name); @@ -363,7 +362,7 @@ impl RootPackageLoader { ) -> IndexMap<String, String> { for (req_name, req_version) in requires { let req_version = preg_replace(php_regex!(r"{^([^,\s@]+) as .+$}"), "$1", req_version); - if let Some(m) = preg_match2(php_regex!(r"{^[^,\s@]+?#([a-f0-9]+)$}"), &req_version, 0) + if let Some(m) = preg_match(php_regex!(r"{^[^,\s@]+?#([a-f0-9]+)$}"), &req_version) && VersionParser::parse_stability(&req_version) == "dev" { let name = strtolower(req_name); diff --git a/crates/shirabe/src/package/loader/validating_array_loader.rs b/crates/shirabe/src/package/loader/validating_array_loader.rs index 5ac1a929..e893756a 100644 --- a/crates/shirabe/src/package/loader/validating_array_loader.rs +++ b/crates/shirabe/src/package/loader/validating_array_loader.rs @@ -10,7 +10,7 @@ use indexmap::IndexMap; use shirabe_php_shim::{ CmpOp, E_USER_DEPRECATED, PHP_EOL, PhpMixed, array_intersect_key, array_values, filter_var_email, get_debug_type, is_array, is_bool, is_int, is_numeric, is_scalar, is_string, - json_encode, parse_url, php_regex, php_to_string, preg_match2, preg_replace, str_replace, + json_encode, parse_url, php_regex, php_to_string, preg_match, preg_replace, str_replace, strcasecmp, strtolower, strtotime, substr, trigger_error, trim, var_export, }; use shirabe_semver::Intervals; @@ -73,12 +73,11 @@ impl ValidatingArrayLoader { return None; } - if preg_match2( + if preg_match( php_regex!( "{^[a-z0-9](?:[_.-]?[a-z0-9]++)*+/[a-z0-9](?:(?:[_.]|-{1,2})?[a-z0-9]++)*+$}iD" ), name, - 0, ) .is_none() { @@ -102,14 +101,14 @@ impl ValidatingArrayLoader { )); } - if preg_match2(php_regex!("{\\.json$}"), name, 0).is_some() { + if preg_match(php_regex!("{\\.json$}"), name).is_some() { return Some(format!( "{} is invalid, package names can not end in .json, consider renaming it or perhaps using a -json suffix instead.", name )); } - if preg_match2(php_regex!("{[A-Z]}"), name, 0).is_some() { + if preg_match(php_regex!("{[A-Z]}"), name).is_some() { if is_link { return Some(format!( "{} is invalid, it should not contain uppercase characters. Please use {} instead.", @@ -143,7 +142,7 @@ impl ValidatingArrayLoader { .as_string() .unwrap_or("") .to_string(); - if preg_match2(format!("{{^{}$}}u", regex), &value, 0).is_none() { + if preg_match(format!("{{^{}$}}u", regex), &value).is_none() { let message = format!( "{} : invalid value ({}), must match {}", property, value, regex @@ -258,7 +257,7 @@ impl ValidatingArrayLoader { if let Some(regex_str) = regex { let value_str = php_to_string(&value); - if preg_match2(format!("{{^{}$}}u", regex_str), &value_str, 0).is_none() { + if preg_match(format!("{{^{}$}}u", regex_str), &value_str).is_none() { self.warnings.borrow_mut().push(format!( "{}.{} : invalid value ({}), must match {}", property, key, value_str, regex_str @@ -1187,8 +1186,7 @@ impl LoaderInterface for ValidatingArrayLoader { self.warnings .borrow_mut() .push(format!("{}.{}", link_type, err)); - } else if preg_match2(php_regex!("{^[A-Za-z0-9_./-]+$}"), &package, 0).is_none() - { + } else if preg_match(php_regex!("{^[A-Za-z0-9_./-]+$}"), &package).is_none() { self.errors.borrow_mut().push(format!( "{}.{} : invalid key, package names must be strings containing only [A-Za-z0-9_./-]", link_type, package @@ -1451,7 +1449,7 @@ impl LoaderInterface for ValidatingArrayLoader { } if let Some(ref_val) = section.get("reference").filter(|_| isset("reference")) { let ref_str = php_to_string(ref_val); - if preg_match2(php_regex!("{^\\s*-}"), &ref_str, 0).is_some() { + if preg_match(php_regex!("{^\\s*-}"), &ref_str).is_some() { self.errors.borrow_mut().push(format!( "{}.reference : must not start with a \"-\", \"{}\" given", src_type, ref_str @@ -1460,7 +1458,7 @@ impl LoaderInterface for ValidatingArrayLoader { } if let Some(url_val) = section.get("url").filter(|_| isset("url")) { let url_str = php_to_string(url_val); - if preg_match2(php_regex!("{^\\s*-}"), &url_str, 0).is_some() { + if preg_match(php_regex!("{^\\s*-}"), &url_str).is_some() { self.errors.borrow_mut().push(format!( "{}.url : must not start with a \"-\", \"{}\" given", src_type, url_str |
