core/config/varpattern.go
2023-11-03 02:13:12 +01:00

32 lines
756 B
Go

package config
import (
"fmt"
"regexp"
)
type VarPattern struct {
Open string
Close string
}
func (vp *VarPattern) getPatternCaptureName() string {
return fmt.Sprintf("%s([^%s]+)%s", regexp.QuoteMeta(vp.Open), regexp.QuoteMeta(string(vp.Close[:1])), regexp.QuoteMeta((vp.Close)))
}
func (vp *VarPattern) getPatternVar() string {
return fmt.Sprintf("(%s.+%s)", regexp.QuoteMeta(vp.Open), regexp.QuoteMeta(vp.Close))
}
func (vp *VarPattern) getPatternVarName(name string) string {
return fmt.Sprintf("%s%s%s", regexp.QuoteMeta(vp.Open), name, regexp.QuoteMeta(vp.Close))
}
func NewVarPattern(open string, close string) *VarPattern {
return &VarPattern{open, close}
}
func DefaultVarPattern() *VarPattern {
return NewVarPattern("{%", "%}")
}