Documentation ¶
Overview ¶
Package trw wraps around various text processing functions from the standard Go library to allow for functional composition of operations, also minimising memory allocations.
Example ¶
package main import "fmt" func main() { src := []byte("*SomeSome* example _text_") res := rewriter.Do(src) fmt.Println(string(res)) } var rewriter = Seq( Delete(LitN("Some", 1)), Replace(Patt(`[[:space:]]+`), " "), Expand(`_([^_]+)_`, `<i>${1}</i>`), Expand(`\*([^\*]+)\*`, `<b>${1}</b>`), )
Output: <b>Some</b> example <i>text</i>
Index ¶
- type Matcher
- type Rewriter
- func Delete(match Matcher) Rewriter
- func Expand(patt, subst string) Rewriter
- func ExpandN(patt, subst string, n int) Rewriter
- func ExpandRe(re *regexp.Regexp, subst string) Rewriter
- func ExpandReN(re *regexp.Regexp, subst string, n int) Rewriter
- func Replace(match Matcher, subst string) Rewriter
- func Seq(rewriters ...Rewriter) Rewriter
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Matcher ¶
Matcher is a type of a function that, given a byte slice, returns a slice holding the index pairs identifying all successive matches, or nil if there is no match.
func LitN ¶ added in v0.6.0
LitN creates a Matcher for the given string literal that matches up to n times.
func PattN ¶ added in v0.6.0
PattN creates a Matcher for the given regular expression pattern, matching up to n times.
type Rewriter ¶
Rewriter is an opaque type representing a text rewriting operation.
func Expand ¶
Expand creates a Rewriter that applies Regexp.Expand() operation to every match of the given regular expression pattern.
func ExpandN ¶ added in v0.6.0
ExpandN creates a Rewriter that applies Regexp.Expand() operation to the first n matches of the given regular expression pattern.
func ExpandRe ¶
ExpandRe creates a Rewriter that applies Regexp.Expand() operation to all matches of the given regular expression object.
func ExpandReN ¶ added in v0.6.0
ExpandReN creates a Rewriter that applies Regexp.Expand() operation to the first n matches of the given regular expression object.