-
Notifications
You must be signed in to change notification settings - Fork 0
/
formatters.go
77 lines (70 loc) · 1.17 KB
/
formatters.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
65
66
67
68
69
70
71
72
73
74
75
76
77
package wordcase
import (
"unicode"
"unicode/utf8"
)
// empty is a zero-sized empty constant
var empty = struct{}{}
// WordSet is a collection of words
type WordSet map[string]struct{}
// GoLintKeywords are words that golint considers to be common initialisms that should always be same-cased
// (this list is https://github.com/golang/lint/blob/master/lint.go#L740 @ 2020-05-17)
var GoLintKeywords = []string{
"acl",
"api",
"ascii",
"cpu",
"css",
"dns",
"eof",
"guid",
"html",
"http",
"https",
"id",
"ip",
"json",
"lhs",
"qps",
"ram",
"rhs",
"rpc",
"sla",
"smtp",
"sql",
"ssh",
"tcp",
"tls",
"ttl",
"udp",
"ui",
"uid",
"uuid",
"uri",
"url",
"utf8",
"vm",
"xml",
"xmpp",
"xsrf",
"xss",
}
// UsefulKeyWords are words that you may want to be same-cased
var UsefulKeyWords = append(
GoLintKeywords,
"grpc",
"tml",
"toml",
"yaml",
"yml",
)
// A Formatter is used to format a token
type Formatter func(string) string
// UppercaseFirst returns the given string with the first rune converted to uppercase
func UppercaseFirst(s string) string {
if s == "" {
return ""
}
r, n := utf8.DecodeRuneInString(s)
return string(unicode.ToUpper(r)) + s[n:]
}