diff --git a/file.go b/file.go index 615ce10..900c445 100644 --- a/file.go +++ b/file.go @@ -274,12 +274,6 @@ func findMatches(data []byte) (loc []int) { return loc } } - for _, s := range searchBytes { - pos := bytes.Index(data, s) - if pos != -1 { - return []int{pos, pos + len(s)} - } - } return nil } diff --git a/main.go b/main.go index 254c88e..c259bf0 100644 --- a/main.go +++ b/main.go @@ -17,7 +17,6 @@ import ( ) // TODO: -// - it would be better to make fixed patterns case insensitive too. // - configurable defaults for exclude. func main() { @@ -42,10 +41,9 @@ which can be repeated multiple times. -e specifies a regular expression and -Q a fixed pattern. When using either flag, any non-flag arguments are treated as paths to scan. -Search defaults to case-sensitive but the -i flag may be passed to make regular -expression searches case-insensitive. Alternatively, the "(?i)" construct may be -added to a regular expression to make that specific expression case insensitive. -Fixed pattern matches are always case-sensitive. +Search defaults to case-sensitive but the -i flag may be passed to make all +search terms case-insensitive. Alternatively, the "(?i)" construct may be added +to a regular expression to make that specific expression case insensitive. Files and directories can be excluded with the -x option. This supports bash-style globs with '*', '?', '[a-z]', '{this,that}', or '/**/' to match zero or more @@ -58,7 +56,6 @@ var ( searchRegexp []string regexps []*regexp.Regexp searchFixed []string - searchBytes [][]byte searchPath []string excludeList []string binaryFile notPlainTextFlag @@ -116,8 +113,15 @@ func run(c *cobra.Command, args []string) error { regexps = append(regexps, re) } - for _, s := range searchFixed { - searchBytes = append(searchBytes, []byte(s)) + for _, r := range searchFixed { + r = regexp.QuoteMeta(r) + if ignoreCase { + r = "(?i)" + r + } + re, err := regexp.Compile(r) + if err != nil { + } + regexps = append(regexps, re) } var errs []error