package strcase import ( "strings" ) // Converts a string to CamelCase func toCamelInitCase(s string, initCase bool) string { s = addWordBoundariesToNumbers(s) s = strings.Trim(s, " ") n := "" capNext := initCase for i, v := range s { if v >= 'A' && v <= 'Z' { if !initCase && i == 0 { n += strings.ToLower(string(v)) } else { n += string(v) } } if v >= '0' && v <= '9' { 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) }