core/config/varpattern.go

32 lines
756 B
Go
Raw Normal View History

2023-11-02 22:04:28 +00:00
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("{%", "%}")
}