match

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NON = iota
	AND
)
View Source
const (
	DFA      = 0
	ASSEMBLE = 1
	REGEXP   = 2
)

Variables

This section is empty.

Functions

func NewRegRule

func NewRegRule(str string) (*regRule, error)

func TrimString

func TrimString(s string) string

TrimString returns s without leading and trailing ASCII space.

Types

type AssembleMather

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

func NewAssembleMather

func NewAssembleMather() *AssembleMather

func (*AssembleMather) Build

func (a *AssembleMather) Build(words []string)

func (*AssembleMather) Match

func (a *AssembleMather) Match(text string, repl rune) (word []string, desensitization string)

type DFAMatcher

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

func NewDFAMather

func NewDFAMather() *DFAMatcher

func (*DFAMatcher) Build

func (d *DFAMatcher) Build(words []string)

Build 构造DFA树

func (*DFAMatcher) Match

func (d *DFAMatcher) Match(text string, repl rune) (sensitiveWords []string, replaceText string)

Match 查找替换发现的敏感词

type DFANode

type DFANode struct {
	End  bool
	Next map[rune]*DFANode
}

func (*DFANode) AddChild

func (n *DFANode) AddChild(c rune) *DFANode

func (*DFANode) AddWord

func (n *DFANode) AddWord(word string)

func (*DFANode) FindChild

func (n *DFANode) FindChild(c rune) *DFANode

type MatchService

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

func NewMatchService

func NewMatchService() *MatchService

func (*MatchService) Build

func (m *MatchService) Build(words []string)

Build 同一个配置中支持三种配置

func (*MatchService) Match

func (m *MatchService) Match(text string, repl rune) (sensitiveWords []string, replaceText string)

Match 只要有一个规则就返回;

type Matcher

type Matcher interface {
	//Build build Matcher
	Build(words []string)

	//Match return match sensitive words
	Match(text string, repl rune) ([]string, string)
}

type RegexpMather

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

func NewRegexpMatcher

func NewRegexpMatcher() *RegexpMather

func (*RegexpMather) Build

func (a *RegexpMather) Build(words []string)

func (*RegexpMather) Match

func (a *RegexpMather) Match(text string, repl rune) (word []string, desensitization string)

Match 所有的正则只有命中一个就返回;

Jump to

Keyboard shortcuts

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