1
0
mirror of https://github.com/BurntSushi/ripgrep.git synced 2024-12-12 19:18:24 +02:00
ripgrep/crates/printer/src
Andrew Gallant 7ed9a31819 printer: fix --count-matches output
In order to implement --count-matches, we simply re-execute the regex on
the spans reported by the searcher. The spans always correspond to the
lines that participated in the match. This is the correct thing to do,
except when the regex contains look-ahead (or look-behind).

In particular, the look-around permits the regex's match success to
depends on an arbitrary point before or after the lines actually
reported as participating in the match. Since only the matched lines are
reported to the printer, it is possible for subsequent searching on
those lines to fail.

A true fix for this would somehow make the total span available to the
printer. But that seems tricky since it isn't always available. For
PCRE2's case in multiline mode, it is available because we force it to
be so for correctness.

For now, we simply detect this corner case heuristically. If the match
count is zero, then it necessarily means there is some kind of
look-around that isn't matching. So we set the match count to 1. This is
probably incorrect in some cases, although my brain can't quite come up
with a concrete example. Nevertheless, this is strictly better than the
status quo.

Fixes #1573
2020-05-08 23:24:40 -04:00
..
color.rs repo: move all source code in crates directory 2020-02-17 19:24:53 -05:00
counter.rs repo: move all source code in crates directory 2020-02-17 19:24:53 -05:00
json.rs repo: move all source code in crates directory 2020-02-17 19:24:53 -05:00
jsont.rs repo: move all source code in crates directory 2020-02-17 19:24:53 -05:00
lib.rs repo: move all source code in crates directory 2020-02-17 19:24:53 -05:00
macros.rs repo: move all source code in crates directory 2020-02-17 19:24:53 -05:00
standard.rs repo: move all source code in crates directory 2020-02-17 19:24:53 -05:00
stats.rs repo: move all source code in crates directory 2020-02-17 19:24:53 -05:00
summary.rs printer: fix --count-matches output 2020-05-08 23:24:40 -04:00
util.rs repo: move all source code in crates directory 2020-02-17 19:24:53 -05:00