Package trw
wraps around various text processing functions from the standard
Go library to allow for functional composition of operations, also minimising
memory consumption.
func Example() {
src := []byte("*SomeSome* example _text_")
res := rewriter.Do(src)
fmt.Println(string(res))
// Output:
// <b>Some</b> example <i>text</i>
}
var rewriter = Seq(
Delete(LitN("Some", 1)),
Replace(Patt(`[[:space:]]+`), " "),
Expand(`_([^_]+)_`, `<i>${1}</i>`),
Expand(`\*([^\*]+)\*`, `<b>${1}</b>`),
)
go get -u github.com/maxim2266/trw
The package is most useful in situations where a number of text rewriting operations is to be applied sequentially to a large input byte slice. For this scenario the package provides:
- Functional composition of the existing or user-defined operations that can later be applied all at once;
- Memory optimisation using various techniques to minimise (re)allocations.