Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MultiSearchAndReplacer ¶
type MultiSearchAndReplacer struct {
// contains filtered or unexported fields
}
MultiSearchAndReplacer is capable of searching for multiple strings in a stream of data and replacing it.
The algorithm that is used to perform string matching is based on the algorithm described in "Efficient String Matching: An Aid to Bibliographic Search" by Aho and Corasick:
https://doi.org/10.1145%2F360825.360855
Noteworthy differences between the algorithm as described in the paper and this implementation include:
The goto function g(state, a) is implemented as a hash table, meaning memory usage is not proportional to the alphabet.
Instead of an output function that returns a set of needles matching at a given location, every node in the goto graph holds the part of the needle matching up to that point. This makes it possible to emit the needle upon mismatch.
func NewMultiSearchAndReplacer ¶
func NewMultiSearchAndReplacer(needles [][]byte) (*MultiSearchAndReplacer, error)
NewMultiSearchAndReplacer creates a MultiSearchAndReplacer that is capable of matching the provided set of needles. An error is returned if one or more needles are empty or contained inside each other.
func (*MultiSearchAndReplacer) SearchAndReplace ¶
func (s *MultiSearchAndReplacer) SearchAndReplace(dst io.Writer, src io.ByteReader, replacements [][]byte) error
SearchAndReplace reads data from a source and writes it to a sink with matching occurrences of the needles substituted by replacement strings.