Documentation
¶
Overview ¶
Authored by icholy (https://github.com/icholy/replace)
Index ¶
- Variables
- func Chain(r io.Reader, tt ...transform.Transformer) io.Reader
- func ReplaceText(cmd *cobra.Command)
- type RegexpTransformer
- func Regexp(re *regexp.Regexp, new []byte) *RegexpTransformer
- func RegexpFunc(re *regexp.Regexp, replace func([]byte) []byte) *RegexpTransformer
- func RegexpIndexFunc(re *regexp.Regexp, replace func(src []byte, index []int) []byte) *RegexpTransformer
- func RegexpString(re *regexp.Regexp, template string) *RegexpTransformer
- func RegexpStringFunc(re *regexp.Regexp, replace func(string) string) *RegexpTransformer
- func RegexpStringSubmatchFunc(re *regexp.Regexp, replace func([]string) string) *RegexpTransformer
- func RegexpSubmatchFunc(re *regexp.Regexp, replace func([][]byte) []byte) *RegexpTransformer
- type Transformer
Constants ¶
This section is empty.
Variables ¶
var ExportCommands = utils.CommandGroup{ Command: &cobra.Command{ Use: "txt", Short: "Text related commands", }, Children: []func(*cobra.Command){ ReplaceText, }, }
Functions ¶
func ReplaceText ¶
Types ¶
type RegexpTransformer ¶
type RegexpTransformer struct { // MaxMatchSize is the maximum size of a regexp match. // If a match exceeds this limit, it may be omitted. // (Default is 2kb). MaxMatchSize int // contains filtered or unexported fields }
RegexpTransformer replaces regexp matches in a stream See: http://golang.org/x/text/transform Note: this Transformer is not safe for concurrent use.
func Regexp ¶
func Regexp(re *regexp.Regexp, new []byte) *RegexpTransformer
Regexp returns a transformer that replaces all matches of re with new
func RegexpFunc ¶
func RegexpFunc(re *regexp.Regexp, replace func([]byte) []byte) *RegexpTransformer
RegexpFunc returns a transformer that replaces all matches of re with the result of calling replace with the match. The []byte parameter passed to replace should not be modified and is not guaranteed to be valid after the function returns.
func RegexpIndexFunc ¶
func RegexpIndexFunc(re *regexp.Regexp, replace func(src []byte, index []int) []byte) *RegexpTransformer
RegexpIndexFunc returns a transformer that replaces all matches of re with the return value of replace. The replace function recieves the underlying src buffer and indexes into that buffer. The []byte parameter passed to replace should not be modified and is not guaranteed to be valid after the function returns.
func RegexpString ¶
func RegexpString(re *regexp.Regexp, template string) *RegexpTransformer
RegexpString returns a transformer that replaces all matches of re with template Inside template, $ signs are interpreted as in Expand, so for instance $1 represents the text of the first submatch.
func RegexpStringFunc ¶
func RegexpStringFunc(re *regexp.Regexp, replace func(string) string) *RegexpTransformer
RegexpStringFunc returns a transformer that replaces all matches of re with the result of calling replace with the match.
func RegexpStringSubmatchFunc ¶
func RegexpStringSubmatchFunc(re *regexp.Regexp, replace func([]string) string) *RegexpTransformer
RegexpStringSubmatchFunc returns a transformer that replaces all matches of re with the result of calling replace with the submatch.
func RegexpSubmatchFunc ¶
func RegexpSubmatchFunc(re *regexp.Regexp, replace func([][]byte) []byte) *RegexpTransformer
RegexpSubmatchFunc returns a transformer that replaces all matches of re with the result of calling replace with the submatch. The [][]byte parameter passed to replace should not be modified and is not guaranteed to be valid after the function returns.
func (*RegexpTransformer) Reset ¶
func (t *RegexpTransformer) Reset()
Reset resets the state and allows a Transformer to be reused.
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.