search

package
v0.0.0-...-20d847b Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

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.

Jump to

Keyboard shortcuts

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