MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / init

Method init

internal/re/regexp.go:58–97  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

56}
57
58func (this *Regexp) init() {
59 this.id = atomic.AddUint64(&lastId, 1)
60 this.idString = "re:" + types.String(this.id)
61
62 if len(this.exp) == 0 {
63 return
64 }
65
66 var exp = strings.TrimSpace(this.exp)
67
68 // 去掉前面的(?...)
69 if prefixReg.MatchString(exp) {
70 var matches = prefixReg.FindStringSubmatch(exp)
71 var modifiers = matches[1]
72 if strings.Contains(modifiers, "i") {
73 this.isCaseInsensitive = true
74 }
75 exp = exp[len(matches[0]):]
76 }
77
78 var keywords = this.ParseKeywords(exp)
79
80 var filteredKeywords = []string{}
81 var minLength = 1
82 var isValid = true
83 for _, keyword := range keywords {
84 if len(keyword) <= minLength {
85 isValid = false
86 break
87 }
88 }
89 if isValid {
90 filteredKeywords = keywords
91 }
92
93 this.keywords = filteredKeywords
94 if len(filteredKeywords) > 0 {
95 this.keywordsMap = NewRuneTree(filteredKeywords)
96 }
97}
98
99func (this *Regexp) Keywords() []string {
100 return this.keywords

Callers 2

MustCompileFunction · 0.45
NewRegexpFunction · 0.45

Calls 6

ParseKeywordsMethod · 0.95
NewRuneTreeFunction · 0.85
MatchStringMethod · 0.80
FindStringSubmatchMethod · 0.80
StringMethod · 0.45
ContainsMethod · 0.45

Tested by

no test coverage detected