Skip to content

Commit

Permalink
api: add SetMatches::matched_all
Browse files Browse the repository at this point in the history
Which compliments `matched_any` with a means to check if a set of
patterns ALL matched the haystack.
  • Loading branch information
tmccombs committed Sep 19, 2024
1 parent ab88aa5 commit ef806b6
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/regexset/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions src/regexset/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ef806b6

Please sign in to comment.