a2c126df64
feat: created ToLowerCamel() to not capitalize the first letter
39 lines
636 B
Go
39 lines
636 B
Go
package strcase
|
|
|
|
import (
|
|
"strings"
|
|
)
|
|
|
|
// Converts a string to CamelCase
|
|
func ToCamelInitCase(s string, initCase bool) string {
|
|
s = strings.Trim(s, " ")
|
|
n := ""
|
|
capNext := initCase
|
|
for _, v := range s {
|
|
if v >= 'A' && v <= 'Z' {
|
|
n += string(v)
|
|
}
|
|
if v >= 'a' && v <= 'z' {
|
|
if capNext {
|
|
n += strings.ToUpper(string(v))
|
|
} else {
|
|
n += string(v)
|
|
}
|
|
}
|
|
if v == '_' || v == ' ' || v == '-' {
|
|
capNext = true
|
|
} else {
|
|
capNext = false
|
|
}
|
|
}
|
|
return n
|
|
}
|
|
|
|
func ToCamel(s string) string {
|
|
return ToCamelInitCase(s, true);
|
|
}
|
|
|
|
func ToLowerCamel(s string) string {
|
|
return ToCamelInitCase(s, false);
|
|
}
|