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:
19
helper.go
19
helper.go
@@ -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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user