diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-08-16 19:06:49 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-08-16 19:07:15 +0900 |
| commit | b6604e1395f003748fe40a44e1190470632a40ce (patch) | |
| tree | 27ce3c137c860a7bd8914852ba5f851e213d448c /crates/shirabe-symfony-console/src | |
| parent | c5605cc072c1880af7d70647278c6aa0de43f402 (diff) | |
| download | php-shirabe-b6604e1395f003748fe40a44e1190470632a40ce.tar.gz php-shirabe-b6604e1395f003748fe40a44e1190470632a40ce.tar.zst php-shirabe-b6604e1395f003748fe40a44e1190470632a40ce.zip | |
refactor(preg): import preg_*() instead of qualifying them
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe-symfony-console/src')
13 files changed, 43 insertions, 58 deletions
diff --git a/crates/shirabe-symfony-console/src/command/command.rs b/crates/shirabe-symfony-console/src/command/command.rs index 6f25595b..b2af47e2 100644 --- a/crates/shirabe-symfony-console/src/command/command.rs +++ b/crates/shirabe-symfony-console/src/command/command.rs @@ -11,7 +11,7 @@ use crate::input::InputInterface; use crate::input::InputOption; use crate::output::OutputInterface; use indexmap::IndexMap; -use shirabe_php_shim::{PhpMixed, php_regex}; +use shirabe_php_shim::{PhpMixed, php_regex, preg_match}; use std::cell::{Cell, Ref}; /// The base-class state of the PHP `Command` class. @@ -109,8 +109,7 @@ impl CommandData { /// Throws InvalidArgumentException when the name is invalid. fn validate_name(&self, name: &str) -> anyhow::Result<Result<(), InvalidArgumentException>> { let mut matches: Vec<Option<String>> = Vec::new(); - if !shirabe_php_shim::preg_match(php_regex!(r"/^[^\:]++(\:[^\:]++)*$/"), name, &mut matches) - { + if !preg_match(php_regex!(r"/^[^\:]++(\:[^\:]++)*$/"), name, &mut matches) { return Ok(Err(InvalidArgumentException::new(format!( "Command name \"{}\" is invalid.", name diff --git a/crates/shirabe-symfony-console/src/completion/completion_input.rs b/crates/shirabe-symfony-console/src/completion/completion_input.rs index a0adff6c..2f146a39 100644 --- a/crates/shirabe-symfony-console/src/completion/completion_input.rs +++ b/crates/shirabe-symfony-console/src/completion/completion_input.rs @@ -3,7 +3,7 @@ use crate::input::ArgvInput; use crate::input::InputDefinition; use crate::input::InputOption; -use shirabe_php_shim::{PhpMixed, php_regex}; +use shirabe_php_shim::{PhpMixed, php_regex, preg_match_all}; /// An input specialized for shell completion. /// @@ -29,7 +29,7 @@ impl CompletionInput { /// /// This is required for shell completions without COMP_WORDS support. pub fn from_string(input_str: &str, current_index: i64) -> anyhow::Result<Self> { - let tokens = shirabe_php_shim::preg_match_all( + let tokens = preg_match_all( php_regex!("/(?<=^|\\s)(['\"]?)(.+?)(?<!\\\\)\\1(?=$|\\s)/"), input_str, ); diff --git a/crates/shirabe-symfony-console/src/formatter/output_formatter.rs b/crates/shirabe-symfony-console/src/formatter/output_formatter.rs index 960187d4..4943e65b 100644 --- a/crates/shirabe-symfony-console/src/formatter/output_formatter.rs +++ b/crates/shirabe-symfony-console/src/formatter/output_formatter.rs @@ -6,7 +6,10 @@ use crate::formatter::output_formatter_style::OutputFormatterStyle; use crate::formatter::output_formatter_style_interface::OutputFormatterStyleInterface; use crate::formatter::output_formatter_style_stack::OutputFormatterStyleStack; use crate::formatter::wrappable_output_formatter_interface::WrappableOutputFormatterInterface; -use shirabe_php_shim::php_regex; +use shirabe_php_shim::{ + php_regex, preg_match, preg_match_all, preg_match_all_offset_capture, preg_match_all_set_order, + preg_replace, +}; use shirabe_symfony_string::b; /// Formatter class for console output. @@ -25,8 +28,7 @@ pub struct OutputFormatter { impl OutputFormatter { /// Escapes "<" and ">" special chars in given text. pub fn escape(text: &str) -> anyhow::Result<String> { - let text = - shirabe_php_shim::preg_replace(php_regex!("/([^\\\\]|^)([<>])/"), "$1\\\\$2", text); + let text = preg_replace(php_regex!("/([^\\\\]|^)([<>])/"), "$1\\\\$2", text); Ok(Self::escape_trailing_backslash(&text)) } @@ -108,11 +110,7 @@ impl OutputFormatter { } let mut matches: Vec<Vec<String>> = vec![]; - if shirabe_php_shim::preg_match_all_set_order( - php_regex!("/([^=]+)=([^;]+)(;|$)/"), - string, - &mut matches, - ) == 0 + if preg_match_all_set_order(php_regex!("/([^=]+)=([^;]+)(;|$)/"), string, &mut matches) == 0 { return Ok(None); } @@ -128,11 +126,10 @@ impl OutputFormatter { } else if r#match[0] == "bg" { style.set_background(Some(&shirabe_php_shim::strtolower(&r#match[1]))); } else if r#match[0] == "href" { - let url = - shirabe_php_shim::preg_replace(php_regex!("{\\\\([<>])}"), "$1", &r#match[1]); + let url = preg_replace(php_regex!("{\\\\([<>])}"), "$1", &r#match[1]); style.set_href(&url); } else if r#match[0] == "options" { - let mut options = shirabe_php_shim::preg_match_all( + let mut options = preg_match_all( php_regex!("([^,;]+)"), &shirabe_php_shim::strtolower(&r#match[1]), ); @@ -184,7 +181,7 @@ impl OutputFormatter { } let mut matches: Vec<Option<String>> = vec![]; - shirabe_php_shim::preg_match(php_regex!("~(\\n)$~"), &text, &mut matches); + preg_match(php_regex!("~(\\n)$~"), &text, &mut matches); text = format!("{}{}", prefix, self.add_line_breaks(&text, width)); let trailing = matches.get(1).and_then(|m| m.clone()).unwrap_or_default(); text = format!("{}{}", shirabe_php_shim::rtrim(&text, Some("\n")), trailing); @@ -294,7 +291,7 @@ impl WrappableOutputFormatterInterface for OutputFormatter { let close_tag_regex = "[a-z][^<>]*"; let mut current_line_length: i64 = 0; let mut matches: shirabe_php_shim::PregOffsetCaptureMatches = Default::default(); - shirabe_php_shim::preg_match_all_offset_capture( + preg_match_all_offset_capture( format!("#<(({open_tag_regex}) | /({close_tag_regex})?)>#ix"), message, &mut matches, diff --git a/crates/shirabe-symfony-console/src/helper/helper.rs b/crates/shirabe-symfony-console/src/helper/helper.rs index 4f0447f3..21f20d34 100644 --- a/crates/shirabe-symfony-console/src/helper/helper.rs +++ b/crates/shirabe-symfony-console/src/helper/helper.rs @@ -2,7 +2,7 @@ use crate::formatter::OutputFormatterInterface; use crate::helper::HelperSet; -use shirabe_php_shim::php_regex; +use shirabe_php_shim::{php_regex, preg_match, preg_replace}; use shirabe_symfony_string::unicode_string::UnicodeString; /// Helper is the base class for all helper classes. @@ -40,7 +40,7 @@ impl Helper { /// Returns the width of a string, using mb_strwidth if it is available. /// The width is how many characters positions the string will use. pub fn width(string: &str) -> i64 { - if shirabe_php_shim::preg_match(php_regex!("//u"), string, &mut Vec::new()) { + if preg_match(php_regex!("//u"), string, &mut Vec::new()) { return UnicodeString::new(string).width(false); } @@ -56,7 +56,7 @@ impl Helper { /// Returns the length of a string, using mb_strlen if it is available. /// The length is related to how many bytes the string will use. pub fn length(string: &str) -> i64 { - if shirabe_php_shim::preg_match(php_regex!("//u"), string, &mut Vec::new()) { + if preg_match(php_regex!("//u"), string, &mut Vec::new()) { return UnicodeString::new(string).length(); } @@ -148,9 +148,9 @@ impl Helper { // remove <...> formatting let string = formatter.format(Some(string)).unwrap().unwrap_or_default(); // remove already formatted characters - let string = shirabe_php_shim::preg_replace(php_regex!("/\u{1b}\\[[^m]*m/"), "", &string); + let string = preg_replace(php_regex!("/\u{1b}\\[[^m]*m/"), "", &string); // remove terminal hyperlinks - let string = shirabe_php_shim::preg_replace( + let string = preg_replace( php_regex!("/\u{1b}]8;[^;]*;[^\u{1b}]*\u{1b}\\\\/"), "", &string, diff --git a/crates/shirabe-symfony-console/src/helper/progress_bar.rs b/crates/shirabe-symfony-console/src/helper/progress_bar.rs index dea1c3ad..1158c507 100644 --- a/crates/shirabe-symfony-console/src/helper/progress_bar.rs +++ b/crates/shirabe-symfony-console/src/helper/progress_bar.rs @@ -9,7 +9,7 @@ use crate::output::OutputInterface; use crate::output::output_interface; use crate::terminal::Terminal; use indexmap::IndexMap; -use shirabe_php_shim::CaptureKey; +use shirabe_php_shim::{CaptureKey, preg_replace_callback}; pub const FORMAT_VERBOSE: &str = "verbose"; pub const FORMAT_VERY_VERBOSE: &str = "very_verbose"; @@ -831,6 +831,6 @@ impl ProgressBar { }) }; - shirabe_php_shim::preg_replace_callback(regex, callback, &format) + preg_replace_callback(regex, callback, &format) } } 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<Option<String>> = 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<Option<String>> = 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<Option<String>> { 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<String> = 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<CaptureKey, Option<String>> = 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, diff --git a/crates/shirabe-symfony-console/src/output/stream_output.rs b/crates/shirabe-symfony-console/src/output/stream_output.rs index c183444b..43cee3a8 100644 --- a/crates/shirabe-symfony-console/src/output/stream_output.rs +++ b/crates/shirabe-symfony-console/src/output/stream_output.rs @@ -5,7 +5,7 @@ use crate::formatter::OutputFormatterInterface; use crate::output::OutputInterface; use crate::output::VERBOSITY_NORMAL; use crate::output::{DoWrite, Output}; -use shirabe_php_shim::php_regex; +use shirabe_php_shim::{php_regex, preg_match}; /// StreamOutput writes the output to a given stream. /// @@ -121,7 +121,7 @@ impl StreamOutput { // See https://github.com/chalk/supports-color/blob/d4f413efaf8da045c5ab440ed418ef02dbb28bf1/index.js#L157 let mut matches: Vec<Option<String>> = Vec::new(); - shirabe_php_shim::preg_match( + preg_match( php_regex!( "/^((screen|xterm|vt100|vt220|putty|rxvt|ansi|cygwin|linux).*)|(.*-256(color)?(-bce)?)$/" ), diff --git a/crates/shirabe-symfony-console/src/question/choice_question.rs b/crates/shirabe-symfony-console/src/question/choice_question.rs index 8c0bafc3..b8ac16d8 100644 --- a/crates/shirabe-symfony-console/src/question/choice_question.rs +++ b/crates/shirabe-symfony-console/src/question/choice_question.rs @@ -5,7 +5,7 @@ use crate::exception::LogicException; use crate::question::Question; use crate::question::QuestionInterface; use indexmap::IndexMap; -use shirabe_php_shim::{PhpMixed, php_regex}; +use shirabe_php_shim::{PhpMixed, php_regex, preg_match}; /// Represents a choice question. #[derive(Debug)] @@ -123,7 +123,7 @@ impl ChoiceQuestion { let selected_choices: Vec<PhpMixed> = if multiselect { // Check for a separated comma values let mut matches: Vec<Option<String>> = Vec::new(); - if !shirabe_php_shim::preg_match( + if !preg_match( php_regex!("/^[^,]+(?:,[^,]+)*$/"), &shirabe_php_shim::strval(&selected), &mut matches, diff --git a/crates/shirabe-symfony-console/src/question/confirmation_question.rs b/crates/shirabe-symfony-console/src/question/confirmation_question.rs index 65dd19ab..6ec9281f 100644 --- a/crates/shirabe-symfony-console/src/question/confirmation_question.rs +++ b/crates/shirabe-symfony-console/src/question/confirmation_question.rs @@ -3,7 +3,7 @@ use crate::exception::InvalidArgumentException; use crate::question::Question; use crate::question::QuestionInterface; -use shirabe_php_shim::PhpMixed; +use shirabe_php_shim::{PhpMixed, preg_match}; /// Represents a yes/no question. #[derive(Debug)] @@ -40,11 +40,7 @@ impl ConfirmationQuestion { let answer_is_true = { let mut matches: Vec<Option<String>> = Vec::new(); - shirabe_php_shim::preg_match( - ®ex, - &shirabe_php_shim::strval(&answer), - &mut matches, - ) + preg_match(®ex, &shirabe_php_shim::strval(&answer), &mut matches) }; // false === $default diff --git a/crates/shirabe-symfony-console/src/terminal.rs b/crates/shirabe-symfony-console/src/terminal.rs index 9af712ad..8ff0431a 100644 --- a/crates/shirabe-symfony-console/src/terminal.rs +++ b/crates/shirabe-symfony-console/src/terminal.rs @@ -1,6 +1,6 @@ //! ref: composer/vendor/symfony/console/Terminal.php -use shirabe_php_shim::{PhpMixed, php_regex}; +use shirabe_php_shim::{PhpMixed, php_regex, preg_match}; use std::cell::Cell; thread_local! { @@ -81,7 +81,7 @@ impl Terminal { let ansicon = shirabe_php_shim::getenv("ANSICON"); let mut matches: Vec<Option<String>> = Vec::new(); if let Some(ansicon) = &ansicon - && shirabe_php_shim::preg_match( + && preg_match( php_regex!("/^(\\d+)x(\\d+)(?: \\((\\d+)x(\\d+)\\))?$/"), &shirabe_php_shim::trim(&ansicon.to_string_lossy(), None), &mut matches, @@ -138,7 +138,7 @@ impl Terminal { return; } let mut matches: Vec<Option<String>> = Vec::new(); - if shirabe_php_shim::preg_match( + if preg_match( php_regex!("/rows.(\\d+);.columns.(\\d+);/i"), &stty_string, &mut matches, @@ -154,7 +154,7 @@ impl Terminal { matches[1].clone().unwrap_or_default(), )))) }); - } else if shirabe_php_shim::preg_match( + } else if preg_match( php_regex!("/;.(\\d+).rows;.(\\d+).columns/i"), &stty_string, &mut matches, @@ -182,7 +182,7 @@ impl Terminal { let info = info?; let mut matches: Vec<Option<String>> = Vec::new(); - if !shirabe_php_shim::preg_match( + if !preg_match( php_regex!("/--------+\\r?\\n.+?(\\d+)\\r?\\n.+?(\\d+)\\r?\\n/"), &info, &mut matches, |
