Don't compile the regex if no valid files were given (eg. all files are directories); print error if file is a binary file (contains NULL character)

This commit is contained in:
2025-04-16 16:58:27 -04:00
parent fc0af1ccc5
commit 83632f2abc
2 changed files with 26 additions and 2 deletions

View File

@@ -1,6 +1,11 @@
package main
import "slices"
import (
"bufio"
"os"
"slices"
"strings"
)
type character interface {
int | rune
@@ -25,3 +30,15 @@ func genRange[T character](start, end T) []T {
}
return toRet
}
// Returns whether or not the given file contains a NULL character
func fileContainsNullChar(file *os.File) bool {
scanner := bufio.NewScanner(file)
for scanner.Scan() {
line := scanner.Text()
if strings.Contains(line, "\000") {
return true
}
}
return false
}