aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe-symfony-console/src
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-08-18 01:57:02 +0900
committernsfisis <nsfisis@gmail.com>2026-08-18 01:57:02 +0900
commitfed0a6e7ac361af9b963c1f62411b1a85478230c (patch)
tree5cde64a24845c761890fbcbe05e0d702f1ec8df7 /crates/shirabe-symfony-console/src
parente093b2be1c333e67c96aebb0a5291bea9ae3d6db (diff)
downloadphp-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')
-rw-r--r--crates/shirabe-symfony-console/src/command/command.rs4
-rw-r--r--crates/shirabe-symfony-console/src/helper/helper.rs6
-rw-r--r--crates/shirabe-symfony-console/src/helper/table.rs7
-rw-r--r--crates/shirabe-symfony-console/src/input/input.rs4
-rw-r--r--crates/shirabe-symfony-console/src/output/stream_output.rs5
-rw-r--r--crates/shirabe-symfony-console/src/question/choice_question.rs8
-rw-r--r--crates/shirabe-symfony-console/src/question/confirmation_question.rs4
7 files changed, 17 insertions, 21 deletions
diff --git a/crates/shirabe-symfony-console/src/command/command.rs b/crates/shirabe-symfony-console/src/command/command.rs
index 848cece3..27966ec1 100644
--- a/crates/shirabe-symfony-console/src/command/command.rs
+++ b/crates/shirabe-symfony-console/src/command/command.rs
@@ -11,7 +11,7 @@ use crate::input::InputInterface;
use crate::input::InputOption;
use crate::output::OutputInterface;
use indexmap::IndexMap;
-use shirabe_php_shim::{PhpMixed, php_regex, preg_match};
+use shirabe_php_shim::{PhpMixed, php_regex, preg_is_match};
use std::cell::{Cell, Ref};
/// The base-class state of the PHP `Command` class.
@@ -108,7 +108,7 @@ impl CommandData {
///
/// Throws InvalidArgumentException when the name is invalid.
fn validate_name(&self, name: &str) -> anyhow::Result<Result<(), InvalidArgumentException>> {
- if preg_match(php_regex!(r"/^[^\:]++(\:[^\:]++)*$/"), name).is_none() {
+ if !preg_is_match(php_regex!(r"/^[^\:]++(\:[^\:]++)*$/"), name) {
return Ok(Err(InvalidArgumentException::new(format!(
"Command name \"{}\" is invalid.",
name
diff --git a/crates/shirabe-symfony-console/src/helper/helper.rs b/crates/shirabe-symfony-console/src/helper/helper.rs
index 435648ca..a740964a 100644
--- a/crates/shirabe-symfony-console/src/helper/helper.rs
+++ b/crates/shirabe-symfony-console/src/helper/helper.rs
@@ -2,7 +2,7 @@
use crate::formatter::OutputFormatterInterface;
use crate::helper::HelperSet;
-use shirabe_php_shim::{php_regex, preg_match, preg_replace};
+use shirabe_php_shim::{php_regex, preg_is_match, preg_replace};
use shirabe_symfony_string::unicode_string::UnicodeString;
/// Helper is the base class for all helper classes.
@@ -40,7 +40,7 @@ impl Helper {
/// Returns the width of a string, using mb_strwidth if it is available.
/// The width is how many characters positions the string will use.
pub fn width(string: &str) -> i64 {
- if preg_match(php_regex!("//u"), string).is_some() {
+ if preg_is_match(php_regex!("//u"), string) {
return UnicodeString::new(string).width(false);
}
@@ -56,7 +56,7 @@ impl Helper {
/// Returns the length of a string, using mb_strlen if it is available.
/// The length is related to how many bytes the string will use.
pub fn length(string: &str) -> i64 {
- if preg_match(php_regex!("//u"), string).is_some() {
+ if preg_is_match(php_regex!("//u"), string) {
return UnicodeString::new(string).length();
}
diff --git a/crates/shirabe-symfony-console/src/helper/table.rs b/crates/shirabe-symfony-console/src/helper/table.rs
index 777f44c7..e9ea12c8 100644
--- a/crates/shirabe-symfony-console/src/helper/table.rs
+++ b/crates/shirabe-symfony-console/src/helper/table.rs
@@ -8,7 +8,7 @@ use crate::helper::{
};
use crate::output::OutputInterface;
use indexmap::IndexMap;
-use shirabe_php_shim::{PhpMixed, php_regex, preg_match};
+use shirabe_php_shim::{PhpMixed, php_regex, preg_is_match};
/// A single cell within a table row.
///
@@ -655,11 +655,10 @@ impl Table {
let mut cell_format = cell_format;
let mut pad_type = style.get_pad_type();
if cell.is_table_cell() && cell.style().is_some() {
- let is_not_styled_by_tag = preg_match(
+ let is_not_styled_by_tag = !preg_is_match(
php_regex!("/^<(\\w+|(\\w+=[\\w,]+;?)*)>.+<\\/(\\w+|(\\w+=\\w+;?)*)?>$/"),
&cell_str,
- )
- .is_none();
+ );
if is_not_styled_by_tag {
let cell_style = cell.style().unwrap();
match cell_style.get_cell_format() {
diff --git a/crates/shirabe-symfony-console/src/input/input.rs b/crates/shirabe-symfony-console/src/input/input.rs
index 4712a713..88bb9f94 100644
--- a/crates/shirabe-symfony-console/src/input/input.rs
+++ b/crates/shirabe-symfony-console/src/input/input.rs
@@ -4,7 +4,7 @@ use crate::exception::InvalidArgumentException;
use crate::exception::RuntimeException;
use crate::input::InputDefinition;
use indexmap::IndexMap;
-use shirabe_php_shim::{PhpMixed, PhpResource, php_regex, preg_match};
+use shirabe_php_shim::{PhpMixed, PhpResource, php_regex, preg_is_match};
/// Input is the base class for all concrete Input classes.
///
@@ -207,7 +207,7 @@ impl Input {
/// Escapes a token through escapeshellarg if it contains unsafe chars.
pub fn escape_token(&self, token: &str) -> String {
- if preg_match(php_regex!("{^[\\w-]+$}"), token).is_some() {
+ if preg_is_match(php_regex!("{^[\\w-]+$}"), token) {
token.to_string()
} else {
shirabe_php_shim::escapeshellarg(token)
diff --git a/crates/shirabe-symfony-console/src/output/stream_output.rs b/crates/shirabe-symfony-console/src/output/stream_output.rs
index 14565012..0d59fe2c 100644
--- a/crates/shirabe-symfony-console/src/output/stream_output.rs
+++ b/crates/shirabe-symfony-console/src/output/stream_output.rs
@@ -5,7 +5,7 @@ use crate::formatter::OutputFormatterInterface;
use crate::output::OutputInterface;
use crate::output::VERBOSITY_NORMAL;
use crate::output::{DoWrite, Output};
-use shirabe_php_shim::{php_regex, preg_match};
+use shirabe_php_shim::{php_regex, preg_is_match};
/// StreamOutput writes the output to a given stream.
///
@@ -120,13 +120,12 @@ impl StreamOutput {
}
// See https://github.com/chalk/supports-color/blob/d4f413efaf8da045c5ab440ed418ef02dbb28bf1/index.js#L157
- preg_match(
+ preg_is_match(
php_regex!(
"/^((screen|xterm|vt100|vt220|putty|rxvt|ansi|cygwin|linux).*)|(.*-256(color)?(-bce)?)$/"
),
&term,
)
- .is_some()
}
}
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(&regex, &shirabe_php_shim::strval(&answer)).is_some();
+ let answer_is_true = preg_is_match(&regex, &shirabe_php_shim::strval(&answer));
// false === $default
if matches!(default, PhpMixed::Bool(false)) {