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 | fed0a6e7ac361af9b963c1f62411b1a85478230c (patch) | |
| tree | 5cde64a24845c761890fbcbe05e0d702f1ec8df7 /crates/shirabe-symfony-console/src/question | |
| parent | e093b2be1c333e67c96aebb0a5291bea9ae3d6db (diff) | |
| download | php-shirabe-fed0a6e7ac361af9b963c1f62411b1a85478230c.tar.gz php-shirabe-fed0a6e7ac361af9b963c1f62411b1a85478230c.tar.zst php-shirabe-fed0a6e7ac361af9b963c1f62411b1a85478230c.zip | |
refactor(preg): add preg_is_match for existence-only call sites
The capture groups were discarded at 162 of the preg_match call sites,
which only tested the Option. They now call preg_is_match, which lets the
regex engine skip capture tracking.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe-symfony-console/src/question')
| -rw-r--r-- | crates/shirabe-symfony-console/src/question/choice_question.rs | 8 | ||||
| -rw-r--r-- | crates/shirabe-symfony-console/src/question/confirmation_question.rs | 4 |
2 files changed, 5 insertions, 7 deletions
diff --git a/crates/shirabe-symfony-console/src/question/choice_question.rs b/crates/shirabe-symfony-console/src/question/choice_question.rs index 84cba360..a29fdf2a 100644 --- a/crates/shirabe-symfony-console/src/question/choice_question.rs +++ b/crates/shirabe-symfony-console/src/question/choice_question.rs @@ -5,7 +5,7 @@ use crate::exception::LogicException; use crate::question::Question; use crate::question::QuestionInterface; use indexmap::IndexMap; -use shirabe_php_shim::{PhpMixed, php_regex, preg_match}; +use shirabe_php_shim::{PhpMixed, php_regex, preg_is_match}; /// Represents a choice question. #[derive(Debug)] @@ -122,12 +122,10 @@ impl ChoiceQuestion { let selected_choices: Vec<PhpMixed> = if multiselect { // Check for a separated comma values - if preg_match( + if !preg_is_match( php_regex!("/^[^,]+(?:,[^,]+)*$/"), &shirabe_php_shim::strval(&selected), - ) - .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 5a18a045..6b8eb389 100644 --- a/crates/shirabe-symfony-console/src/question/confirmation_question.rs +++ b/crates/shirabe-symfony-console/src/question/confirmation_question.rs @@ -3,7 +3,7 @@ use crate::exception::InvalidArgumentException; use crate::question::Question; use crate::question::QuestionInterface; -use shirabe_php_shim::{PhpMixed, preg_match}; +use shirabe_php_shim::{PhpMixed, preg_is_match}; /// Represents a yes/no question. #[derive(Debug)] @@ -38,7 +38,7 @@ impl ConfirmationQuestion { return answer; } - let answer_is_true = preg_match(®ex, &shirabe_php_shim::strval(&answer)).is_some(); + let answer_is_true = preg_is_match(®ex, &shirabe_php_shim::strval(&answer)); // false === $default if matches!(default, PhpMixed::Bool(false)) { |
