增加蛇形转驼峰方法

This commit is contained in:
zhangdeman committed 2021-10-25 18:06:26 +08:00
1 parent bd32998c76
commit 5a7a4099e2
3 files changed
+29

No files matched your search

+26
View File
@@ -11,6 +11,7 @@ import (
"crypto/md5"
"encoding/hex"
"math/rand"
"strings"
"time"
)
@@ -46,3 +47,28 @@ func Md5(str string) string {
_, _ = h.Write([]byte(str))
return hex.EncodeToString(h.Sum(nil))
}
// SnakeCaseToCamel 蛇形字符串转换为驼峰
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 4:58 下午 2021/10/25
func SnakeCaseToCamel(str string) string {
builder := strings.Builder{}
index := 0
if str[0] >= 'a' && str[0] <= 'z' {
builder.WriteByte(str[0] - ('a' - 'A'))
index = 1
}
for i := index; i < len(str); i++ {
if str[i] == '_' && i+1 < len(str) {
if str[i+1] >= 'a' && str[i+1] <= 'z' {
builder.WriteByte(str[i+1] - ('a' - 'A'))
i++
continue
}
}
builder.WriteByte(str[i])
}
return builder.String()
}
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.