-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathformat.go
61 lines (56 loc) · 1.08 KB
/
format.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
package main
import (
"strings"
"unicode"
)
// keyFilter
func (xj *xjson) keyFilter(str string) (string, string) {
temp := xj.keyCase(str)
if _, ok := xj.MapTag[temp]; !ok {
xj.MapTag[temp] = str
}
if xj.JSONTag {
return str, temp
}
xj.MapTag[temp] = ""
return str, temp
}
// change name to different case
func (xj *xjson) keyCase(str string) string {
var (
upperStr string
)
temp := strings.FieldsFunc(str, xj.XJSplit)
for y := 0; y < len(temp); y++ {
x := []rune(temp[y])
for i := 0; i < len(x); i++ {
if i == 0 && y == 0 {
x[i] = unicode.ToUpper(x[i])
upperStr += string(x[i])
continue
}
if xj.UpperCase {
x[i] = unicode.ToUpper(x[i])
upperStr += string(x[i])
continue
}
if xj.LowerCase {
x[i] = unicode.ToLower(x[i])
upperStr += string(x[i])
continue
}
if i == 0 {
x[i] = unicode.ToUpper(x[i])
upperStr += string(x[i])
continue
}
upperStr += string(x[i])
continue
}
}
return upperStr
}
// 4 char
func (xj *xjson) XJSplit(r rune) bool {
return r == ':' || r == '.' || r == '-' || r == '_'
}