Remove unused code.

This commit is contained in:
go-jet 2019-07-19 16:19:20 +02:00
parent c82c2d0b6b
commit a2ee0155ac
2 changed files with 3 additions and 161 deletions

View file

@ -8,42 +8,9 @@ import (
"unicode"
)
// CamelToSnake converts a given string to snake case
func CamelToSnake(s string) string {
var result string
var words []string
var lastPos int
rs := []rune(s)
for i := 0; i < len(rs); i++ {
if i > 0 && unicode.IsUpper(rs[i]) {
if initialism := startsWithInitialism(s[lastPos:]); initialism != "" {
words = append(words, initialism)
i += len(initialism) - 1
lastPos = i
continue
}
words = append(words, s[lastPos:i])
lastPos = i
}
}
// append the last word
if s[lastPos:] != "" {
words = append(words, s[lastPos:])
}
for k, word := range words {
if k > 0 {
result += "_"
}
result += strings.ToLower(word)
}
return result
// SnakeToCamel returns a string converted from snake case to uppercase
func SnakeToCamel(s string) string {
return snakeToCamel(s, true)
}
func snakeToCamel(s string, upperCase bool) string {
@ -54,28 +21,6 @@ func snakeToCamel(s string, upperCase bool) string {
words := strings.Split(s, "_")
//// if there is no underscore, first try commons and then just return
//if len(words) == 1 {
// if exception := snakeToCamelExceptions[words[0]]; len(exception) > 0 {
// return exception
// }
//
// if upperCase {
// if upper := strings.ToUpper(words[0]); commonInitialisms[upper] {
// return upper
// }
// }
//
// w := []rune(s)
// if upperCase {
// w[0] = unicode.ToUpper(w[0])
// } else {
// w[0] = unicode.ToLower(w[0])
// }
//
// return string(w)
//}
for i, word := range words {
if exception := snakeToCamelExceptions[word]; len(exception) > 0 {
result += exception
@ -117,28 +62,6 @@ func camelizeWord(word string, force bool) string {
return string(runes)
}
// SnakeToCamel returns a string converted from snake case to uppercase
func SnakeToCamel(s string) string {
return snakeToCamel(s, true)
}
// SnakeToCamelLower returns a string converted from snake case to lowercase
func SnakeToCamelLower(s string) string {
return snakeToCamel(s, false)
}
// startsWithInitialism returns the initialism if the given string begins with it
func startsWithInitialism(s string) string {
var initialism string
// the longest initialism is 5 char, the shortest 2
for i := 1; i <= 5; i++ {
if len(s) > i-1 && commonInitialisms[s[:i]] {
initialism = s[:i]
}
}
return initialism
}
// commonInitialisms, taken from
// https://github.com/golang/lint/blob/206c0f020eba0f7fbcfbc467a5eb808037df2ed6/lint.go#L731
var commonInitialisms = map[string]bool{