From 9fd6aecad27240ccedab4487f6c157914142ca47 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Mon, 17 Aug 2026 07:36:34 +0900 Subject: refactor(preg): return the preg_* $matches instead of filling an out-param PHP fills `$matches` through a by-ref parameter, which the port mirrored with a `&mut` out-param plus a bool or count return. Every caller then had to declare an empty binding one line ahead of the call, and nothing in the type said the binding is only meaningful when the call succeeded. Return the matches instead: preg_match() and preg_match2() hand back an Option, and the three preg_match_all* functions hand back the collection they used to fill. The occurrence count the two map-shaped preg_match_all* functions used to return is the length of any one of the map's columns, so it is not lost -- Preg::match_all() and friends derive it via occurrence_count(). preg_replace2() keeps its `count: Option<&mut usize>`: that one is not derivable from the replaced string, and callers that do not want it pay nothing for passing None. Co-Authored-By: Claude Opus 5 (1M context) --- crates/shirabe-symfony-console/src/question/choice_question.rs | 8 ++++---- .../shirabe-symfony-console/src/question/confirmation_question.rs | 5 +---- 2 files changed, 5 insertions(+), 8 deletions(-) (limited to 'crates/shirabe-symfony-console/src/question') diff --git a/crates/shirabe-symfony-console/src/question/choice_question.rs b/crates/shirabe-symfony-console/src/question/choice_question.rs index b8ac16d8..84cba360 100644 --- a/crates/shirabe-symfony-console/src/question/choice_question.rs +++ b/crates/shirabe-symfony-console/src/question/choice_question.rs @@ -122,12 +122,12 @@ impl ChoiceQuestion { let selected_choices: Vec = if multiselect { // Check for a separated comma values - let mut matches: Vec> = Vec::new(); - if !preg_match( + if preg_match( php_regex!("/^[^,]+(?:,[^,]+)*$/"), &shirabe_php_shim::strval(&selected), - &mut matches, - ) { + ) + .is_none() + { return Err(InvalidArgumentException::new(shirabe_php_shim::sprintf( &error_message, std::slice::from_ref(&selected), diff --git a/crates/shirabe-symfony-console/src/question/confirmation_question.rs b/crates/shirabe-symfony-console/src/question/confirmation_question.rs index 6ec9281f..5a18a045 100644 --- a/crates/shirabe-symfony-console/src/question/confirmation_question.rs +++ b/crates/shirabe-symfony-console/src/question/confirmation_question.rs @@ -38,10 +38,7 @@ impl ConfirmationQuestion { return answer; } - let answer_is_true = { - let mut matches: Vec> = Vec::new(); - preg_match(®ex, &shirabe_php_shim::strval(&answer), &mut matches) - }; + let answer_is_true = preg_match(®ex, &shirabe_php_shim::strval(&answer)).is_some(); // false === $default if matches!(default, PhpMixed::Bool(false)) { -- cgit v1.3.1-4-g156e