text

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contains

func Contains(s []string, e string) bool

func GetFieldByRegex

func GetFieldByRegex(regex, data string, fields []string) (results map[string]string, err error)

func GroupWithMultipleRegex

func GroupWithMultipleRegex(j1 string, j2 string, key string, data string) ([]string, error)

func GroupWithRegexFilter

func GroupWithRegexFilter(j string, fields []string, first int, last int, data string) ([]string, error)

从json字串中提取Splitter,

func IndentSection2

func IndentSection2(txt string) []string

func InitializeStruct

func InitializeStruct(t reflect.Type, v reflect.Value)

func RegexSplit

func RegexSplit(re string, text string) []string

Types

type Splitter

type Splitter struct {
	Regex string `json:"regex"`
	Name  string `json:"name"`
	Flags string `json:"flags"`
	Pcre  bool   `json:"pcre"`
	// contains filtered or unexported fields
}

func NewSplitterFromJson

func NewSplitterFromJson(j string) (*Splitter, error)

func NewSplitterFromMap

func NewSplitterFromMap(m map[string]string) (*Splitter, error)

func (Splitter) Input

func (s Splitter) Input(text string) (*SplitterResult, error)

func (Splitter) PCREInput

func (s Splitter) PCREInput(text string) (*SplitterResult, error)

func (Splitter) PCRERevert

func (s Splitter) PCRERevert(text string) (string, error)

func TestPCRERegexp(t *testing.T) {

func (Splitter) Revert

func (s Splitter) Revert(text string) (string, error)

type SplitterResult

type SplitterResult struct {
	// 与Python版本的attr类似,指定保持到结果的字段名称
	Attr   []string
	Result []map[string]string
}

func IndentSection

func IndentSection(txt string) *SplitterResult

func SplitterProcessOneTime

func SplitterProcessOneTime(m map[string]string, data string) (*SplitterResult, error)

func (SplitterResult) Cell

func (s SplitterResult) Cell(index int, field string) (string, error)

获取正则匹配结果的指定Cell

func (SplitterResult) CombinKey

func (s SplitterResult) CombinKey(keys []string) ([]string, error)

按照多个key的组合进行分组 返回分组后__match__组成的字符串列表,在返回结果中并不包含分组字段的相关信息,纯粹就是一个聚合功能,用于后续继续处理

func (SplitterResult) ConcatString

func (s SplitterResult) ConcatString(fields []string, first int,
	offset int, key string) ([]string, error)

主要用于文本的预处理,将匹配结果以给定关键字为key,进行拼接 如果fields字段为nil或长度为0,则用__match__进行拼接,否则用fields包含的字段进行拼接 first和offset同时为-1时,表示在所有结果中进行拼接 first为负,表示从末尾开始计数,-1表示最后,相当与last(s.Result)-1,first = len(s.Result) + first offset为-1时,表示从first直到s.Result的末尾 注意:最终数据以各关键字在文本中出现的先后为顺序

func (SplitterResult) Dump

func (s SplitterResult) Dump(m map[string]string, count int, t reflect.Type) (interface{}, error)

与MapToFields类似,但是需要提供数据的类型,最终将数据dump成为指定结构

func (SplitterResult) Filter

func (s SplitterResult) Filter(fields []string, first int, offset int) ([]string, error)

主要用于文本的预处理 如果fields字段为nil或长度为0,则用__match__进行拼接,否则用fields包含的字段进行拼接 first和offset同时为-1时,表示在所有结果中进行拼接 first为负,表示从末尾开始计数,-1表示最后,相当与last(s.Result)-1,first = len(s.Result) + first offset为-1时,表示从first直到s.Result的末尾

func (SplitterResult) GroupWith

func (s SplitterResult) GroupWith(other *SplitterResult, key string) ([]string, error)

将两个匹配结果集进行组合,主要用于文本预处理场景,用于将两个匹配结果进行拼接 拼接的方法: 1.只有包含了关键字字段的结果才能进行拼接 2.拼接保持了s中的顺序

func (SplitterResult) GroupWithCombinKey

func (s SplitterResult) GroupWithCombinKey(other *SplitterResult, leftKey []string, rightKey []string) ([]string, error)

将两个匹配结果集进行组合,主要用于文本预处理场景,用于将两个匹配结果进行拼接 拼接的方法: 1.只有包含了关键字字段的结果才能进行拼接, 2.拼接保持了s中的顺序

func (*SplitterResult) Iterator

func (sp *SplitterResult) Iterator() *SplitterResultIterator

func (SplitterResult) Json

func (s SplitterResult) Json() ([]byte, error)

将正则匹配结果转换为json字符串

func (SplitterResult) Len

func (s SplitterResult) Len() int

func (SplitterResult) MapToFields

func (s SplitterResult) MapToFields(m map[string]string, count int) (interface{}, error)

从分割结果中取出COUNT行,如果有需要,还可以将原来结果中的字段,映射为指定字段

func (SplitterResult) One

func (s SplitterResult) One() (map[string]string, bool)

func (SplitterResult) Projection

func (sp SplitterResult) Projection(multipleField []string, sep string, pairFields [][]string) (map[string]string, error)

set security nat source rule-set OUT_TO_IN_DY_RULESET rule out_to_in_rule1 match destination-address 20.1.2.2/32 set security nat source rule-set OUT_TO_IN_DY_RULESET rule out_to_in_rule1 then source-nat interface set security nat source rule-set OUT_TO_IN_DY_RULESET rule out_to_in_rule2 match destination-address 172.20.2.10/32 set security nat source rule-set OUT_TO_IN_DY_RULESET rule out_to_in_rule2 match destination-port 1234 to 2222 set security nat source rule-set OUT_TO_IN_DY_RULESET rule out_to_in_rule2 match destination-port 3333 to 3335 set security nat source rule-set OUT_TO_IN_DY_RULESET rule out_to_in_rule2 then source-nat interface multipleField字段定义的数据,将进行拼接,比如: dport=1234-2222 dport=3333-3335,最终返回{dport: "1234-2222,3333-3335"} 不在multipleField中的字段,返回最后的不为空的值,比如:[{"name": "testName"}, {"name": ""}],返回{"name": "testName"}

func (SplitterResult) RowJson

func (s SplitterResult) RowJson(index int) ([]byte, error)

将匹配结果中指定行转换为json字符串

type SplitterResultIterator

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

func (*SplitterResultIterator) HasNext

func (it *SplitterResultIterator) HasNext() bool

func (*SplitterResultIterator) Next

func (it *SplitterResultIterator) Next() (int, []string, map[string]string)

Jump to

Keyboard shortcuts

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