package regexp2
import (
"sync"
)
type RuntimeEngineData struct {
Caps map [int ]int
CapNames map [string ]int
CapsList []string
CapSize int
FindFirstChar func (*Runner ) bool
Execute func (*Runner ) error
ExecuteQuick func (*Runner ) error
StringPrefixFilter StringPrefixFilter
}
type cacheKey struct {
pattern string
opt RegexOptions
maintainCaptureOrder bool
maxBacktrackingStackSize int
}
func RegisterEngine (pattern string , engine RuntimeEngineData , options ...CompileOption ) {
c := newCompileConfig (options )
enginesMu .Lock ()
engines [cacheKeyFromConfig (pattern , c )] = engine
enginesMu .Unlock ()
}
func newEngineRegexp(pattern string , c compileConfig , engine RuntimeEngineData ) *Regexp {
re := &Regexp {
pattern : pattern ,
options : c .regexOptions ,
debug : c .debug ,
caps : engine .Caps ,
capnames : engine .CapNames ,
capslist : engine .CapsList ,
capsize : engine .CapSize ,
MatchTimeout : DefaultMatchTimeout ,
optimizations : c .optimizations ,
findFirstChar : engine .FindFirstChar ,
execute : engine .Execute ,
executeQuick : engine .ExecuteQuick ,
stringPrefixFilter : engine .StringPrefixFilter ,
}
re .initCaches ()
return re
}
func getEngineRegexp(pattern string , c compileConfig ) *Regexp {
enginesMu .RLock ()
engine , ok := engines [cacheKeyFromConfig (pattern , c )]
enginesMu .RUnlock ()
if !ok {
return nil
}
return newEngineRegexp (pattern , c , engine )
}
func cacheKeyFromConfig(pattern string , c compileConfig ) cacheKey {
return cacheKey {
pattern : pattern ,
opt : c .regexOptions ,
maintainCaptureOrder : c .maintainCaptureOrder ,
maxBacktrackingStackSize : c .optimizations .MaxBacktrackingStackSize ,
}
}
var (
enginesMu sync .RWMutex
engines = map [cacheKey ]RuntimeEngineData {}
)
The pages are generated with Golds v0.8.7 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .