-
Notifications
You must be signed in to change notification settings - Fork 2
/
util.go
70 lines (61 loc) · 1013 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
63
64
65
66
67
68
69
70
package main
import (
"strings"
)
// ToBigCamelCase user_id => UserId
func ToBigCamelCase(str string) string {
result := ""
if str == "" {
return result
}
strs := strings.Split(str, "_")
for _, s := range strs {
r := []rune(s)
if len(r) > 0 {
for _, word := range Cfg.BigCamelCaseWords {
if word == s {
for i := range r {
r[i] -= 32
}
}
}
if r[0] >= 'a' && r[0] <= 'z' {
r[0] -= 32
}
result += string(r)
}
}
return result
}
// ToSmallCamelCase user_id => userId
func ToSmallCamelCase(str string) string {
result := ""
if str == "" {
return result
}
strs := strings.Split(str, "_")
for i, s := range strs {
r := []rune(s)
if len(r) > 0 {
if i == 0 {
result += string(r)
continue
}
for _, word := range Cfg.BigCamelCaseWords {
if word == s {
for j := range r {
r[j] -= 32
}
}
}
result += string(r)
}
}
return result
}
func MaxFunc(i, j int) int {
if i > j {
return i
}
return j
}