()
| 56 | } |
| 57 | |
| 58 | func (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 | |
| 99 | func (this *Regexp) Keywords() []string { |
| 100 | return this.keywords |
no test coverage detected