aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe-php-shim
diff options
context:
space:
mode:
Diffstat (limited to 'crates/shirabe-php-shim')
-rw-r--r--crates/shirabe-php-shim/src/preg.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/crates/shirabe-php-shim/src/preg.rs b/crates/shirabe-php-shim/src/preg.rs
index c2aa0df3..e758fd20 100644
--- a/crates/shirabe-php-shim/src/preg.rs
+++ b/crates/shirabe-php-shim/src/preg.rs
@@ -96,6 +96,20 @@ preg_match_map! {
pub struct PregMatchesAllWithOffsets(CaptureKey => Vec<(Option<String>, i64)>);
}
+impl PregMatchesAll {
+ /// The number PHP's `preg_match_all` returns: every column holds one entry per occurrence.
+ pub fn occurrence_count(&self) -> usize {
+ self[&CaptureKey::ByIndex(0)].len()
+ }
+}
+
+impl PregMatchesAllWithOffsets {
+ /// The number PHP's `preg_match_all` returns: every column holds one entry per occurrence.
+ pub fn occurrence_count(&self) -> usize {
+ self[&CaptureKey::ByIndex(0)].len()
+ }
+}
+
pub fn preg_quote(str: &str, delimiter: Option<char>) -> String {
// Regex pattern compatibility:
// PHP's preg_quote escapes `<` and `>` (PCRE treats `\<`/`\>` as literals), but the `regex`