aboutsummaryrefslogtreecommitdiff
path: root/internal/cond/eval.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/cond/eval.go')
-rw-r--r--internal/cond/eval.go17
1 files changed, 11 insertions, 6 deletions
diff --git a/internal/cond/eval.go b/internal/cond/eval.go
index e3093af..3cec110 100644
--- a/internal/cond/eval.go
+++ b/internal/cond/eval.go
@@ -19,7 +19,10 @@ type Facts interface {
Size() int64
ModTime() time.Time
Now() time.Time
- Content(ignoreCase, fold bool) (string, error) // normalised with norm.Text
+ // ContentContains reports the index of the first of keywords, each
+ // normalised under opt with norm.Text, that the file's text contains, or
+ // -1 when it contains none.
+ ContentContains(opt Options, keywords []string) (int, error)
Duplicate(dirs []string) (original string, ok bool, err error)
Matched() bool // an earlier rule matched this file
}
@@ -167,14 +170,16 @@ func (c *Cond) evalLeaf(n *node, f Facts) (ok bool, reason, warn string, caps []
return false, "", "", nil
case kContent:
- text, err := f.Content(c.opt.IgnoreCase, c.opt.Fold)
+ norms := make([]string, len(n.keywords))
+ for i, kw := range n.keywords {
+ norms[i] = kw.norm
+ }
+ i, err := f.ContentContains(c.opt, norms)
if err != nil {
return false, "", "content unreadable: " + err.Error(), nil
}
- for _, kw := range n.keywords {
- if strings.Contains(text, kw.norm) {
- return true, `content "` + kw.src + `"`, "", nil
- }
+ if i >= 0 {
+ return true, `content "` + n.keywords[i].src + `"`, "", nil
}
return false, "", "", nil