grep: factor test for \0 in grep patterns into a function