-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtag.go
67 lines (60 loc) · 1.03 KB
/
tag.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
60
61
62
63
64
65
66
67
package astconf
import (
"strings"
)
type fieldTag struct {
name string
omit bool
opts tagOptions
}
func parseTag(s string) (tag fieldTag) {
if s == "" {
return
}
if s == "-" {
tag.omit = true
return
}
if idx := strings.Index(s, ","); idx != -1 {
tag.name = s[:idx]
tag.opts = tagOptions(strings.Split(s[idx+1:], ","))
} else {
tag.name = s
}
return
}
func (ft *fieldTag) Contains(option string) bool {
return ft.opts.Contains(option)
}
type tagOptions []string
func (o tagOptions) Contains(option string) bool {
if o == nil {
return false
}
for _, s := range o {
if s == option {
return true
}
}
return false
}
/*
func isValidTag(s string) bool {
if s == "" {
return false
}
for _, c := range s {
switch {
case strings.ContainsRune("!#$%&()*+-./:<=>?@[]^_{|}~ ", c):
// Backslash and quote chars are reserved, but
// otherwise any punctuation chars are allowed
// in a tag name.
default:
if !unicode.IsLetter(c) && !unicode.IsDigit(c) {
return false
}
}
}
return true
}
*/