File: text.go

package info (click to toggle)
wuzz 0.4.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 372 kB
  • sloc: makefile: 6
file content (34 lines) | stat: -rw-r--r-- 605 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package formatter

import (
	"io"
	"regexp"
)

type TextFormatter struct {
}

func (f *TextFormatter) Format(writer io.Writer, data []byte) error {
	_, err := writer.Write(data)
	return err
}

func (f *TextFormatter) Title() string {
	return "[text]"
}

func (f *TextFormatter) Searchable() bool {
	return true
}

func (f *TextFormatter) Search(q string, body []byte) ([]string, error) {
	search_re, err := regexp.Compile(q)
	if err != nil {
		return nil, err
	}
	ret := make([]string, 0, 16)
	for _, match := range search_re.FindAll(body, 1000) {
		ret = append(ret, string(match))
	}
	return ret, nil
}