/
regexp.go
37 lines (29 loc) · 660 Bytes
/
regexp.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package funcs
import (
"sync"
"github.com/hairyhenderson/gomplate/conv"
"github.com/hairyhenderson/gomplate/regexp"
)
var (
reNS *ReFuncs
reNSInit sync.Once
)
// ReNS -
func ReNS() *ReFuncs {
reNSInit.Do(func() { reNS = &ReFuncs{} })
return reNS
}
// AddReFuncs -
func AddReFuncs(f map[string]interface{}) {
f["regexp"] = ReNS
}
// ReFuncs -
type ReFuncs struct{}
// Replace -
func (f *ReFuncs) Replace(re, replacement string, input interface{}) string {
return regexp.Replace(re, replacement, conv.ToString(input))
}
// Match -
func (f *ReFuncs) Match(re string, input interface{}) bool {
return regexp.Match(re, conv.ToString(input))
}