From ef806b6cbf6a9978360e265418e9980089d85132 Mon Sep 17 00:00:00 2001 From: Thayne McCombs Date: Thu, 19 Sep 2024 01:53:14 -0600 Subject: [PATCH 1/2] api: add SetMatches::matched_all Which compliments `matched_any` with a means to check if a set of patterns ALL matched the haystack. --- src/regexset/bytes.rs | 18 ++++++++++++++++++ src/regexset/string.rs | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/regexset/bytes.rs b/src/regexset/bytes.rs index 2f46abc4d..c46fda05d 100644 --- a/src/regexset/bytes.rs +++ b/src/regexset/bytes.rs @@ -482,6 +482,24 @@ impl SetMatches { !self.0.is_empty() } + /// Whether all patterns in this set matched + /// + /// # Example + /// + /// ``` + /// use regex::RegexSet; + /// + /// let set = RegexSet::new(&[ + /// r"^foo", + /// r"[a-z]+\.com", + /// ]).unwrap(); + /// let matches = set.matches("foo.example.com"); + /// assert!(matches.matched_all()); + /// ``` + pub fn matched_all(&self) -> bool { + self.0.is_full() + } + /// Whether the regex at the given index matched. /// /// The index for a regex is determined by its insertion order upon the diff --git a/src/regexset/string.rs b/src/regexset/string.rs index 5cb9b5608..35e6058e2 100644 --- a/src/regexset/string.rs +++ b/src/regexset/string.rs @@ -478,6 +478,24 @@ impl SetMatches { !self.0.is_empty() } + /// Whether all patterns in this set matched + /// + /// # Example + /// + /// ``` + /// use regex::RegexSet; + /// + /// let set = RegexSet::new(&[ + /// r"^foo", + /// r"[a-z]+\.com", + /// ]).unwrap(); + /// let matches = set.matches("foo.example.com"); + /// assert!(matches.matched_all()); + /// ``` + pub fn matched_all(&self) -> bool { + self.0.is_full() + } + /// Whether the regex at the given index matched. /// /// The index for a regex is determined by its insertion order upon the From 35ab389373e08576c60b9479e051fa513757ceeb Mon Sep 17 00:00:00 2001 From: Thayne McCombs Date: Fri, 20 Sep 2024 00:25:15 -0600 Subject: [PATCH 2/2] fixup! api: add SetMatches::matched_all --- src/regexset/bytes.rs | 6 +++--- src/regexset/string.rs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/regexset/bytes.rs b/src/regexset/bytes.rs index c46fda05d..46f02fbbd 100644 --- a/src/regexset/bytes.rs +++ b/src/regexset/bytes.rs @@ -482,18 +482,18 @@ impl SetMatches { !self.0.is_empty() } - /// Whether all patterns in this set matched + /// Whether all patterns in this set matched. /// /// # Example /// /// ``` - /// use regex::RegexSet; + /// use regex::bytes::RegexSet; /// /// let set = RegexSet::new(&[ /// r"^foo", /// r"[a-z]+\.com", /// ]).unwrap(); - /// let matches = set.matches("foo.example.com"); + /// let matches = set.matches(b"foo.example.com"); /// assert!(matches.matched_all()); /// ``` pub fn matched_all(&self) -> bool { diff --git a/src/regexset/string.rs b/src/regexset/string.rs index 35e6058e2..535a670c8 100644 --- a/src/regexset/string.rs +++ b/src/regexset/string.rs @@ -478,7 +478,7 @@ impl SetMatches { !self.0.is_empty() } - /// Whether all patterns in this set matched + /// Whether all patterns in this set matched. /// /// # Example ///