You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

18 lines
321 B

2 years ago
  1. package gentools
  2. import "strings"
  3. func FlagString[T ~uint32](value T, flags []T, names []string) string {
  4. if value == 0 {
  5. return "(none)"
  6. }
  7. parts := make([]string, 0, len(flags))
  8. for i, flag := range flags {
  9. if value&flag == flag {
  10. parts = append(parts, names[i])
  11. }
  12. }
  13. return strings.Join(parts, "|")
  14. }