use std::slice;
use std::vec;
- use error::Error;
- use exec::Exec;
- use re_builder::$builder_mod::RegexSetBuilder;
- use re_trait::RegularExpression;
+ use crate::error::Error;
+ use crate::exec::Exec;
+ use crate::re_builder::$builder_mod::RegexSetBuilder;
+ use crate::re_trait::RegularExpression;
/// Match multiple (possibly overlapping) regular expressions in a single scan.
///
/// Note that it would be possible to adapt the above example to using `Regex`
/// with an expression like:
///
-/// ```ignore
+/// ```text
/// (?P<email>[a-z]+@(?P<email_domain>[a-z]+[.](com|org|net)))|(?P<domain>[a-z]+[.](com|org|net))
/// ```
///
RegexSetBuilder::new(exprs).build()
}
+ /// Create a new empty regex set.
+ ///
+ /// # Example
+ ///
+ /// ```rust
+ /// # use regex::RegexSet;
+ /// let set = RegexSet::empty();
+ /// assert!(set.is_empty());
+ /// ```
+ pub fn empty() -> RegexSet {
+ RegexSetBuilder::new(&[""; 0]).build().unwrap()
+ }
+
/// Returns true if and only if one of the regexes in this set matches
/// the text given.
///
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
/// This will always produces matches in ascending order of index, where
/// the index corresponds to the index of the regex that matched with
/// respect to its position when initially building the set.
- pub fn iter(&self) -> SetMatchesIter {
+ pub fn iter(&self) -> SetMatchesIter<'_> {
SetMatchesIter((&*self.matches).into_iter().enumerate())
}
}
/// This will always produces matches in ascending order of index, where the
/// index corresponds to the index of the regex that matched with respect to
/// its position when initially building the set.
+#[derive(Debug)]
pub struct SetMatchesIntoIter(iter::Enumerate<vec::IntoIter<bool>>);
impl Iterator for SetMatchesIntoIter {
}
}
+impl iter::FusedIterator for SetMatchesIntoIter {}
+
/// A borrowed iterator over the set of matches from a regex set.
///
/// The lifetime `'a` refers to the lifetime of a `SetMatches` value.
/// This will always produces matches in ascending order of index, where the
/// index corresponds to the index of the regex that matched with respect to
/// its position when initially building the set.
-#[derive(Clone)]
+#[derive(Clone, Debug)]
pub struct SetMatchesIter<'a>(iter::Enumerate<slice::Iter<'a, bool>>);
impl<'a> Iterator for SetMatchesIter<'a> {
}
}
+impl<'a> iter::FusedIterator for SetMatchesIter<'a> {}
+
#[doc(hidden)]
impl From<Exec> for RegexSet {
fn from(exec: Exec) -> Self {
}
impl fmt::Debug for RegexSet {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "RegexSet({:?})", self.0.regex_strings())
}
}