sed

package
v0.0.0-...-bb8ed5d Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: GPL-3.0 Imports: 12 Imported by: 13

Documentation

Overview

Package sed implements the classic UNIX sed language in pure Go. The interface is very simple: a user compiles a program into an execution engine by calling New or NewQuiet. Then, the engine can Wrap() any io.Reader to lazily process the stream as you read from it.

All classic sed commands are supported, but since the package uses Go's regexp package for the regular expressions, the syntax for regexps will not be the same as a typical UNIX sed. In other words, instead of: s|ab\(c*\)d|\1|g you would say: s|ab(c*)d|$1|g. So this is a Go-flavored sed, rather than a drop-in replacement for a UNIX sed. Depending on your tastes, you will either consider this an improvement or completely brain-dead.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Engine

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

Engine is the compiled instruction stream for a sed program. It is the main type that users of the go-sed library will interact with.

func New

func New(program io.Reader) (*Engine, error)

New creates a new sed engine from a program. The program is executed via the Run method. If the provided program has any errors, the returned engine will be 'nil' and the error will be returned. Otherwise, the returned error will be nil.

func NewQuiet

func NewQuiet(program io.Reader) (*Engine, error)

NewQuiet creates a new sed engine from a program. It behaves exactly as New(), except it produces an engine that doesn't print lines by defualt. This is the classic '-n' sed behaviour.

func (*Engine) RunString

func (e *Engine) RunString(input string) (string, error)

RunString executes the program embodied by the Engine on the given string as input, returning the output string and any errors that occured.

func (*Engine) Wrap

func (e *Engine) Wrap(input io.Reader) io.Reader

Wrap supplies an io.Reader that applies the sed Engine to the given input. The sed program is run lazily against the input as the user asks for bytes. If you'd prefer to run all at once from string to string, use RunString instead.

Jump to

Keyboard shortcuts

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