-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
match.go
57 lines (45 loc) · 957 Bytes
/
match.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
package match
import (
"os"
"strconv"
"strings"
)
type Match int
const (
CASE_SENSITIVE Match = iota
CASE_INSENSITIVE
)
func (m Match) Equal(s, t string) bool {
if m == CASE_INSENSITIVE {
strings.EqualFold(s, t)
}
return s == t
}
func (m Match) HasPrefix(s, prefix string) bool {
if m == CASE_INSENSITIVE {
return strings.HasPrefix(strings.ToLower(s), strings.ToLower(prefix))
}
return strings.HasPrefix(s, prefix)
}
func (m Match) TrimPrefix(s, prefix string) string {
if m.HasPrefix(s, prefix) {
return s[len(prefix):]
}
return s
}
var match = CASE_SENSITIVE
func init() {
switch os.Getenv("CARAPACE_MATCH") {
case "CASE_INSENSITIVE", strconv.Itoa(int(CASE_INSENSITIVE)):
match = CASE_INSENSITIVE
}
}
func Equal(s, t string) bool {
return match.Equal(s, t)
}
func HasPrefix(s, prefix string) bool {
return match.HasPrefix(s, prefix)
}
func TrimPrefix(s, prefix string) string {
return match.TrimPrefix(s, prefix)
}