diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-08-18 01:57:02 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-08-18 01:57:02 +0900 |
| commit | cb77f7c7076aa4bac3e6aaa1c164cf9c1d449ddc (patch) | |
| tree | 1402c6cb393dd760dc240532119ee3df1e1be1ec /crates/shirabe-symfony-console/src/formatter | |
| parent | 530d085d4f3e19f94ac3cf8f8ac3b17000214b2e (diff) | |
| download | php-shirabe-cb77f7c7076aa4bac3e6aaa1c164cf9c1d449ddc.tar.gz php-shirabe-cb77f7c7076aa4bac3e6aaa1c164cf9c1d449ddc.tar.zst php-shirabe-cb77f7c7076aa4bac3e6aaa1c164cf9c1d449ddc.zip | |
refactor(preg): fold preg_match into preg_match2
preg_match copied every group into a Vec<Option<String>> while
preg_match2 handed back the borrowed captures. They now differ only in
the offset argument, so preg_match delegates with offset 0 and its
callers read groups through PregMatches::get.
Going through preg_match2 also makes preg_match honour the PCRE A
modifier, which it used to ignore; no caller passes such a pattern.
VersionParser::manipulate_version_string takes an index accessor instead
of a slice, and VersionParser::normalize matches against a copy of the
subject because the captures outlive the assignments to $version.
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.rs | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/crates/shirabe-symfony-console/src/formatter/output_formatter.rs b/crates/shirabe-symfony-console/src/formatter/output_formatter.rs index 571d66c0..256fade1 100644 --- a/crates/shirabe-symfony-console/src/formatter/output_formatter.rs +++ b/crates/shirabe-symfony-console/src/formatter/output_formatter.rs @@ -190,9 +190,11 @@ impl OutputFormatter { prefix = String::new(); } - let matches = preg_match(php_regex!("~(\\n)$~"), &text).unwrap_or_default(); + let trailing = preg_match(php_regex!("~(\\n)$~"), &text) + .and_then(|matches| matches.get(1)) + .unwrap_or("") + .to_string(); 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); if *current_line_length == 0 |
