1
0
mirror of https://github.com/fumiama/NanoBot.git synced 2026-06-10 13:10:26 +08:00

add helper.UnderlineToCamel

This commit is contained in:
源文雨
2023-10-13 00:45:21 +09:00
parent 40f743cf46
commit e495e2d4d0
2 changed files with 41 additions and 0 deletions

View File

@@ -47,3 +47,22 @@ func MessageUnescape(text string) string {
text = strings.ReplaceAll(text, ">", ">")
return text
}
// UnderlineToCamel convert abc_def to AbcDef
func UnderlineToCamel(s string) string {
sb := strings.Builder{}
isnextupper := true
for _, c := range []byte(strings.ToLower(s)) {
if c == '_' {
isnextupper = true
continue
}
if isnextupper {
sb.WriteString(strings.ToUpper(string(c)))
isnextupper = false
continue
}
sb.WriteByte(c)
}
return sb.String()
}