Skip to content

How to use Searcher to find exact portions of a byte match. #1633

Answered by BurntSushi
acheronfail asked this question in General
Discussion options

You must be logged in to vote

You aren't using it incorrectly and this is indeed expected behavior, although it is perhaps a design flaw. In particular, the grep-searcher and grep-matcher architecture generally assume two things:

  1. Detecting whether a match exists in a particular line is cheaper (possibly substantially so) than finding the exact boundary of that match.
  2. A match is generally infrequent compared to the size of the haystack.

This is why hamfisted APIs like Matcher::find_candidate_line exist. Indeed, in the most basic grep output format (no color), you never even need the match boundaries in the first place. All you need is the line that matched.

If, however, you're working on a problem in which you always…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@BurntSushi
Comment options

Answer selected by BurntSushi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants