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/src/command/config_command.rs | |
| 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/src/command/config_command.rs')
| -rw-r--r-- | crates/shirabe/src/command/config_command.rs | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/crates/shirabe/src/command/config_command.rs b/crates/shirabe/src/command/config_command.rs index f1eb14b0..0788d694 100644 --- a/crates/shirabe/src/command/config_command.rs +++ b/crates/shirabe/src/command/config_command.rs @@ -22,8 +22,8 @@ use shirabe_php_shim::{ InvalidArgumentException, PhpMixed, RuntimeException, array_is_list, array_merge, escapeshellcmd, exec, explode, file_exists, impl_php_class, implode, in_array_loose, in_array_strict, is_array, is_bool, is_dir, is_numeric, is_object, is_string, json_encode, - php_regex, preg_match, preg_replace, str_replace, strpos, strtolower, system, touch, - var_export, + php_regex, preg_is_match, preg_match, preg_replace, str_replace, strpos, strtolower, system, + touch, var_export, }; use shirabe_semver::VersionParser; use shirabe_symfony_console::command::Command; @@ -1449,7 +1449,7 @@ impl Command for ConfigCommand { } // Check if the header is in correct "Name: Value" format - if preg_match(php_regex!("/^[^:]+:\\s*.+$/"), header).is_none() { + if !preg_is_match(php_regex!("/^[^:]+:\\s*.+$/"), header) { return Err(RuntimeException::new(format!( "Header \"{}\" is not in \"Header-Name: Header-Value\" format", header @@ -1735,13 +1735,10 @@ fn build_unique_config_values() -> IndexMap<String, (ValidatorFn, NormalizerFn)> "cache-files-maxsize".to_string(), ( Box::new(|val| { - PhpMixed::Bool( - preg_match( - php_regex!("/^\\s*([0-9.]+)\\s*(?:([kmg])(?:i?b)?)?\\s*$/i"), - val.as_string().unwrap_or(""), - ) - .is_some(), - ) + PhpMixed::Bool(preg_is_match( + php_regex!("/^\\s*([0-9.]+)\\s*(?:([kmg])(?:i?b)?)?\\s*$/i"), + val.as_string().unwrap_or(""), + )) }), Box::new(|val| val.clone()), ), |
