ripgrep icon indicating copy to clipboard operation
ripgrep copied to clipboard

feat(globset): better way to see if ALL globs match

Open tmccombs opened this issue 1 year ago • 0 comments

A have a use case where I have a set of 1 or more globs, and want to know if all of them match, rather than if any of them match.

I can of course use a Vec<Glob> and do something like globs.iter().all(|g| g.is_match(path)), but it sounds like using a GlobSet may be more efficient, since it can use a single pass.

I think I can accomplish this with glob_set.matches(path).len() == glob_set.len(), but then it has to allocate a Vec, and then I just throw it away, because I only care about the length.

Possible ways this could be improved are:

  1. Add a matches_all method that returns true if all globs match (fwiw, I'd also like that on RegexSet)
  2. Return an iterator similar to how RegexSet.matches returns an iterator, so it can be counted instead of storing in a Vec.

tmccombs avatar Aug 12 '24 04:08 tmccombs