util.go 293 B

1234567891011121314151617
  1. package chat
  2. import "strings"
  3. func humanJoin(items []string) string {
  4. count := len(items)
  5. switch count {
  6. case 0:
  7. return ""
  8. case 1:
  9. return items[0]
  10. case 2:
  11. return items[0] + " and " + items[1]
  12. default:
  13. return strings.Join(items[:count-1], ", ") + ", and " + items[count-1]
  14. }
  15. }