Skip to content

Why don't patterns that match empty strings match empty files? #2091

Answered by BurntSushi
jzinn asked this question in General
Discussion options

You must be logged in to vote

Sorry, I missed this question and it probably dipped too far into my email inbox and I ended up forgetting about it.

This is a good question, although ambiguous. On the one hand, maybe you're interested in "why does the implementation behave this way?" Or maybe you're interested in, "why did you choose to implement these semantics?" I suspect you're interested in the latter. But I'll answer the former too.

For the former, the answer is that when ripgrep goes to read a file, it has to know when to stop reading and thus stop searching. It knows this when read syscalls return 0 bytes, which conventionally indicates EOF. So in the current implementation, for an empty file, ripgrep issues a read

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@jzinn
Comment options

@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