forked from abice/go-enum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommented_enum.go
132 lines (114 loc) · 3.44 KB
/
commented_enum.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// Code generated by go-enum
// DO NOT EDIT!
package example
import (
"fmt"
"strings"
)
const (
// CommentedValue1 is a Commented of type Value1
// Commented value 1
CommentedValue1 Commented = iota
// CommentedValue2 is a Commented of type Value2
CommentedValue2
// CommentedValue3 is a Commented of type Value3
// Commented value 3
CommentedValue3
)
const _CommentedName = "value1value2value3"
var _CommentedMap = map[Commented]string{
0: _CommentedName[0:6],
1: _CommentedName[6:12],
2: _CommentedName[12:18],
}
// String implements the Stringer interface.
func (x Commented) String() string {
if str, ok := _CommentedMap[x]; ok {
return str
}
return fmt.Sprintf("Commented(%d)", x)
}
var _CommentedValue = map[string]Commented{
_CommentedName[0:6]: 0,
strings.ToLower(_CommentedName[0:6]): 0,
_CommentedName[6:12]: 1,
strings.ToLower(_CommentedName[6:12]): 1,
_CommentedName[12:18]: 2,
strings.ToLower(_CommentedName[12:18]): 2,
}
// ParseCommented attempts to convert a string to a Commented
func ParseCommented(name string) (Commented, error) {
if x, ok := _CommentedValue[name]; ok {
return x, nil
}
return Commented(0), fmt.Errorf("%s is not a valid Commented", name)
}
// MarshalText implements the text marshaller method
func (x Commented) MarshalText() ([]byte, error) {
return []byte(x.String()), nil
}
// UnmarshalText implements the text unmarshaller method
func (x *Commented) UnmarshalText(text []byte) error {
name := string(text)
tmp, err := ParseCommented(name)
if err != nil {
return err
}
*x = tmp
return nil
}
const (
// Skipped value
// Placeholder with a ',' in it. (for harder testing)
_ ComplexCommented = iota
// ComplexCommentedValue1 is a ComplexCommented of type Value1
// Commented value 1
ComplexCommentedValue1
// ComplexCommentedValue2 is a ComplexCommented of type Value2
ComplexCommentedValue2
// ComplexCommentedValue3 is a ComplexCommented of type Value3
// Commented value 3
ComplexCommentedValue3
)
const _ComplexCommentedName = "value1value2value3"
var _ComplexCommentedMap = map[ComplexCommented]string{
1: _ComplexCommentedName[0:6],
2: _ComplexCommentedName[6:12],
3: _ComplexCommentedName[12:18],
}
// String implements the Stringer interface.
func (x ComplexCommented) String() string {
if str, ok := _ComplexCommentedMap[x]; ok {
return str
}
return fmt.Sprintf("ComplexCommented(%d)", x)
}
var _ComplexCommentedValue = map[string]ComplexCommented{
_ComplexCommentedName[0:6]: 1,
strings.ToLower(_ComplexCommentedName[0:6]): 1,
_ComplexCommentedName[6:12]: 2,
strings.ToLower(_ComplexCommentedName[6:12]): 2,
_ComplexCommentedName[12:18]: 3,
strings.ToLower(_ComplexCommentedName[12:18]): 3,
}
// ParseComplexCommented attempts to convert a string to a ComplexCommented
func ParseComplexCommented(name string) (ComplexCommented, error) {
if x, ok := _ComplexCommentedValue[name]; ok {
return x, nil
}
return ComplexCommented(0), fmt.Errorf("%s is not a valid ComplexCommented", name)
}
// MarshalText implements the text marshaller method
func (x ComplexCommented) MarshalText() ([]byte, error) {
return []byte(x.String()), nil
}
// UnmarshalText implements the text unmarshaller method
func (x *ComplexCommented) UnmarshalText(text []byte) error {
name := string(text)
tmp, err := ParseComplexCommented(name)
if err != nil {
return err
}
*x = tmp
return nil
}