-
Notifications
You must be signed in to change notification settings - Fork 2
/
enum_yesno.go
78 lines (64 loc) · 1.38 KB
/
enum_yesno.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
68
69
70
71
72
73
74
75
76
77
78
// Code generated by "enumerator -type YesNo -linecomment -trimprefix"; DO NOT EDIT.
package form
import (
"fmt"
"strconv"
)
func _() {
// An "invalid array index" compiler error signifies that the constant values have changed.
// Re-run the stringer command to generate them again.
var x [1]struct{}
_ = x[YesNoUnknown-0]
_ = x[Yes-1]
_ = x[No-2]
}
const _YesNo_name = "Unknownyesno"
var _YesNo_index = [...]uint8{0, 7, 10, 12}
func (i YesNo) String() string {
if i >= YesNo(len(_YesNo_index)-1) {
return "YesNo(" + strconv.FormatInt(int64(i), 10) + ")"
}
return _YesNo_name[_YesNo_index[i]:_YesNo_index[i+1]]
}
func (i YesNo) MarshalText() ([]byte, error) {
return []byte(i.String()), nil
}
func (i *YesNo) UnmarshalText(text []byte) error {
val, err := ParseYesNo(string(text))
if err != nil {
return err
}
*i = val
return nil
}
func (i YesNo) IsUnknown() bool {
return i == YesNoUnknown
}
func (i YesNo) IsYes() bool {
return i == Yes
}
func (i YesNo) IsNo() bool {
return i == No
}
func ParseYesNo(s string) (YesNo, error) {
switch s {
case "Unknown":
return YesNoUnknown, nil
case "yes":
return Yes, nil
case "no":
return No, nil
default:
return YesNo(0), fmt.Errorf("invalid YesNo '%s'", s)
}
}
type YesNoOptions struct {
Unknown YesNo
Yes YesNo
No YesNo
}
var YesNoValues = YesNoOptions{
Unknown: YesNoUnknown,
Yes: Yes,
No: No,
}