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) --- .../src/formatter/output_formatter.rs | 23 ++++++++++------------ 1 file changed, 10 insertions(+), 13 deletions(-) (limited to 'crates/shirabe-symfony-console/src/formatter') 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 { - 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![]; - 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> = 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, -- cgit v1.3.1-4-g156e