maxim2266 / trw

Functional composition of text processing operations.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

trw: Text Re-Writer.

GoDoc Go Report Card License: BSD 3 Clause

Package trw wraps around various text processing functions from the standard Go library to allow for functional composition of operations, also minimising memory consumption.

Example

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>`),
)

Installation

go get -u github.com/maxim2266/trw

About the package

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.

About

Functional composition of text processing operations.

License:BSD 3-Clause "New" or "Revised" License


Languages

Language:Go 99.0%Language:Makefile 1.0%