mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-12-25 06:26:34 +08:00
优化代码
This commit is contained in:
@@ -3,9 +3,11 @@
|
||||
package re
|
||||
|
||||
import (
|
||||
"github.com/iwind/TeaGo/types"
|
||||
"regexp"
|
||||
"regexp/syntax"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
)
|
||||
|
||||
var prefixReg = regexp.MustCompile(`^\(\?([\w\s]+)\)`) // (?x)
|
||||
@@ -13,6 +15,8 @@ var prefixReg2 = regexp.MustCompile(`^\(\?([\w\s]*:)`) // (?x: ...
|
||||
var braceZeroReg = regexp.MustCompile(`^{\s*0*\s*}`) // {0}
|
||||
var braceZeroReg2 = regexp.MustCompile(`^{\s*0*\s*,`) // {0, x}
|
||||
|
||||
var lastId uint64
|
||||
|
||||
type Regexp struct {
|
||||
exp string
|
||||
rawRegexp *regexp.Regexp
|
||||
@@ -21,6 +25,9 @@ type Regexp struct {
|
||||
isCaseInsensitive bool
|
||||
keywords []string
|
||||
keywordsMap RuneMap
|
||||
|
||||
id uint64
|
||||
idString string
|
||||
}
|
||||
|
||||
func MustCompile(exp string) *Regexp {
|
||||
@@ -50,6 +57,9 @@ func NewRegexp(rawRegexp *regexp.Regexp) *Regexp {
|
||||
}
|
||||
|
||||
func (this *Regexp) init() {
|
||||
this.id = atomic.AddUint64(&lastId, 1)
|
||||
this.idString = "re:" + types.String(this.id)
|
||||
|
||||
if len(this.exp) == 0 {
|
||||
return
|
||||
}
|
||||
@@ -202,6 +212,10 @@ func (this *Regexp) ParseKeywords(exp string) (keywords []string) {
|
||||
return
|
||||
}
|
||||
|
||||
func (this *Regexp) IdString() string {
|
||||
return this.idString
|
||||
}
|
||||
|
||||
func (this *Regexp) parseKeyword(subExp string) (result []rune) {
|
||||
if len(subExp) == 0 {
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user