mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-21 22:10:27 +08:00
优化正则表达式/修复一些测试用例
This commit is contained in:
@@ -7,7 +7,7 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
var prefixReg = regexp.MustCompile(`^\(\?(\w+)\)`) // (?x)
|
||||
var prefixReg = regexp.MustCompile(`^\(\?([\w\s]+)\)`) // (?x)
|
||||
var prefixReg2 = regexp.MustCompile(`^\(\?([\w\s]*:)`) // (?x: ...
|
||||
var braceZero = regexp.MustCompile(`^{\s*0*\s*}`) // {0}
|
||||
var braceZero2 = regexp.MustCompile(`^{\s*0*\s*,`) // {0, x}
|
||||
@@ -18,6 +18,7 @@ type Regexp struct {
|
||||
|
||||
isStrict bool
|
||||
isCaseInsensitive bool
|
||||
keywords []string
|
||||
keywordsMap RuneMap
|
||||
}
|
||||
|
||||
@@ -67,11 +68,24 @@ func (this *Regexp) init() {
|
||||
}
|
||||
|
||||
var keywords = this.ParseKeywords(exp)
|
||||
this.keywords = keywords
|
||||
if len(keywords) > 0 {
|
||||
this.keywordsMap = NewRuneTree(keywords)
|
||||
}
|
||||
}
|
||||
|
||||
func (this *Regexp) Keywords() []string {
|
||||
return this.keywords
|
||||
}
|
||||
|
||||
func (this *Regexp) Raw() *regexp.Regexp {
|
||||
return this.rawRegexp
|
||||
}
|
||||
|
||||
func (this *Regexp) IsCaseInsensitive() bool {
|
||||
return this.isCaseInsensitive
|
||||
}
|
||||
|
||||
func (this *Regexp) MatchString(s string) bool {
|
||||
if this.keywordsMap != nil {
|
||||
var b = this.keywordsMap.Lookup(s, this.isCaseInsensitive)
|
||||
|
||||
Reference in New Issue
Block a user