aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe-symfony-console/src/formatter
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-08-16 19:06:49 +0900
committernsfisis <nsfisis@gmail.com>2026-08-16 19:07:15 +0900
commitb6604e1395f003748fe40a44e1190470632a40ce (patch)
tree27ce3c137c860a7bd8914852ba5f851e213d448c /crates/shirabe-symfony-console/src/formatter
parentc5605cc072c1880af7d70647278c6aa0de43f402 (diff)
downloadphp-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/formatter')
-rw-r--r--crates/shirabe-symfony-console/src/formatter/output_formatter.rs23
1 files changed, 10 insertions, 13 deletions
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,