Back to

Package acascii

Latest Go to latest

The latest major version is .

Published: May 19, 2020 | License: BSD-3-Clause | Module:


Package ac provides an implementation of the Aho-Corasick string matching algorithm. Throughout this code []byte is referred to as a blice.

Copyright (c) 2013 CloudFlare, Inc.

Originally from




var ErrNotASCII = errors.New("non-ASCII input")

ErrNotASCII is returned when the dictionary input is not ASCII

type Matcher

type Matcher struct {
	// contains filtered or unexported fields

Matcher contains a list of blices to match against

func Compile

func Compile(dictionary [][]byte) (*Matcher, error)

Compile creates a new Matcher using a list of []byte

func CompileString

func CompileString(dictionary []string) (*Matcher, error)

CompileString creates a new Matcher used to match against a set of strings (this is a helper to make initialization easy)

func MustCompile

func MustCompile(dictionary [][]byte) *Matcher

MustCompile returns a Matcher or panics

func MustCompileString

func MustCompileString(dictionary []string) *Matcher

MustCompileString returns a Matcher or panics

func (*Matcher) FindAll

func (m *Matcher) FindAll(in []byte) [][]byte

FindAll searches in for blices and returns all the blices found in the original dictionary

func (*Matcher) FindAllString

func (m *Matcher) FindAllString(in string) []string

FindAllString searches in for blices and returns all the blices (as strings) found as in the original dictionary



m := MustCompileString([]string{"Superman", "uperman", "perman", "erman"})
matches := m.FindAllString("The Man Of Steel: Superman")
[Superman uperman perman erman]

func (*Matcher) Match

func (m *Matcher) Match(in []byte) bool

Match returns true if the input slice contains any subslices

func (*Matcher) MatchString

func (m *Matcher) MatchString(in string) bool

MatchString returns true if the input slice contains any subslices



m := MustCompileString([]string{"Superman", "uperman", "perman", "erman"})
contains := m.MatchString("The Man Of Steel: Superman")

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier