Skip to content

Commit

Permalink
标签读取转换
Browse files Browse the repository at this point in the history
  • Loading branch information
swxctx committed Dec 20, 2018
1 parent ad601fc commit d9f137f
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions format.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package main

import (
"strings"
"unicode"
)

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 {
temp := strings.FieldsFunc(str, xj.XJSplit)
var (
upperStr string
)
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 == '_'
}

0 comments on commit d9f137f

Please sign in to comment.