-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathword.go
64 lines (57 loc) · 1.14 KB
/
word.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package namecase
// word Is the word and kind
type word struct {
kind wordKind
word string
}
func (w word) String() string {
return w.word
}
func (w word) convert(kind wordKind) string {
switch kind {
case upperWordCase:
return w.Upper()
case lowerWordCase:
return w.Lower()
case titleWordCase:
return w.Title()
case initialismsWordCase:
return w.Initialisms()
default:
return w.word
}
}
// Initialisms If it's an acronym, it's all capital letters.
func (w word) Initialisms() string {
if _, ok := commonInitialisms[w.word]; ok {
return upper(w.word)
}
return w.Title()
}
// Title returns capitalize the first letter of other lower case.
func (w word) Title() string {
switch w.kind {
case lowerWordCase, upperWordCase:
return title(string(w.word))
default:
return w.word
}
}
// Lower returns all lowercase.
func (w word) Lower() string {
switch w.kind {
case upperWordCase, titleWordCase:
return lower(string(w.word))
default:
return w.word
}
}
// Upper returns all uppercase.
func (w word) Upper() string {
switch w.kind {
case lowerWordCase, titleWordCase:
return upper(string(w.word))
default:
return w.word
}
}