Skip to content

Commit

Permalink
api: add SetMatches::matched_all
Browse files Browse the repository at this point in the history
This complements `matched_any` with a means to check if a set of
patterns all matched the haystack.

PR #1228
  • Loading branch information
tmccombs authored Sep 29, 2024
1 parent d3d3ff7 commit b790aa5
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::bytes::RegexSet;
///
/// let set = RegexSet::new(&[
/// r"^foo",
/// r"[a-z]+\.com",
/// ]).unwrap();
/// let matches = set.matches(b"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 b790aa5

Please sign in to comment.