filter

package module
v0.0.0-...-c467cba Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 4, 2019 License: BSD-3-Clause Imports: 4 Imported by: 2

README

go-filter

GoDoc Build Status

go-filter provides a filtered line-based io.Reader.

Documentation

Overview

Package filter provides a filtered line-based io.Reader.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Func

type Func func(line []byte) bool

Func represents a line-matching function.

func After

func After(f Func, typ MatchType) Func

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 All

func All(f ...Func) Func

All matches the line if all of f match the current line.

func Alternate

func Alternate(f ...Func) Func

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 Any

func Any(f ...Func) Func

Any matches the line if any of f match the current line.

func Before

func Before(f Func, typ MatchType) Func

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 Contains

func Contains(tok []byte) Func

Contains matches the current line if it contains tok.

func ContainsString

func ContainsString(tok string) Func

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 HasPrefix

func HasPrefix(prefix []byte) Func

HasPrefix matches the current line if it starts with prefix.

func HasPrefixString

func HasPrefixString(prefix string) Func

HasPrefixString matches the current line if it starts with prefix.

func HasSuffix

func HasSuffix(suffix []byte) Func

HasSuffix matches the current line if it ends with suffix.

func HasSuffixString

func HasSuffixString(suffix string) Func

HasSuffixString matches the current line if it ends with suffix.

func Not

func Not(f Func) Func

Not inverts f and matches the current line if f doesn't match the line.

func Odd

func Odd() Func

Odd matches every second line including the first.

It is not safe to call concurrently or reuse.

func Previous

func Previous(f Func) Func

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 Regexp

func Regexp(r *regexp.Regexp) Func

Regexp uses an already compiled regular expression to match lines.

func RegexpString

func RegexpString(r string) Func

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.

const (
	// ExcludeCurrent instructs the matching function to exclude
	// the current line.
	ExcludeCurrent MatchType = true
	// IncludeCurrent instructs the matching function to include
	// the current line.
	IncludeCurrent MatchType = false
)

type Reader

type Reader struct {
	// contains filtered or unexported fields
}

Reader is a filtered line-based io.Reader.

func NewReader

func NewReader(r io.Reader, f Func) *Reader

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

func (r *Reader) Buffer(buf []byte, max int)

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.

func (*Reader) Read

func (r *Reader) Read(p []byte) (n int, err error)

Read implements io.Reader and reads from the underlying reader.

func (*Reader) WriteTo

func (r *Reader) WriteTo(w io.Writer) (n int64, err error)

WriteTo implements io.WriterTo and reads from the underlying reader.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL