aca

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2019 License: MIT Imports: 2 Imported by: 0

README

ACA

ACA is a AC automation implementation for Go.

Documentation

Documentation can be found at Godoc

Example


func TestACA(t *testing.T) {
	strs := []string{"say", "she", "he", "her", "shr"}
	aca := New(
		strs,
		GroupCleaners(
			NewSkipsCleaner([]rune("-|}+=)(&")),
			NewIgnoreCaseCleaner(),
		),
	)

	{
		var contains QueryContainsProcessor
		aca.Process("yaSherhs", &contains)
		if !contains.Result() {
			t.Fatal("ACA check contained in failed")
		}
	}

	{
		var matched QueryMatchedProcessor
		aca.Process("yaShErhs", &matched)
		if !reflect.DeepEqual([]string{"ShE", "hE", "hEr"}, matched.Result()) {
			t.Fatal("ACA match failed")
		}
	}

	var replacement = '*'
	{
		var replace = NewReplaceMatchedHandler(replacement)
		aca.Process("yasherhs", replace)
		if replace.Result() != "ya****hs" {
			t.Fatal("ACA replace failed")
		}
	}

	{
		var replace = NewReplaceMatchedHandler(replacement)
		aca.Process("-y|a}s+h=e)r(h&s", replace)
		if replace.Result() != "-y|a}*+*=*)*(h&s" {
			t.Fatal("ACA replace with skipsCleaner failed")
		}
	}
}

LICENSE

MIT.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ACA

type ACA struct {
	// contains filtered or unexported fields
}

func New

func New(strs []string, cleaner Cleaner) *ACA

func (*ACA) Process

func (a *ACA) Process(str string, processor Processor)

type Cleaner added in v0.0.2

type Cleaner interface {
	Clean(runes IndexedRunes) IndexedRunes
}

func GroupCleaners added in v0.0.2

func GroupCleaners(cls ...Cleaner) Cleaner

func NewIgnoreCaseCleaner added in v0.0.2

func NewIgnoreCaseCleaner() Cleaner

func NewSkipsCleaner added in v0.0.2

func NewSkipsCleaner(skips []rune) Cleaner

type IndexedRune added in v0.0.2

type IndexedRune struct {
	Rune  rune
	Index int
}

type IndexedRunes added in v0.0.2

type IndexedRunes []IndexedRune

func (IndexedRunes) Runes added in v0.0.2

func (c IndexedRunes) Runes() []rune

func (IndexedRunes) String added in v0.0.2

func (c IndexedRunes) String() string

type Processor

type Processor interface {
	Init(str string, raw IndexedRunes)
	Process(runes IndexedRunes, matched string) (continu bool)
}

type QueryContainsProcessor added in v0.0.3

type QueryContainsProcessor struct {
	// contains filtered or unexported fields
}

func (*QueryContainsProcessor) Init added in v0.0.3

func (p *QueryContainsProcessor) Init(str string, raw IndexedRunes)

func (*QueryContainsProcessor) Process added in v0.0.3

func (*QueryContainsProcessor) Result added in v0.0.3

func (p *QueryContainsProcessor) Result() bool

type QueryMatchedProcessor added in v0.0.3

type QueryMatchedProcessor struct {
	// contains filtered or unexported fields
}

func (*QueryMatchedProcessor) Init added in v0.0.3

func (m *QueryMatchedProcessor) Init(str string, raw IndexedRunes)

func (*QueryMatchedProcessor) Process added in v0.0.3

func (m *QueryMatchedProcessor) Process(runes IndexedRunes, matched string) bool

func (*QueryMatchedProcessor) Result added in v0.0.3

func (m *QueryMatchedProcessor) Result() []string

type ReplaceMatchedHandler added in v0.0.3

type ReplaceMatchedHandler struct {
	// contains filtered or unexported fields
}

func NewReplaceMatchedHandler added in v0.0.3

func NewReplaceMatchedHandler(replacement rune) *ReplaceMatchedHandler

func (*ReplaceMatchedHandler) Init added in v0.0.3

func (p *ReplaceMatchedHandler) Init(str string, raw IndexedRunes)

func (*ReplaceMatchedHandler) Process added in v0.0.3

func (p *ReplaceMatchedHandler) Process(runes IndexedRunes, matched string) bool

func (*ReplaceMatchedHandler) Result added in v0.0.3

func (p *ReplaceMatchedHandler) Result() string

Jump to

Keyboard shortcuts

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