forked from mangalorg/libmangal
-
Notifications
You must be signed in to change notification settings - Fork 1
/
format_enumer.go
142 lines (119 loc) · 3.6 KB
/
format_enumer.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
133
134
135
136
137
138
139
140
141
142
// Code generated by "enumer -type=Format -trimprefix=Format -json -yaml -text"; DO NOT EDIT.
package libmangal
import (
"encoding/json"
"fmt"
"strings"
)
const _FormatName = "PDFImagesCBZTARTARGZZIP"
var _FormatIndex = [...]uint8{0, 3, 9, 12, 15, 20, 23}
const _FormatLowerName = "pdfimagescbztartargzzip"
func (i Format) String() string {
i -= 1
if i >= Format(len(_FormatIndex)-1) {
return fmt.Sprintf("Format(%d)", i+1)
}
return _FormatName[_FormatIndex[i]:_FormatIndex[i+1]]
}
// An "invalid array index" compiler error signifies that the constant values have changed.
// Re-run the stringer command to generate them again.
func _FormatNoOp() {
var x [1]struct{}
_ = x[FormatPDF-(1)]
_ = x[FormatImages-(2)]
_ = x[FormatCBZ-(3)]
_ = x[FormatTAR-(4)]
_ = x[FormatTARGZ-(5)]
_ = x[FormatZIP-(6)]
}
var _FormatValues = []Format{FormatPDF, FormatImages, FormatCBZ, FormatTAR, FormatTARGZ, FormatZIP}
var _FormatNameToValueMap = map[string]Format{
_FormatName[0:3]: FormatPDF,
_FormatLowerName[0:3]: FormatPDF,
_FormatName[3:9]: FormatImages,
_FormatLowerName[3:9]: FormatImages,
_FormatName[9:12]: FormatCBZ,
_FormatLowerName[9:12]: FormatCBZ,
_FormatName[12:15]: FormatTAR,
_FormatLowerName[12:15]: FormatTAR,
_FormatName[15:20]: FormatTARGZ,
_FormatLowerName[15:20]: FormatTARGZ,
_FormatName[20:23]: FormatZIP,
_FormatLowerName[20:23]: FormatZIP,
}
var _FormatNames = []string{
_FormatName[0:3],
_FormatName[3:9],
_FormatName[9:12],
_FormatName[12:15],
_FormatName[15:20],
_FormatName[20:23],
}
// FormatString retrieves an enum value from the enum constants string name.
// Throws an error if the param is not part of the enum.
func FormatString(s string) (Format, error) {
if val, ok := _FormatNameToValueMap[s]; ok {
return val, nil
}
if val, ok := _FormatNameToValueMap[strings.ToLower(s)]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to Format values", s)
}
// FormatValues returns all values of the enum
func FormatValues() []Format {
return _FormatValues
}
// FormatStrings returns a slice of all String values of the enum
func FormatStrings() []string {
strs := make([]string, len(_FormatNames))
copy(strs, _FormatNames)
return strs
}
// IsAFormat returns "true" if the value is listed in the enum definition. "false" otherwise
func (i Format) IsAFormat() bool {
for _, v := range _FormatValues {
if i == v {
return true
}
}
return false
}
// MarshalJSON implements the json.Marshaler interface for Format
func (i Format) MarshalJSON() ([]byte, error) {
return json.Marshal(i.String())
}
// UnmarshalJSON implements the json.Unmarshaler interface for Format
func (i *Format) UnmarshalJSON(data []byte) error {
var s string
if err := json.Unmarshal(data, &s); err != nil {
return fmt.Errorf("Format should be a string, got %s", data)
}
var err error
*i, err = FormatString(s)
return err
}
// MarshalText implements the encoding.TextMarshaler interface for Format
func (i Format) MarshalText() ([]byte, error) {
return []byte(i.String()), nil
}
// UnmarshalText implements the encoding.TextUnmarshaler interface for Format
func (i *Format) UnmarshalText(text []byte) error {
var err error
*i, err = FormatString(string(text))
return err
}
// MarshalYAML implements a YAML Marshaler for Format
func (i Format) MarshalYAML() (interface{}, error) {
return i.String(), nil
}
// UnmarshalYAML implements a YAML Unmarshaler for Format
func (i *Format) UnmarshalYAML(unmarshal func(interface{}) error) error {
var s string
if err := unmarshal(&s); err != nil {
return err
}
var err error
*i, err = FormatString(s)
return err
}