Skip to content

Commit b790aa5

Browse files
authored
api: add SetMatches::matched_all
This complements `matched_any` with a means to check if a set of patterns all matched the haystack. PR #1228
1 parent d3d3ff7 commit b790aa5

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/regexset/bytes.rs

+18
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,24 @@ impl SetMatches {
482482
!self.0.is_empty()
483483
}
484484

485+
/// Whether all patterns in this set matched.
486+
///
487+
/// # Example
488+
///
489+
/// ```
490+
/// use regex::bytes::RegexSet;
491+
///
492+
/// let set = RegexSet::new(&[
493+
/// r"^foo",
494+
/// r"[a-z]+\.com",
495+
/// ]).unwrap();
496+
/// let matches = set.matches(b"foo.example.com");
497+
/// assert!(matches.matched_all());
498+
/// ```
499+
pub fn matched_all(&self) -> bool {
500+
self.0.is_full()
501+
}
502+
485503
/// Whether the regex at the given index matched.
486504
///
487505
/// The index for a regex is determined by its insertion order upon the

src/regexset/string.rs

+18
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,24 @@ impl SetMatches {
478478
!self.0.is_empty()
479479
}
480480

481+
/// Whether all patterns in this set matched.
482+
///
483+
/// # Example
484+
///
485+
/// ```
486+
/// use regex::RegexSet;
487+
///
488+
/// let set = RegexSet::new(&[
489+
/// r"^foo",
490+
/// r"[a-z]+\.com",
491+
/// ]).unwrap();
492+
/// let matches = set.matches("foo.example.com");
493+
/// assert!(matches.matched_all());
494+
/// ```
495+
pub fn matched_all(&self) -> bool {
496+
self.0.is_full()
497+
}
498+
481499
/// Whether the regex at the given index matched.
482500
///
483501
/// The index for a regex is determined by its insertion order upon the

0 commit comments

Comments
 (0)