1 Star 1 Fork 0

bigbase / pg

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
underscore.go 1.12 KB
一键复制 编辑 原始数据 按行查看 历史
package internal
func isUpper(c byte) bool {
return c >= 'A' && c <= 'Z'
}
func isLower(c byte) bool {
return !isUpper(c)
}
func toUpper(c byte) byte {
return c - 32
}
func toLower(c byte) byte {
return c + 32
}
// Underscore converts "CamelCasedString" to "camel_cased_string".
func Underscore(s string) string {
r := make([]byte, 0, len(s))
for i := 0; i < len(s); i++ {
c := s[i]
if isUpper(c) {
if i > 0 && i+1 < len(s) && (isLower(s[i-1]) || isLower(s[i+1])) {
r = append(r, '_', toLower(c))
} else {
r = append(r, toLower(c))
}
} else {
r = append(r, c)
}
}
return string(r)
}
func ToUpper(s string) string {
if isUpperString(s) {
return s
}
b := make([]byte, len(s))
for i := range b {
c := s[i]
if c >= 'a' && c <= 'z' {
c -= 'a' - 'A'
}
b[i] = c
}
return string(b)
}
func isUpperString(s string) bool {
for i := 0; i < len(s); i++ {
c := s[i]
if c >= 'a' && c <= 'z' {
return false
}
}
return true
}
func ToExported(s string) string {
if len(s) == 0 {
return s
}
if c := s[0]; isLower(c) {
b := []byte(s)
b[0] = toUpper(c)
return string(b)
}
return s
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/bigbase/pg.git
git@gitee.com:bigbase/pg.git
bigbase
pg
pg
v6.4.5

搜索帮助

344bd9b3 5694891 D2dac590 5694891