mirror of https://github.com/dmarkham/enumer.git
95 lines
2.3 KiB
Plaintext
95 lines
2.3 KiB
Plaintext
|
|
const _DayName = "MondayTuesdayWednesdayThursdayFridaySaturdaySunday"
|
|
|
|
var _DayIndex = [...]uint8{0, 6, 13, 22, 30, 36, 44, 50}
|
|
|
|
const _DayLowerName = "mondaytuesdaywednesdaythursdayfridaysaturdaysunday"
|
|
|
|
func (i Day) String() string {
|
|
if i < 0 || i >= Day(len(_DayIndex)-1) {
|
|
return fmt.Sprintf("Day(%d)", i)
|
|
}
|
|
return _DayName[_DayIndex[i]:_DayIndex[i+1]]
|
|
}
|
|
|
|
func (Day) Values() []string {
|
|
return DayStrings()
|
|
}
|
|
|
|
// An "invalid array index" compiler error signifies that the constant values have changed.
|
|
// Re-run the stringer command to generate them again.
|
|
func _DayNoOp() {
|
|
var x [1]struct{}
|
|
_ = x[Monday-(0)]
|
|
_ = x[Tuesday-(1)]
|
|
_ = x[Wednesday-(2)]
|
|
_ = x[Thursday-(3)]
|
|
_ = x[Friday-(4)]
|
|
_ = x[Saturday-(5)]
|
|
_ = x[Sunday-(6)]
|
|
}
|
|
|
|
var _DayValues = []Day{Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday}
|
|
|
|
var _DayNameToValueMap = map[string]Day{
|
|
_DayName[0:6]: Monday,
|
|
_DayLowerName[0:6]: Monday,
|
|
_DayName[6:13]: Tuesday,
|
|
_DayLowerName[6:13]: Tuesday,
|
|
_DayName[13:22]: Wednesday,
|
|
_DayLowerName[13:22]: Wednesday,
|
|
_DayName[22:30]: Thursday,
|
|
_DayLowerName[22:30]: Thursday,
|
|
_DayName[30:36]: Friday,
|
|
_DayLowerName[30:36]: Friday,
|
|
_DayName[36:44]: Saturday,
|
|
_DayLowerName[36:44]: Saturday,
|
|
_DayName[44:50]: Sunday,
|
|
_DayLowerName[44:50]: Sunday,
|
|
}
|
|
|
|
var _DayNames = []string{
|
|
_DayName[0:6],
|
|
_DayName[6:13],
|
|
_DayName[13:22],
|
|
_DayName[22:30],
|
|
_DayName[30:36],
|
|
_DayName[36:44],
|
|
_DayName[44:50],
|
|
}
|
|
|
|
// DayString retrieves an enum value from the enum constants string name.
|
|
// Throws an error if the param is not part of the enum.
|
|
func DayString(s string) (Day, error) {
|
|
if val, ok := _DayNameToValueMap[s]; ok {
|
|
return val, nil
|
|
}
|
|
|
|
if val, ok := _DayNameToValueMap[strings.ToLower(s)]; ok {
|
|
return val, nil
|
|
}
|
|
return 0, fmt.Errorf("%s does not belong to Day values", s)
|
|
}
|
|
|
|
// DayValues returns all values of the enum
|
|
func DayValues() []Day {
|
|
return _DayValues
|
|
}
|
|
|
|
// DayStrings returns a slice of all String values of the enum
|
|
func DayStrings() []string {
|
|
strs := make([]string, len(_DayNames))
|
|
copy(strs, _DayNames)
|
|
return strs
|
|
}
|
|
|
|
// IsADay returns "true" if the value is listed in the enum definition. "false" otherwise
|
|
func (i Day) IsADay() bool {
|
|
for _, v := range _DayValues {
|
|
if i == v {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|