textfile

package module
v0.0.0-...-355c1af Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Filter

func Filter(r io.Reader, w io.Writer, ff ...FilterFunc) error

Filter reads data from a reader, transforms it with filter functions and writes the resulting data to a writer. Filter functions are applied in the specified order.

Types

type FilterFunc

type FilterFunc func(io.Reader, io.Writer) error

FilterFunc signature

func Expand

func Expand(re *regexp.Regexp, ff ...LookupFunc) FilterFunc

Format returns a filter function that transforms a line by using fmt.Sprintf(format, string(line))

func Format

func Format(format string) FilterFunc

Format returns a filter function that transforms a line by using fmt.Sprintf(format, string(line))

func Grep

func Grep(re *regexp.Regexp, invert bool) FilterFunc

Grep returns a filter function that only let's through matching lines. If invert is true, only non-matching lines are returned.

func Join

func Join() FilterFunc

Join returns a filter function that reads lines from a reader, removes trailing whitespace, joins lines marked with the continuation character (\) and writes the result to a writer. Line numbers are preserved by inserting newlines after continued lines.

func Map

func Map(ff ...MapFunc) FilterFunc

Map returns a filter function that reads lines from a reader, transforms them with the given map functions, and writes the result to a writer.

func PrependSource

func PrependSource(source string) FilterFunc

PrependSource returns a filter function that prepends the given source (with {n} replaced by the current line number), followed by a zero byte to the line. This function must not be reused with other streams to ensure the line count is correct.

type LookupFunc

type LookupFunc func(string) (string, bool)

func LookupEnv

func LookupEnv() LookupFunc

LookupEnv returns a lookup function that uses the current environment as data source.

func LookupMap

func LookupMap(m map[string]string) LookupFunc

LookupMap returns a lookup function that uses the given map as data source.

func LookupStatic

func LookupStatic(val string) LookupFunc

LookupStatic returns a lookup function that returns the given value. If the value contains %s, all occurences will be replaced by the name that is looked up.

type MapFunc

type MapFunc func([]byte) ([]byte, error)

Jump to

Keyboard shortcuts

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