-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.go
62 lines (47 loc) · 958 Bytes
/
util.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
package markers
import (
"strings"
"unicode"
)
func IsUpper(s string) bool {
for _, r := range s {
if !unicode.IsUpper(r) && unicode.IsLetter(r) {
return false
}
}
return true
}
func IsLower(s string) bool {
for _, r := range s {
if !unicode.IsLower(r) && unicode.IsLetter(r) {
return false
}
}
return true
}
func IsDecimal(character rune) bool {
return '0' <= character && character <= '9'
}
func IsIdentifier(character rune, index int) bool {
return character == '_' || unicode.IsLetter(character) || unicode.IsDigit(character) && index > 0
}
func LowerCamelCase(str string) string {
isFirst := true
return strings.Map(func(r rune) rune {
if isFirst {
isFirst = false
return unicode.ToLower(r)
}
return r
}, str)
}
func UpperCamelCase(str string) string {
isFirst := true
return strings.Map(func(r rune) rune {
if isFirst {
isFirst = false
return unicode.ToUpper(r)
}
return r
}, str)
}