flect.go 810 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. Package flect is a new inflection engine to replace [https://github.com/markbates/inflect](https://github.com/markbates/inflect) designed to be more modular, more readable, and easier to fix issues on than the original.
  3. */
  4. package flect
  5. import (
  6. "strings"
  7. "unicode"
  8. )
  9. var spaces = []rune{'_', ' ', ':', '-', '/'}
  10. func isSpace(c rune) bool {
  11. for _, r := range spaces {
  12. if r == c {
  13. return true
  14. }
  15. }
  16. return unicode.IsSpace(c)
  17. }
  18. func xappend(a []string, ss ...string) []string {
  19. for _, s := range ss {
  20. s = strings.TrimSpace(s)
  21. for _, x := range spaces {
  22. s = strings.Trim(s, string(x))
  23. }
  24. if _, ok := baseAcronyms[strings.ToUpper(s)]; ok {
  25. s = strings.ToUpper(s)
  26. }
  27. if s != "" {
  28. a = append(a, s)
  29. }
  30. }
  31. return a
  32. }
  33. func abs(x int) int {
  34. if x < 0 {
  35. return -x
  36. }
  37. return x
  38. }