aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe-class-map-generator
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
commite093b2be1c333e67c96aebb0a5291bea9ae3d6db (patch)
tree0743fad689f419959c3a898605e21485087884fa /crates/shirabe-class-map-generator
parent050c56ef263d90d862ef565bc1762909110e02eb (diff)
downloadphp-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-class-map-generator')
-rw-r--r--crates/shirabe-class-map-generator/src/class_map.rs4
-rw-r--r--crates/shirabe-class-map-generator/src/class_map_generator.rs11
2 files changed, 7 insertions, 8 deletions
diff --git a/crates/shirabe-class-map-generator/src/class_map.rs b/crates/shirabe-class-map-generator/src/class_map.rs
index 982d8494..1d980129 100644
--- a/crates/shirabe-class-map-generator/src/class_map.rs
+++ b/crates/shirabe-class-map-generator/src/class_map.rs
@@ -1,7 +1,7 @@
//! ref: composer/vendor/composer/class-map-generator/src/ClassMap.php
use indexmap::IndexMap;
-use shirabe_php_shim::{OutOfBoundsException, preg_match2, rtrim, strpos, strtr};
+use shirabe_php_shim::{OutOfBoundsException, preg_match, rtrim, strpos, strtr};
#[derive(Debug, Clone)]
pub struct PsrViolationEntry {
@@ -66,7 +66,7 @@ impl ClassMap {
for (class, paths) in &self.ambiguous_classes {
let paths: Vec<String> = paths
.iter()
- .filter(|path| preg_match2(duplicates_filter, &strtr(path, "\\", "/"), 0).is_none())
+ .filter(|path| preg_match(duplicates_filter, &strtr(path, "\\", "/")).is_none())
.cloned()
.collect();
if !paths.is_empty() {
diff --git a/crates/shirabe-class-map-generator/src/class_map_generator.rs b/crates/shirabe-class-map-generator/src/class_map_generator.rs
index c4130cff..da2f62c5 100644
--- a/crates/shirabe-class-map-generator/src/class_map_generator.rs
+++ b/crates/shirabe-class-map-generator/src/class_map_generator.rs
@@ -5,7 +5,7 @@ use crate::file_list::FileList;
use crate::php_file_parser::PhpFileParser;
use shirabe_php_shim::{
InvalidArgumentException, LogicException, PATHINFO_EXTENSION, RuntimeException, explode,
- getcwd, implode, is_dir, is_file, pathinfo, php_regex, preg_match2, preg_quote, preg_replace,
+ getcwd, implode, is_dir, is_file, pathinfo, php_regex, preg_match, preg_quote, preg_replace,
preg_replace_callback, realpath, str_replace, stream_get_wrappers, strlen, strpos, strrpos,
strtr, substr,
};
@@ -135,7 +135,7 @@ impl ClassMapGenerator {
}
let is_stream_wrapper_path =
- preg_match2(&self.stream_wrappers_regex, &file_path, 0).is_some();
+ preg_match(&self.stream_wrappers_regex, &file_path).is_some();
if !Self::is_absolute_path(&file_path) && !is_stream_wrapper_path {
file_path = format!("{}/{}", cwd, file_path);
file_path = Self::normalize_path(&file_path);
@@ -183,11 +183,11 @@ impl ClassMapGenerator {
// check the realpath of the file against the excluded paths as the path might be a symlink and the excluded path is realpath'd so symlink are resolved
if let Some(ref excluded) = excluded {
- if preg_match2(excluded, &strtr(&real_path, "\\", "/"), 0).is_some() {
+ if preg_match(excluded, &strtr(&real_path, "\\", "/")).is_some() {
continue;
}
// check non-realpath of file for directories symlink in project dir
- if preg_match2(excluded, &strtr(&file_path, "\\", "/"), 0).is_some() {
+ if preg_match(excluded, &strtr(&file_path, "\\", "/")).is_some() {
continue;
}
}
@@ -348,10 +348,9 @@ impl ClassMapGenerator {
}
// extract a prefix being a protocol://, protocol:, protocol://drive: or simply drive:
- if let Some(r#match) = preg_match2(
+ if let Some(r#match) = preg_match(
php_regex!(r"{^( [0-9a-z]{2,}+: (?: // (?: [a-z]: )? )? | [a-z]: )}ix"),
&path,
- 0,
) {
prefix = r#match.get(1).unwrap_or_default().to_string();
path = substr(&path, strlen(&prefix), None);