replace

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2020 License: MIT Imports: 2 Imported by: 18

README

Streaming text replacement

GoDoc

This package provides a x/text/transform.Transformer implementation that replaces text

Example

package main

import (
	"io"
	"os"

	"github.com/icholy/replace"
	"golang.org/x/text/transform"
)

func main() {
	f, _ := os.Open("file")
	defer f.Close()

	r := transform.NewReader(f, transform.Chain(
		replace.String("foo", "bar"),
		replace.Bytes([]byte("thing"), []byte("test")),
	))

	_, _ = io.Copy(os.Stdout, r)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Transformer

type Transformer struct {
	transform.NopResetter
	// contains filtered or unexported fields
}

Transformer replaces text in a stream See: http://golang.org/x/text/transform

func Bytes

func Bytes(old, new []byte) Transformer

Bytes returns a transformer that replaces all instances of old with new. Unlike bytes.Replace, empty old values don't match anything.

func String

func String(old, new string) Transformer

String returns a transformer that replaces all instances of old with new. Unlike strings.Replace, empty old values don't match anything.

func (Transformer) Transform

func (t Transformer) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error)

Transform implements golang.org/x/text/transform#Transformer

Jump to

Keyboard shortcuts

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