-
-
Notifications
You must be signed in to change notification settings - Fork 30
/
flect.go
43 lines (38 loc) · 810 Bytes
/
flect.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
/*
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.
*/
package flect
import (
"strings"
"unicode"
)
var spaces = []rune{'_', ' ', ':', '-', '/'}
func isSpace(c rune) bool {
for _, r := range spaces {
if r == c {
return true
}
}
return unicode.IsSpace(c)
}
func xappend(a []string, ss ...string) []string {
for _, s := range ss {
s = strings.TrimSpace(s)
for _, x := range spaces {
s = strings.Trim(s, string(x))
}
if _, ok := baseAcronyms[strings.ToUpper(s)]; ok {
s = strings.ToUpper(s)
}
if s != "" {
a = append(a, s)
}
}
return a
}
func abs(x int) int {
if x < 0 {
return -x
}
return x
}