diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-08-17 04:45:47 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-08-17 04:45:47 +0900 |
| commit | 2337aa8225b1452e2ec65c122e4b6e8b54f3ea7e (patch) | |
| tree | 53b6154f1c41249aa94365feb508209c75ca6df1 /crates | |
| parent | d28eefe6833e44db89a27e6afb5f15fc5d667b9b (diff) | |
| download | php-shirabe-2337aa8225b1452e2ec65c122e4b6e8b54f3ea7e.tar.gz php-shirabe-2337aa8225b1452e2ec65c122e4b6e8b54f3ea7e.tar.zst php-shirabe-2337aa8225b1452e2ec65c122e4b6e8b54f3ea7e.zip | |
refactor(pcre): drop the guards for unsupported preg flags
Preg::match5() rejected PREG_OFFSET_CAPTURE and check_set_order() rejected
PREG_SET_ORDER, mirroring the PHP where those flags would change the type
of $matches. The Rust ports of both take a typed `matches` out-param
instead, so neither flag can reach them; check_set_order() already had no
caller. The three constants are unreferenced once the guards are gone.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates')
| -rw-r--r-- | crates/shirabe-pcre/src/preg.rs | 22 | ||||
| -rw-r--r-- | crates/shirabe-php-shim/src/preg.rs | 3 |
2 files changed, 2 insertions, 23 deletions
diff --git a/crates/shirabe-pcre/src/preg.rs b/crates/shirabe-pcre/src/preg.rs index f45b86df..fb71c63b 100644 --- a/crates/shirabe-pcre/src/preg.rs +++ b/crates/shirabe-pcre/src/preg.rs @@ -14,9 +14,8 @@ use indexmap::IndexMap; pub use shirabe_php_shim::CaptureKey; use shirabe_php_shim::{ - PREG_OFFSET_CAPTURE, PREG_SET_ORDER, PREG_UNMATCHED_AS_NULL, PregPattern, preg_grep, - preg_match_all_offset_capture, preg_match_all2, preg_match2, preg_replace_callback, - preg_replace2, + PREG_UNMATCHED_AS_NULL, PregPattern, preg_grep, preg_match_all_offset_capture, preg_match_all2, + preg_match2, preg_replace_callback, preg_replace2, }; #[derive(Debug)] @@ -38,8 +37,6 @@ impl Preg { flags: i64, offset: usize, ) -> bool { - Self::check_offset_capture(flags, "matchWithOffsets"); - let mut internal: IndexMap<CaptureKey, Option<String>> = IndexMap::new(); let result = preg_match2( pattern, @@ -216,21 +213,6 @@ impl Preg { ) -> bool { Self::match_all_with_offsets5(pattern, subject, matches) > 0 } - - fn check_offset_capture(flags: i64, use_function_name: &str) { - assert!( - flags & PREG_OFFSET_CAPTURE == 0, - "PREG_OFFSET_CAPTURE is not supported as it changes the type of $matches, use {}() instead", - use_function_name - ); - } - - fn check_set_order(flags: i64) { - assert!( - flags & PREG_SET_ORDER == 0, - "PREG_SET_ORDER is not supported as it changes the type of $matches" - ); - } } // Drops `null` (unmatched) groups, mirroring how the public `string`-valued diff --git a/crates/shirabe-php-shim/src/preg.rs b/crates/shirabe-php-shim/src/preg.rs index 6d70c717..62ad464c 100644 --- a/crates/shirabe-php-shim/src/preg.rs +++ b/crates/shirabe-php-shim/src/preg.rs @@ -1,9 +1,6 @@ use indexmap::IndexMap; use std::sync::{Arc, LazyLock, Mutex}; -pub const PREG_PATTERN_ORDER: i64 = 1; -pub const PREG_SET_ORDER: i64 = 2; -pub const PREG_OFFSET_CAPTURE: i64 = 256; pub const PREG_UNMATCHED_AS_NULL: i64 = 512; #[derive(Debug, Clone, PartialOrd, Ord, PartialEq, Eq, Hash)] |
