52 lines
1023 B
Go
52 lines
1023 B
Go
/*
|
|
* @Date: 2021-06-10 14:33:29
|
|
* @LastEditors: viletyy
|
|
* @LastEditTime: 2021-06-10 14:40:55
|
|
* @FilePath: /yolk/word/word.go
|
|
*/
|
|
package word
|
|
|
|
import (
|
|
"strings"
|
|
"unicode"
|
|
)
|
|
|
|
// 全部转为大写
|
|
func ToUpper(s string) string {
|
|
return strings.ToUpper(s)
|
|
}
|
|
|
|
// 全部转为小写
|
|
func ToLower(s string) string {
|
|
return strings.ToLower(s)
|
|
}
|
|
|
|
// 下划线转大写驼峰
|
|
func UnderscoreToUpperCamelCase(s string) string {
|
|
s = strings.Replace(s, "_", " ", -1)
|
|
s = strings.Title(s)
|
|
return strings.Replace(s, " ", "", -1)
|
|
}
|
|
|
|
// 下划线转小写驼峰
|
|
func UnderscoreToLowerCamelCase(s string) string {
|
|
s = UnderscoreToUpperCamelCase(s)
|
|
return string(unicode.ToLower(rune(s[0]))) + s[1:]
|
|
}
|
|
|
|
// 驼峰转下划线
|
|
func CamelCaseToUnderscore(s string) string {
|
|
var output []rune
|
|
for i, r := range s {
|
|
if i == 0 {
|
|
output = append(output, unicode.ToLower(r))
|
|
continue
|
|
}
|
|
if unicode.IsUpper(r) {
|
|
output = append(output, '_')
|
|
}
|
|
output = append(output, unicode.ToLower(r))
|
|
}
|
|
return string(output)
|
|
}
|