gosed

package module
v0.0.0-...-01ec013 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2019 License: GPL-3.0 Imports: 3 Imported by: 0

README

go-sed

A sed implementation in Go. This project aims to be a fully compatable sed clone writen in pure Go with no dependencies. There is also a Go api that you can call to integrate this into other Go programs.

For example, the follwoing will indent the text by five spaces:

myTxt := `
if (!the_program) {
  if (optind < argc) {
	char *arg = argv[optind++];
    the_program = compile_string(the_program, arg, strlen(arg));
  } else {
      usage(4);
  }
}`

cmd := sed.MustCompileProgram('s/^/     /')

fmt.Println(cmd.FilterString(myTxt))

Command Line Tool

This also command line tool that you can use in place of the standard sed command. You can install it by running go get github.com/zkry/go-sed/cmd/gosed.

API

The current API for the package is as follows

func MustCompile(program string, opt Options) Program
func Compile(program string, opt Options) (Program, error)

func (p Program) Copy(data []byte) Program

func (p Program) Filter(data []byte) []byte
func (p Program) FilterString(data []byte, opt Options) []byte

func (p Program) FilterA(str string) string
func (p Program) FilterStringA(data []byte, opt Options) []byte

Roadmap

  • Thourough test suite for compatability with sed.
  • GNU sed features.
  • Implement more command line flags.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Info

func Info(program string) []lexer.Item

Types

type Options

type Options struct {
	SupressOutput     bool // Prevents program from automatically outputing line.
	AppendFile        bool // Makes the w command append to file.
	ExtendRegexp      bool // Use extended version of regexp
	PreviousLinesRead int
}

type Program

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

func Compile

func Compile(program string, opt Options) (*Program, ast.ErrorList)

Compile compiles a sed script and returns a program upon successfull compilation. If unsuccessfull errors are returned.

func MustCompile

func MustCompile(program string, opt Options) *Program

MustCompile takes a sed script and compiles it into a program. Panics if errors are found in script.

func (*Program) Filter

func (p *Program) Filter(data []byte) []byte

func (*Program) FilterA

func (p *Program) FilterA(data []byte) []byte

FilterA performs a normal filter operation but does not reset the state after completion. You can repeatedly call FilterA to process input line by line.

func (*Program) FilterString

func (p *Program) FilterString(data string) string

func (*Program) FilterStringA

func (p *Program) FilterStringA(data string) string

FilterStringA performs a normal filter operation but does not reset the state after completion. Operation is performed on string and returns a string. You can repeatedly call FilterA to process input line by line.

Directories

Path Synopsis
cmd
gosed command

Jump to

Keyboard shortcuts

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