1 Star 1 Fork 0

zhuyuns/basic

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
naming.go 1.13 KB
一键复制 编辑 原始数据 按行查看 历史
wing 提交于 2021-12-18 11:42 . 添加基础包
package naming
import (
"regexp"
"strings"
)
//----------------------------------------------- "FooBar" => "foo_bar"
var regexp1 = regexp.MustCompile(`([A-Z]+)([A-Z][a-z])`)
var regexp2 = regexp.MustCompile(`([a-z])([A-Z])`)
func UnderScore(str string) string {
ret := regexp1.ReplaceAllString(str, `${1}_${2}`)
ret = regexp2.ReplaceAllString(ret, `${1}_${2}`)
return strings.ToLower(strings.Replace(string(ret), "-", "_", -1))
}
//----------------------------------------------- "foo_bar" -> "FooBar"
var regexp3 = regexp.MustCompile(`^[a-z]|_[a-z]`)
func CamelCase(str string) string {
str = strings.ToLower(str)
ret := regexp3.ReplaceAllFunc([]byte(str), func(match []byte) []byte {
v := strings.TrimLeft(string(match), "_")
v = strings.ToUpper(v)
return []byte(v)
})
return string(ret)
}
//------------------------------------------------ FNV-1a 32-bit String Hash
func FNV1a(str string) uint32 {
FNV_prime := uint32(16777619)
hash := uint32(2166136261)
octects := []byte(str)
for _, v := range octects {
hash = hash ^ uint32(v)
hash = hash * FNV_prime
}
return hash
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/zhuyuns/basic.git
git@gitee.com:zhuyuns/basic.git
zhuyuns
basic
basic
v0.0.35

搜索帮助