fix application bug

This commit is contained in:
Jeff
2019-05-13 11:19:18 +08:00
committed by zryfish
parent 996d6fe4c5
commit 5462f51e65
717 changed files with 87703 additions and 53426 deletions

View File

@@ -159,16 +159,20 @@ func SplitByFormat(data, format string) []string {
return result
}
type byLength []string
type byInitialism []string
func (s byLength) Len() int {
func (s byInitialism) Len() int {
return len(s)
}
func (s byLength) Swap(i, j int) {
func (s byInitialism) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
}
func (s byLength) Less(i, j int) bool {
return len(s[i]) < len(s[j])
func (s byInitialism) Less(i, j int) bool {
if len(s[i]) != len(s[j]) {
return len(s[i]) < len(s[j])
}
return strings.Compare(s[i], s[j]) > 0
}
// Prepares strings by splitting by caps, spaces, dashes, and underscore
@@ -222,7 +226,7 @@ func lower(str string) string {
// Camelize an uppercased word
func Camelize(word string) (camelized string) {
for pos, ru := range word {
for pos, ru := range []rune(word) {
if pos > 0 {
camelized += string(unicode.ToLower(ru))
} else {
@@ -278,7 +282,7 @@ func ToHumanNameTitle(name string) string {
for _, w := range in {
uw := upper(w)
if !isInitialism(uw) {
out = append(out, upper(w[:1])+lower(w[1:]))
out = append(out, Camelize(w))
} else {
out = append(out, w)
}
@@ -296,7 +300,7 @@ func ToJSONName(name string) string {
out = append(out, lower(w))
continue
}
out = append(out, upper(w[:1])+lower(w[1:]))
out = append(out, Camelize(w))
}
return strings.Join(out, "")
}
@@ -322,19 +326,15 @@ func ToGoName(name string) string {
uw := upper(w)
mod := int(math.Min(float64(len(uw)), 2))
if !isInitialism(uw) && !isInitialism(uw[:len(uw)-mod]) {
uw = upper(w[:1]) + lower(w[1:])
uw = Camelize(w)
}
out = append(out, uw)
}
result := strings.Join(out, "")
if len(result) > 0 {
ud := upper(result[:1])
ru := []rune(ud)
if unicode.IsUpper(ru[0]) {
result = ud + result[1:]
} else {
result = "X" + ud + result[1:]
if !unicode.IsUpper([]rune(result)[0]) {
result = "X" + result
}
}
return result