taboo

package
v1.0.11 Latest Latest
Warning

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

Go to latest
Published: May 13, 2023 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetCacheReg

func SetCacheReg(name string, reg *MatchReg) error

func SetCacheTree

func SetCacheTree(name string, tree *MatchTree) error

func SetDefaultReg

func SetDefaultReg(tree *MatchReg)

func SetDefaultTree

func SetDefaultTree(tree *MatchTree)

Types

type Match

type Match struct {
	Start  int    `json:"start"`             // 起始位置
	End    int    `json:"end"`               // 结束位置
	Word   string `json:"word"`              // 匹配到的词
	Fuzzy  bool   `json:"fuzzy,omitempty"`   // 是否模糊匹配
	RegExp string `json:"reg_exp,omitempty"` // 模糊匹配使用的正则表达式
}

Match 匹配的结果数据结构

type MatchReg

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

MatchReg 正则匹配2

func GetCacheReg

func GetCacheReg(name string) (*MatchReg, bool)

func GetDefaultReg

func GetDefaultReg() *MatchReg

func NewReg

func NewReg(words []string) *MatchReg

NewReg 构造一个正则匹配

func (*MatchReg) Contains

func (mr *MatchReg) Contains(text string) bool

Contains 是否包含

func (*MatchReg) Find

func (mr *MatchReg) Find(text string) []Match

Find 找到一个匹配

func (*MatchReg) FindAll

func (mr *MatchReg) FindAll(text string) []Match

FindAll 查找全部

func (*MatchReg) ReplaceAll

func (mr *MatchReg) ReplaceAll(text, repl string) string

ReplaceAll 全部替换

type MatchTree

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

MatchTree 精确匹配搜索树,用于对指定列表中的字符串进行精确匹配

func GetCacheTree

func GetCacheTree(name string) (*MatchTree, bool)

func GetDefaultTree

func GetDefaultTree() *MatchTree

func NewTree

func NewTree(t []string) *MatchTree

NewTree 根据传入敏感词列表创建一个新的敏感词匹配树

func (*MatchTree) Contains

func (tree *MatchTree) Contains(text string) bool

Contains 输入的文本中是否包含敏感词

func (*MatchTree) Find

func (tree *MatchTree) Find(text string, n int) []Match

Find 找到输入的文本中的敏感词,最多匹配 n 次

func (*MatchTree) FindAll

func (tree *MatchTree) FindAll(text string) []Match

FindAll 找到输入的文本中的全部敏感词

func (*MatchTree) ReplaceAll

func (tree *MatchTree) ReplaceAll(text, repl string) string

ReplaceAll 替换全部敏感词为repl

Jump to

Keyboard shortcuts

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