-
Notifications
You must be signed in to change notification settings - Fork 1
/
op_endswith.go
59 lines (50 loc) · 936 Bytes
/
op_endswith.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package uni_filter
import (
"errors"
"fmt"
"strings"
)
type OPEnds struct {
s string
ignoreCase bool
is string
}
func (op *OPEnds) Name() string {
if op.ignoreCase {
return "iends"
}
return "ends"
}
func (op *OPEnds) parse() error {
if op.s == "" {
return errors.New(fmt.Sprintf("op param for %s can not be empty", op.Name()))
}
if op.ignoreCase {
op.is = strings.ToLower(op.s)
}
return nil
}
func (op *OPEnds) check(v any, exists bool) bool {
if !exists {
return false
}
s := convert2string(v)
if op.ignoreCase {
s = strings.ToLower(s)
return strings.HasSuffix(s, op.is)
} else {
return strings.HasSuffix(s, op.s)
}
}
func NewOPEnds(s string) (OP, error) {
op := &OPEnds{s: s}
return op, op.parse()
}
func NewOPIEnds(s string) (OP, error) {
op := &OPEnds{s: s, ignoreCase: true}
return op, op.parse()
}
func init() {
register("ends", NewOPEnds)
register("iends", NewOPIEnds)
}