diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-06-14 12:48:58 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-06-14 12:48:58 +0900 |
| commit | c1070afe69f53b621adea232527080d2c922e1a9 (patch) | |
| tree | be125ece467c2d1d761cd9f8a606337f6e5233f4 /crates/shirabe/src/console | |
| parent | 4ace644474d3d0e5575d19616ce46ba7d521fc64 (diff) | |
| download | php-shirabe-c1070afe69f53b621adea232527080d2c922e1a9.tar.gz php-shirabe-c1070afe69f53b621adea232527080d2c922e1a9.tar.zst php-shirabe-c1070afe69f53b621adea232527080d2c922e1a9.zip | |
refactor(pcre): consolidate duplicate preg_* shim helpers
The preg.rs shim had several near-duplicate functions: simple helpers
re-implementing logic already covered by their full-featured `2`
variants. Delegate or remove the redundant ones while preserving
behavior, and migrate the affected callers:
- preg_replace / preg_split now delegate to preg_replace2 / preg_split2
- preg_match_all_simple removed; its caller uses preg_match_all
- preg_split_chars removed; its caller uses a char-boundary iterator
- preg_match_offset removed; its callers use preg_match2 directly
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/console')
| -rw-r--r-- | crates/shirabe/src/console/application.rs | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/crates/shirabe/src/console/application.rs b/crates/shirabe/src/console/application.rs index 00453f8..4be2f90 100644 --- a/crates/shirabe/src/console/application.rs +++ b/crates/shirabe/src/console/application.rs @@ -2703,17 +2703,33 @@ impl Application { let mut line = String::new(); let mut offset = 0i64; - let mut m: Vec<String> = Vec::new(); - while shirabe_php_shim::preg_match_offset(r"/.{1,10000}/u", &utf8_string, &mut m, 0, offset) + let mut m: indexmap::IndexMap<shirabe_php_shim::CaptureKey, Option<String>> = + indexmap::IndexMap::new(); + while shirabe_php_shim::preg_match2( + r"/.{1,10000}/u", + &utf8_string, + Some(&mut m), + 0, + offset as usize, + ) + .expect("invalid regex") + == 1 { - offset += shirabe_php_shim::strlen(&m[0]); + let m0 = m[&shirabe_php_shim::CaptureKey::ByIndex(0)] + .as_deref() + .unwrap_or(""); + offset += shirabe_php_shim::strlen(m0); - for char in shirabe_php_shim::preg_split_chars(r"//u", &m[0]) { + let chunk = m0; + for char in chunk + .char_indices() + .map(|(i, c)| &chunk[i..i + c.len_utf8()]) + { // test if $char could be appended to current line if shirabe_php_shim::mb_strwidth(&format!("{}{}", line, char), Some("utf8")) <= width { - line.push_str(&char); + line.push_str(char); continue; } // if not, push current line to array and make new line @@ -2723,7 +2739,7 @@ impl Application { " ", shirabe_php_shim::STR_PAD_RIGHT, )); - line = char; + line = char.to_string(); } } |
