package regexp2
var (
DefaultUnmarshalOptions = None
DefaultOptimizationOptions = OptimizationOptions {
MaxBacktrackingStackSize : 100000 ,
MaxCachedRuneBufferLength : 256 << 10 ,
MaxCachedReplaceBufferLength : 256 << 10 ,
MaxCachedReplacerDataEntries : 16 ,
MaxCachedReplacerDataBytes : 4 << 10 ,
DisableCharClassASCIIBitmap : false ,
}
)
type RegexOptions int32
func (o RegexOptions ) applyCompileOption (c *compileConfig ) {
c .regexOptions |= o
}
const (
None RegexOptions = 0x0
IgnoreCase RegexOptions = 0x0001
Multiline RegexOptions = 0x0002
ExplicitCapture RegexOptions = 0x0004
Singleline RegexOptions = 0x0010
IgnorePatternWhitespace RegexOptions = 0x0020
RightToLeft RegexOptions = 0x0040
ECMAScript RegexOptions = 0x0100
RE2 RegexOptions = 0x0200
Unicode RegexOptions = 0x0400
)
type OptimizationOptions struct {
MaxBacktrackingStackSize int
MaxCachedRuneBufferLength int
MaxCachedReplaceBufferLength int
MaxCachedReplacerDataEntries int
MaxCachedReplacerDataBytes int
DisableCharClassASCIIBitmap bool
}
type CompileOption interface {
applyCompileOption(*compileConfig )
}
type compileConfig struct {
regexOptions RegexOptions
optimizations OptimizationOptions
codeGen bool
debug bool
maintainCaptureOrder bool
}
type compileOptionFunc func (*compileConfig )
func (f compileOptionFunc ) applyCompileOption (c *compileConfig ) {
f (c )
}
func (o OptimizationOptions ) cacheReplacerData (replacement string ) bool {
if o .MaxCachedReplacerDataEntries == 0 {
return false
}
return keepCacheBytes (o .MaxCachedReplacerDataBytes , len (replacement ))
}
func keepCacheBytes(maxBytes , actualBytes int ) bool {
if maxBytes < 0 {
return true
}
return maxBytes > 0 && actualBytes <= maxBytes
}
func newCompileConfig(options []CompileOption ) compileConfig {
c := compileConfig {
optimizations : DefaultOptimizationOptions ,
}
for _ , option := range options {
if option != nil {
option .applyCompileOption (&c )
}
}
return c
}
func OptionMaxBacktrackingStackSize (n int ) CompileOption {
return compileOptionFunc (func (c *compileConfig ) {
c .optimizations .MaxBacktrackingStackSize = n
})
}
func OptionMaxCachedRuneBufferLength (n int ) CompileOption {
return compileOptionFunc (func (c *compileConfig ) {
c .optimizations .MaxCachedRuneBufferLength = n
})
}
func OptionMaxCachedReplaceBufferLength (n int ) CompileOption {
return compileOptionFunc (func (c *compileConfig ) {
c .optimizations .MaxCachedReplaceBufferLength = n
})
}
func OptionMaxCachedReplacerDataEntries (n int ) CompileOption {
return compileOptionFunc (func (c *compileConfig ) {
c .optimizations .MaxCachedReplacerDataEntries = n
})
}
func OptionMaxCachedReplacerDataBytes (n int ) CompileOption {
return compileOptionFunc (func (c *compileConfig ) {
c .optimizations .MaxCachedReplacerDataBytes = n
})
}
func OptionDisableCharClassASCIIBitmap () CompileOption {
return compileOptionFunc (func (c *compileConfig ) {
c .optimizations .DisableCharClassASCIIBitmap = true
})
}
func OptionIsCodeGen () CompileOption {
return compileOptionFunc (func (c *compileConfig ) {
c .codeGen = true
})
}
func OptionDebug () CompileOption {
return compileOptionFunc (func (c *compileConfig ) {
c .debug = true
})
}
func OptionMaintainCaptureOrder () CompileOption {
return compileOptionFunc (func (c *compileConfig ) {
c .maintainCaptureOrder = true
})
}
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 .