Documentation
¶
Index ¶
- Constants
- type AhoCorasick
- func (ac AhoCorasick) FindAll(haystack string) []Match
- func (ac AhoCorasick) Iter(haystack string) Iter
- func (ac AhoCorasick) IterByte(haystack []byte) Iter
- func (ac AhoCorasick) IterOverlapping(haystack string) Iter
- func (ac AhoCorasick) IterOverlappingByte(haystack []byte) Iter
- func (ac AhoCorasick) PatternCount() int
- type AhoCorasickBuilder
- type Finder
- type Iter
- type Match
- type Opts
- type Replacer
Constants ¶
const ( // Use standard match semantics, which support overlapping matches. When // used with non-overlapping matches, matches are reported as they are seen. StandardMatch matchKind = iota // Use leftmost-first match semantics, which reports leftmost matches. // When there are multiple possible leftmost matches, the match // corresponding to the pattern that appeared earlier when constructing // the automaton is reported. // This does **not** support overlapping matches or stream searching LeftMostFirstMatch // Use leftmost-longest match semantics, which reports leftmost matches. // When there are multiple possible leftmost matches, the longest match is chosen. LeftMostLongestMatch )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AhoCorasick ¶
type AhoCorasick struct {
// contains filtered or unexported fields
}
AhoCorasick is the main data structure that does most of the work
func (AhoCorasick) FindAll ¶
func (ac AhoCorasick) FindAll(haystack string) []Match
FindAll returns the matches found in the haystack
func (AhoCorasick) Iter ¶
func (ac AhoCorasick) Iter(haystack string) Iter
Iter gives an iterator over the built patterns
func (AhoCorasick) IterByte ¶
func (ac AhoCorasick) IterByte(haystack []byte) Iter
IterByte gives an iterator over the built patterns
func (AhoCorasick) IterOverlapping ¶
func (ac AhoCorasick) IterOverlapping(haystack string) Iter
Iter gives an iterator over the built patterns with overlapping matches
func (AhoCorasick) IterOverlappingByte ¶
func (ac AhoCorasick) IterOverlappingByte(haystack []byte) Iter
IterOverlappingByte gives an iterator over the built patterns with overlapping matches
func (AhoCorasick) PatternCount ¶
func (ac AhoCorasick) PatternCount() int
type AhoCorasickBuilder ¶
type AhoCorasickBuilder struct {
// contains filtered or unexported fields
}
AhoCorasickBuilder defines a set of options applied before the patterns are built
func NewAhoCorasickBuilder ¶
func NewAhoCorasickBuilder(o Opts) AhoCorasickBuilder
NewAhoCorasickBuilder creates a new AhoCorasickBuilder based on Opts
func (*AhoCorasickBuilder) Build ¶
func (a *AhoCorasickBuilder) Build(patterns []string) AhoCorasick
Build builds a (non)deterministic finite automata from the user provided patterns
func (*AhoCorasickBuilder) BuildByte ¶
func (a *AhoCorasickBuilder) BuildByte(patterns [][]byte) AhoCorasick
BuildByte builds a (non)deterministic finite automata from the user provided patterns
type Iter ¶
type Iter interface {
Next() *Match
}
Iter is an iterator over matches found on the current haystack it gives the user more granular control. You can chose how many and what kind of matches you need.
type Match ¶
type Match struct {
// contains filtered or unexported fields
}
A representation of a match reported by an Aho-Corasick automaton.
A match has two essential pieces of information: the identifier of the pattern that matched, along with the start and end offsets of the match in the haystack.
type Opts ¶
type Opts struct { AsciiCaseInsensitive bool MatchOnlyWholeWords bool MatchKind matchKind DFA bool }
Opts defines a set of options applied before the patterns are built MatchOnlyWholeWords does filtering after matching with MatchKind this could lead to situations where, in this case, nothing is matched
trieBuilder := NewAhoCorasickBuilder(Opts{ MatchOnlyWholeWords: true, MatchKind: LeftMostLongestMatch, DFA: false, }) trie := trieBuilder.Build([]string{"testing", "testing 123"}) result := trie.FindAll("testing 12345") len(result) == 0
this is due to the fact LeftMostLongestMatch is the matching strategy "testing 123" is found but then is filtered out by MatchOnlyWholeWords use MatchOnlyWholeWords with caution
type Replacer ¶
type Replacer struct {
// contains filtered or unexported fields
}
func NewReplacer ¶
func (Replacer) ReplaceAll ¶
ReplaceAll replaces the matches found in the haystack according to the user provided slice `replaceWith` It panics, if `replaceWith` has length different from the patterns that it was built with
func (Replacer) ReplaceAllFunc ¶
ReplaceAllFunc replaces the matches found in the haystack according to the user provided function it gives fine grained control over what is replaced. A user can chose to stop the replacing process early by returning false in the lambda In that case, everything from that point will be kept as the original haystack
func (Replacer) ReplaceAllWith ¶
ReplaceAllWith replaces the matches found in the haystack according with replacement.