filter

package
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package filter provides fundamentals for each filters.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MustRegister

func MustRegister(name string, f Factory)

MustRegister registers a filter, panic if failed.

func Register

func Register(name string, f Factory) error

Register registers a filter with name.

Types

type Base

type Base struct {
	Reader *bufio.Reader
	// contains filtered or unexported fields
}

Base is base of filters. It provides common features for filter.

func (*Base) Close

func (b *Base) Close() error

Close closes head filter.

func (*Base) Init

func (b *Base) Init(r io.ReadCloser, readNext BaseReadNext)

Init initializes Base object.

func (*Base) Read

func (b *Base) Read(buf []byte) (int, error)

func (*Base) ReadLine

func (b *Base) ReadLine() ([]byte, error)

ReadLine reads a line as []byte.

type BaseReadNext

type BaseReadNext func(buf *bytes.Buffer) error

BaseReadNext is callback to read next data hunk to buf

type Factory

type Factory func(*resource.Resource, Params) (*resource.Resource, error)

Factory is filter factory.

func Find

func Find(name string) Factory

Find finds a filter.

type Grep

type Grep struct {
	Base
	// contains filtered or unexported fields
}

Grep represents grep like filter.

func NewGrep

func NewGrep(r io.ReadCloser, re *regexp.Regexp, match bool, lf LineFilter, lnum bool, cnum int) *Grep

NewGrep creates an instance of grep filter.

type Hash

type Hash struct {
	Base
	// contains filtered or unexported fields
}

Hash represents hash filter.

func NewHash

func NewHash(r io.ReadCloser, h hash.Hash, enc hashEncoder) *Hash

NewHash creates a hash filter instance.

type Head struct {
	Base
	// contains filtered or unexported fields
}

Head is "head" like filter.

func NewHead

func NewHead(r io.ReadCloser, start, limit uint) *Head

NewHead creates an instance of head filter.

type LTSV

type LTSV struct {
	Base
	// contains filtered or unexported fields
}

LTSV represents a structure for LTSV (labeled tab separated value)

func NewLTSV

func NewLTSV(r io.ReadCloser, label string, re *regexp.Regexp, match bool, cut []string) *LTSV

NewLTSV creates a new instance of LTSV.

type LineFilter

type LineFilter func([]byte) []byte

LineFilter is a line filter.

var TrimEOL LineFilter = func(b []byte) []byte {
	l := len(b)
	if l >= 1 && b[l-1] == '\n' {
		c := 1
		if l >= 2 && b[len(b)-2] == '\r' {
			c++
		}
		return b[:len(b)-c]
	}
	return b
}

TrimEOL trims EOL bytes.

func NewCutLF

func NewCutLF(sep []byte, n int) LineFilter

NewCutLF creates a cut line filter with sep and position.

func (LineFilter) Apply

func (lf LineFilter) Apply(b []byte) []byte

Apply applies a filter to a line bytes.

func (LineFilter) Chain

func (lf LineFilter) Chain(second LineFilter) LineFilter

Chain createa a new LineFilters which chains two LineFilters.

type Params

type Params map[string]string

Params represents parameters for filter.

func (Params) Bool

func (p Params) Bool(n string, value bool) bool

Bool gets bool value from Params by name.

func (Params) Int

func (p Params) Int(n string, value int) int

Int gets int value from Params by name.

func (Params) String

func (p Params) String(n string, value string) string

String gets string value from Params by name.

Directories

Path Synopsis
Package count provides count filter.
Package count provides count filter.
Package cut provides "cut" command like filter for NVGD.
Package cut provides "cut" command like filter for NVGD.
Package echarts provides chart drawing filter
Package echarts provides chart drawing filter
Package htmltable provides HTML table filter.
Package htmltable provides HTML table filter.
Package indexhtml provides index HTML filter.
Package indexhtml provides index HTML filter.
Package jsonarray provides JSON array filter.
Package jsonarray provides JSON array filter.
Package markdown provides markdown filter which render HTML from Markdown.
Package markdown provides markdown filter which render HTML from Markdown.
Package pager provides a NVGD filter to split resource into pages.
Package pager provides a NVGD filter to split resource into pages.
Package tail provides tail filter.
Package tail provides tail filter.
Package texttable provides table formatter in plain text.
Package texttable provides table formatter in plain text.
Package trdsql provides https://github.com/noborus/trdsql filter
Package trdsql provides https://github.com/noborus/trdsql filter

Jump to

Keyboard shortcuts

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