Documentation ¶
Overview ¶
Package filter provides a filtered line-based io.Reader.
Index ¶
- type Func
- func After(f Func, typ MatchType) Func
- func All(f ...Func) Func
- func Alternate(f ...Func) Func
- func Any(f ...Func) Func
- func Before(f Func, typ MatchType) Func
- func Contains(tok []byte) Func
- func ContainsString(tok string) Func
- func Even() Func
- func HasPrefix(prefix []byte) Func
- func HasPrefixString(prefix string) Func
- func HasSuffix(suffix []byte) Func
- func HasSuffixString(suffix string) Func
- func Not(f Func) Func
- func Odd() Func
- func Previous(f Func) Func
- func Regexp(r *regexp.Regexp) Func
- func RegexpString(r string) Func
- type MatchType
- type Reader
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Func ¶
Func represents a line-matching function.
func After ¶
After matches every line after f matches the current line.
Whether to include or exclude the current line is controlled by typ. Either ExcludeCurrent or IncludeCurrent may be passed.
It is not safe to call concurrently or reuse.
func Alternate ¶
Alternate cycles through f, calling the n-th f to match the n-th line, it repeats once len(f) lines have been seen.
It is not safe to call concurrently or reuse.
func Before ¶
Before matches every line before f matches the current line.
Whether to include or exclude the current line is controlled by typ. Either ExcludeCurrent or IncludeCurrent may be passed.
It is not safe to call concurrently or reuse.
func ContainsString ¶
ContainsString matches the current line if it contains tok.
func Even ¶
func Even() Func
Even matches every second line excluding the first.
It is not safe to call concurrently or reuse.
func HasPrefixString ¶
HasPrefixString matches the current line if it starts with prefix.
func HasSuffixString ¶
HasSuffixString matches the current line if it ends with suffix.
func Odd ¶
func Odd() Func
Odd matches every second line including the first.
It is not safe to call concurrently or reuse.
func Previous ¶
Previous matches the current line iff f matches the previous line. It never matches the first line.
It is not safe to call concurrently or reuse.
func RegexpString ¶
RegexpString compiles a regular expression to match lines. It panics if the expression cannot be parsed.
type MatchType ¶
type MatchType bool
MatchType controls whether Before and After match the current line.
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader is a filtered line-based io.Reader.
func NewReader ¶
NewReader wraps r and returns a new reader that will only pass through reads where the line is matched by f. It reads line by line and preserves newlines and carriage returns.
func (*Reader) Buffer ¶
Buffer sets the initial buffer to use when scanning and the maximum size of buffer that may be allocated during scanning. The maximum token size is the larger of max and cap(buf). If max <= cap(buf), Read will use this buffer only and do no allocation.
By default, Read uses an internal buffer and sets the maximum token size to bufio.MaxScanTokenSize.
Buffer panics if it is called after reading has started.