Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add is_empty() to RegexSet. #687

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/re_set.rs
Expand Up @@ -207,6 +207,11 @@ impl RegexSet {
self.0.regex_strings().len()
}

/// Returns `true` if this set contains no regular expressions.
pub fn is_empty(&self) -> bool {
self.0.regex_strings().is_empty()
}

/// Returns the patterns that this set will match on.
///
/// This function can be used to determine the pattern for a match. The
Expand Down
11 changes: 11 additions & 0 deletions tests/set.rs
Expand Up @@ -54,3 +54,14 @@ fn get_set_patterns() {
let set = regex_set!(&["a", "b"]);
assert_eq!(vec!["a", "b"], set.patterns());
}

#[test]
fn len_and_empty() {
let empty = regex_set!(&[""; 0]);
assert_eq!(empty.len(), 0);
assert!(empty.is_empty());

let not_empty = regex_set!(&["ab", "b"]);
assert_eq!(not_empty.len(), 2);
assert!(!not_empty.is_empty());
}