aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/command/init_command.rs
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/src/command/init_command.rs
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/src/command/init_command.rs')
-rw-r--r--crates/shirabe/src/command/init_command.rs18
1 files changed, 6 insertions, 12 deletions
diff --git a/crates/shirabe/src/command/init_command.rs b/crates/shirabe/src/command/init_command.rs
index b316e4fe..3ca6c0fb 100644
--- a/crates/shirabe/src/command/init_command.rs
+++ b/crates/shirabe/src/command/init_command.rs
@@ -24,7 +24,7 @@ use shirabe_php_shim::{
CaptureKey, FILE_IGNORE_NEW_LINES, InvalidArgumentException, PHP_EOL, PHP_SERVER, PhpMixed,
array_flip_strings, array_intersect_key, array_map, basename, empty, explode, file,
file_exists, file_get_contents, file_put_contents, get_current_user, impl_php_class, implode,
- is_dir, is_string, php_regex, preg_match_all, preg_match2, preg_quote, preg_replace, realpath,
+ is_dir, is_string, php_regex, preg_match, preg_match_all, preg_quote, preg_replace, realpath,
str_replace, strpos, strtolower, trim, ucwords,
};
use shirabe_spdx_licenses::SpdxLicenses;
@@ -89,10 +89,9 @@ impl InitCommand {
&self,
author: &str,
) -> anyhow::Result<IndexMap<String, Option<String>>> {
- if let Some(m) = preg_match2(
+ if let Some(m) = preg_match(
php_regex!(r#"/^(?P<name>[- .,\p{L}\p{N}\p{Mn}\'’\"()]+)(?:\s+<(?P<email>.+?)>)?$/u"#),
author,
- 0,
) {
let email = m.name("email").map(str::to_string);
if let Some(ref email) = email
@@ -210,7 +209,7 @@ impl InitCommand {
let lines = file(ignore_file, FILE_IGNORE_NEW_LINES).unwrap_or_default();
for line in &lines {
- if preg_match2(&pattern, line, 0).is_some() {
+ if preg_match(&pattern, line).is_some() {
return true;
}
}
@@ -498,13 +497,12 @@ impl Command for InitCommand {
});
if options.contains_key("name")
- && preg_match2(
+ && preg_match(
php_regex!(r"{^[a-z0-9]([_.-]?[a-z0-9]+)*\/[a-z0-9](([_.]|-{1,2})?[a-z0-9]+)*$}D"),
options
.get("name")
.and_then(|v| v.as_string())
.unwrap_or(""),
- 0,
)
.is_none()
{
@@ -910,11 +908,7 @@ impl Command for InitCommand {
return Ok(PhpMixed::String(name_for_validate.clone()));
}
- if preg_match2(
- php_regex!(r"{^[a-z0-9]([_.-]?[a-z0-9]+)*\/[a-z0-9](([_.]|-{1,2})?[a-z0-9]+)*$}D"),
- value.as_string().unwrap_or(""),
- 0,
- )
+ if preg_match(php_regex!(r"{^[a-z0-9]([_.-]?[a-z0-9]+)*\/[a-z0-9](([_.]|-{1,2})?[a-z0-9]+)*$}D"), value.as_string().unwrap_or(""))
.is_none()
{
return Err(InvalidArgumentException::new(format!(
@@ -1226,7 +1220,7 @@ impl Command for InitCommand {
value_str
};
- if preg_match2(php_regex!(r"{^[^/][A-Za-z0-9\-_/]+/$}"), &value_or_default, 0)
+ if preg_match(php_regex!(r"{^[^/][A-Za-z0-9\-_/]+/$}"), &value_or_default)
.is_none()
{
return Err(InvalidArgumentException::new(format!(