From b6604e1395f003748fe40a44e1190470632a40ce Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 16 Aug 2026 19:06:49 +0900 Subject: refactor(preg): import preg_*() instead of qualifying them Co-Authored-By: Claude Opus 5 (1M context) --- crates/shirabe-symfony-console/src/input/argv_input.rs | 5 ++--- crates/shirabe-symfony-console/src/input/input.rs | 4 ++-- crates/shirabe-symfony-console/src/input/input_option.rs | 4 ++-- crates/shirabe-symfony-console/src/input/string_input.rs | 16 +++++----------- 4 files changed, 11 insertions(+), 18 deletions(-) (limited to 'crates/shirabe-symfony-console/src/input') diff --git a/crates/shirabe-symfony-console/src/input/argv_input.rs b/crates/shirabe-symfony-console/src/input/argv_input.rs index 200c7384..b2b663a6 100644 --- a/crates/shirabe-symfony-console/src/input/argv_input.rs +++ b/crates/shirabe-symfony-console/src/input/argv_input.rs @@ -6,7 +6,7 @@ use crate::input::InputDefinition; use crate::input::InputInterface; use crate::input::StreamableInputInterface; use indexmap::IndexMap; -use shirabe_php_shim::{PhpMixed, php_regex}; +use shirabe_php_shim::{PhpMixed, php_regex, preg_match}; /// ArgvInput represents an input coming from the CLI arguments. /// @@ -524,8 +524,7 @@ impl std::fmt::Display for ArgvInput { .iter() .map(|token| { let mut r#match: Vec> = Vec::new(); - if shirabe_php_shim::preg_match(php_regex!("{^(-[^=]+=)(.+)}"), token, &mut r#match) - { + if preg_match(php_regex!("{^(-[^=]+=)(.+)}"), token, &mut r#match) { return format!( "{}{}", r#match[1].as_deref().unwrap_or(""), diff --git a/crates/shirabe-symfony-console/src/input/input.rs b/crates/shirabe-symfony-console/src/input/input.rs index 7744a4f1..89eedb03 100644 --- a/crates/shirabe-symfony-console/src/input/input.rs +++ b/crates/shirabe-symfony-console/src/input/input.rs @@ -4,7 +4,7 @@ use crate::exception::InvalidArgumentException; use crate::exception::RuntimeException; use crate::input::InputDefinition; use indexmap::IndexMap; -use shirabe_php_shim::{PhpMixed, PhpResource, php_regex}; +use shirabe_php_shim::{PhpMixed, PhpResource, php_regex, preg_match}; /// Input is the base class for all concrete Input classes. /// @@ -208,7 +208,7 @@ impl Input { /// Escapes a token through escapeshellarg if it contains unsafe chars. pub fn escape_token(&self, token: &str) -> String { let mut matches: Vec> = vec![]; - if shirabe_php_shim::preg_match(php_regex!("{^[\\w-]+$}"), token, &mut matches) { + if preg_match(php_regex!("{^[\\w-]+$}"), token, &mut matches) { token.to_string() } else { shirabe_php_shim::escapeshellarg(token) diff --git a/crates/shirabe-symfony-console/src/input/input_option.rs b/crates/shirabe-symfony-console/src/input/input_option.rs index 6734f374..3b24d914 100644 --- a/crates/shirabe-symfony-console/src/input/input_option.rs +++ b/crates/shirabe-symfony-console/src/input/input_option.rs @@ -2,7 +2,7 @@ use crate::exception::InvalidArgumentException; use crate::exception::LogicException; -use shirabe_php_shim::{PhpMixed, php_regex}; +use shirabe_php_shim::{PhpMixed, php_regex, preg_split}; #[derive(Debug, Clone)] pub struct InputOption { @@ -99,7 +99,7 @@ impl InputOption { fn normalize_shortcut(s: String) -> anyhow::Result> { let stripped = shirabe_php_shim::ltrim(&s, Some("-")); - let parts = shirabe_php_shim::preg_split(php_regex!(r"{(\|)-?}"), &stripped); + let parts = preg_split(php_regex!(r"{(\|)-?}"), &stripped); let filtered: Vec = shirabe_php_shim::array_filter(&parts, |s: &String| !s.is_empty()); let result = shirabe_php_shim::implode("|", &filtered); diff --git a/crates/shirabe-symfony-console/src/input/string_input.rs b/crates/shirabe-symfony-console/src/input/string_input.rs index 453bca45..1ec6e853 100644 --- a/crates/shirabe-symfony-console/src/input/string_input.rs +++ b/crates/shirabe-symfony-console/src/input/string_input.rs @@ -6,7 +6,7 @@ use crate::input::InputDefinition; use crate::input::InputInterface; use crate::input::StreamableInputInterface; use indexmap::IndexMap; -use shirabe_php_shim::{CaptureKey, PhpMixed, php_regex}; +use shirabe_php_shim::{CaptureKey, PhpMixed, php_regex, preg_match2}; /// StringInput represents an input provided as a string. /// @@ -58,19 +58,13 @@ impl StringInput { } let mut m: IndexMap> = IndexMap::new(); - if shirabe_php_shim::preg_match2( - php_regex!(r"/\s+/A"), - input, - &mut m, - 0, - cursor as usize, - ) { + if preg_match2(php_regex!(r"/\s+/A"), input, &mut m, 0, cursor as usize) { if token.is_some() { tokens.push(token.take().unwrap()); } cursor += shirabe_php_shim::strlen(m[&CaptureKey::ByIndex(0)].as_deref().unwrap_or("")); - } else if shirabe_php_shim::preg_match2( + } else if preg_match2( format!(r#"/([^="'\s]+?)(=?)({}+)/A"#, Self::REGEX_QUOTED_STRING), input, &mut m, @@ -93,7 +87,7 @@ impl StringInput { )); cursor += shirabe_php_shim::strlen(m[&CaptureKey::ByIndex(0)].as_deref().unwrap_or("")); - } else if shirabe_php_shim::preg_match2( + } else if preg_match2( format!(r"/{}/A", Self::REGEX_QUOTED_STRING), input, &mut m, @@ -111,7 +105,7 @@ impl StringInput { )); cursor += shirabe_php_shim::strlen(m[&CaptureKey::ByIndex(0)].as_deref().unwrap_or("")); - } else if shirabe_php_shim::preg_match2( + } else if preg_match2( format!(r"/{}/A", Self::REGEX_UNQUOTED_STRING), input, &mut m, -- cgit v1.3.1-4-g156e