aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe-external-packages/src/symfony/console/formatter
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-06-14 13:02:59 +0900
committernsfisis <nsfisis@gmail.com>2026-06-14 13:02:59 +0900
commitcfd2a4488797ddaabd0087aa0021b26892663ffb (patch)
treeed2c030dded78355e0721d5458c2c6b12a3c2f2c /crates/shirabe-external-packages/src/symfony/console/formatter
parentc1070afe69f53b621adea232527080d2c922e1a9 (diff)
downloadphp-shirabe-cfd2a4488797ddaabd0087aa0021b26892663ffb.tar.gz
php-shirabe-cfd2a4488797ddaabd0087aa0021b26892663ffb.tar.zst
php-shirabe-cfd2a4488797ddaabd0087aa0021b26892663ffb.zip
refactor(pcre): treat regex compile failure as fatal in shim
The preg_* shim helpers wrapped their results in Option/Result solely to signal a regex that failed to compile. Composer never feeds a pattern that fails at runtime, so such a failure is a programming error: panic instead and drop the Option/Result wrappers, updating all callers. preg_replace_callback keeps its Result return type since the callback itself is fallible. preg_match_groups is removed in favor of preg_match at its sole call site. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe-external-packages/src/symfony/console/formatter')
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/formatter/output_formatter.rs10
1 files changed, 4 insertions, 6 deletions
diff --git a/crates/shirabe-external-packages/src/symfony/console/formatter/output_formatter.rs b/crates/shirabe-external-packages/src/symfony/console/formatter/output_formatter.rs
index 0de90be..6736ada 100644
--- a/crates/shirabe-external-packages/src/symfony/console/formatter/output_formatter.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/formatter/output_formatter.rs
@@ -19,8 +19,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("/([^\\\\]|^)([<>])/", "$1\\\\$2", text)
- .expect("preg_replace failed");
+ let text = shirabe_php_shim::preg_replace("/([^\\\\]|^)([<>])/", "$1\\\\$2", text);
Ok(Self::escape_trailing_backslash(&text))
}
@@ -106,7 +105,7 @@ impl OutputFormatter {
"/([^=]+)=([^;]+)(;|$)/",
string,
&mut matches,
- )? == 0
+ ) == 0
{
return Ok(None);
}
@@ -122,8 +121,7 @@ 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("{\\\\([<>])}", "$1", &r#match[1])
- .expect("preg_replace failed");
+ let url = shirabe_php_shim::preg_replace("{\\\\([<>])}", "$1", &r#match[1]);
style.set_href(&url);
} else if r#match[0] == "options" {
let mut options = shirabe_php_shim::preg_match_all(
@@ -292,7 +290,7 @@ impl WrappableOutputFormatterInterface for OutputFormatter {
&format!("#<(({open_tag_regex}) | /({close_tag_regex})?)>#ix"),
message,
&mut matches,
- )?;
+ );
let count = matches.group(0).len();
for i in 0..count {
let (text, pos) = matches.group(0)[i].clone();